Module: Shaf::Spec::Fixtures

Defined in:
lib/shaf/spec/fixtures.rb

Defined Under Namespace

Modules: Accessors Classes: FixtureNotFound

Class Method Summary collapse

Class Method Details

.clearObject



26
27
28
29
# File 'lib/shaf/spec/fixtures.rb', line 26

def clear
  fixtures.each { |name, _| Accessors.clear(name) }
  @initialized_fixtures = []
end

.fixture_defined(fixture) ⇒ Object



44
45
46
47
# File 'lib/shaf/spec/fixtures.rb', line 44

def fixture_defined(fixture)
  fixtures[fixture.name] = fixture
  Accessors.add(fixture.name)
end

.fixture_dirObject



65
66
67
# File 'lib/shaf/spec/fixtures.rb', line 65

def fixture_dir
  Shaf::Settings.fixtures_dir || 'spec/fixtures'
end

.fixture_filesObject



61
62
63
# File 'lib/shaf/spec/fixtures.rb', line 61

def fixture_files
  @fixture_files ||= Dir[File.join(fixture_dir, '**', '*.rb')]
end

.fixturesObject



49
50
51
# File 'lib/shaf/spec/fixtures.rb', line 49

def fixtures
  @fixtures ||= {}
end

.init_fixture(name, fixture = nil) ⇒ Object

Raises:



35
36
37
38
39
40
41
42
# File 'lib/shaf/spec/fixtures.rb', line 35

def init_fixture(name, fixture = nil)
  fixture ||= fixtures[name]
  raise FixtureNotFound, name unless fixture
  return if initialized? name

  initialized_fixtures << name
  fixture.init
end

.init_fixturesObject



31
32
33
# File 'lib/shaf/spec/fixtures.rb', line 31

def init_fixtures
  fixtures.each { |name, fixture| init_fixture(name, fixture) }
end

.initialized?(name) ⇒ Boolean

Returns:

  • (Boolean)


69
70
71
# File 'lib/shaf/spec/fixtures.rb', line 69

def initialized?(name)
  initialized_fixtures.include? name
end

.initialized_fixturesObject



53
54
55
# File 'lib/shaf/spec/fixtures.rb', line 53

def initialized_fixtures
  @initialized_fixtures ||= []
end

.load(reload: false) ⇒ Object



20
21
22
23
24
# File 'lib/shaf/spec/fixtures.rb', line 20

def load(reload: false)
  clear if reload
  require_fixture_files
  init_fixtures
end

.require_fixture_filesObject



57
58
59
# File 'lib/shaf/spec/fixtures.rb', line 57

def require_fixture_files
  fixture_files.each { |file| require(file) }
end