module Fixturama

A set of helpers to prettify specs with fixtures

Constants

VERSION

The current version of the gem

Public Class Methods

start_ids_from(value) click to toggle source

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

call_fixture(path, **options) click to toggle source

@!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
Also aliased as: seed_fixture, stub_fixture
load_fixture(path, **options) click to toggle source

@!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
read_fixture(path, **options) click to toggle source

@!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
seed_fixture(path, **options)

@!method seed_fixture(path, options) The alias for the call_fixture @param (see call_fixture) @return (see call_fixture)

Alias for: call_fixture
stub_fixture(path, **options)

@!method stub_fixture(path, options) The alias for the call_fixture @param (see call_fixture) @return (see call_fixture)

Alias for: call_fixture

Private Instance Methods

changes() click to toggle source
   # File lib/fixturama.rb
74 def changes
75   @changes ||= Changes.new
76 end