module Fixturama
A set of helpers to prettify specs with fixtures
Constants
- VERSION
The current version of the gem
Public Class Methods
Set the initial value for database-generated IDs @param [#to_i] value @return [Fixturama]
# File lib/fixturama.rb 21 def self.start_ids_from(value) 22 Config.start_ids_from(value) 23 self 24 end
Public Instance Methods
@!method call_fixture
(path, options) Stub different objects and seed the database from a fixture @param (see read_fixture
) @return [RSpec::Core::Example] the current example
# File lib/fixturama.rb 52 def call_fixture(path, **options) 53 items = Array load_fixture(path, **options) 54 items.each { |item| changes.add(item) } 55 tap { changes.call(self) } 56 rescue FixtureError => err 57 raise err.with_file(path) 58 end
@!method load_fixture
(path, options) Load data from a fixture @param (see read_fixture
) @return [Object]
# File lib/fixturama.rb 44 def load_fixture(path, **options) 45 Loader.new(self, path, options).call 46 end
@!method read_fixture
(path, options) Read the text content of the fixture @param [#to_s] path The path to the fixture file @param [Hash<Symbol, _>] options
The list of options to be accessible in the fixture
@return [String]
# File lib/fixturama.rb 32 def read_fixture(path, **options) 33 content = File.read(path) 34 hashie = Hashie::Mash.new(options) 35 bindings = hashie.instance_eval { binding } 36 37 ERB.new(content).result(bindings) 38 end
@!method seed_fixture
(path, options) The alias for the call_fixture
@param (see call_fixture
) @return (see call_fixture
)
@!method stub_fixture
(path, options) The alias for the call_fixture
@param (see call_fixture
) @return (see call_fixture
)
Private Instance Methods
# File lib/fixturama.rb 74 def changes 75 @changes ||= Changes.new 76 end