Module: Fixturama
- Defined in:
- lib/fixturama.rb,
lib/fixturama/changes.rb
Overview
A set of helpers to prettify specs with fixtures
Defined Under Namespace
Modules: Config Classes: Changes, FixtureError, Loader
Class Method Summary collapse
-
.start_ids_from(value) ⇒ Fixturama
Set the initial value for database-generated IDs.
Instance Method Summary collapse
-
#call_fixture(path, options) ⇒ RSpec::Core::Example
(also: #seed_fixture, #stub_fixture)
Stub different objects and seed the database from a fixture.
-
#load_fixture(path, options) ⇒ Object
Load data from a fixture.
-
#read_fixture(path, options) ⇒ String
Read the text content of the fixture.
Class Method Details
.start_ids_from(value) ⇒ Fixturama
Set the initial value for database-generated IDs
21 22 23 24 |
# File 'lib/fixturama.rb', line 21 def self.start_ids_from(value) Config.start_ids_from(value) self end |
Instance Method Details
#call_fixture(path, options) ⇒ RSpec::Core::Example Also known as: seed_fixture, stub_fixture
Stub different objects and seed the database from a fixture
52 53 54 55 56 57 58 |
# File 'lib/fixturama.rb', line 52 def call_fixture(path, **) items = Array load_fixture(path, **) items.each { |item| changes.add(item) } tap { changes.call(self) } rescue FixtureError => err raise err.with_file(path) end |
#load_fixture(path, options) ⇒ Object
Load data from a fixture
44 45 46 |
# File 'lib/fixturama.rb', line 44 def load_fixture(path, **) Loader.new(path, ).call end |
#read_fixture(path, options) ⇒ String
Read the text content of the fixture
32 33 34 35 36 37 38 |
# File 'lib/fixturama.rb', line 32 def read_fixture(path, **) content = File.read(path) hashie = Hashie::Mash.new() bindings = hashie.instance_eval { binding } ERB.new(content).result(bindings) end |