Class: Smartest::Fixture

Inherits:
Object
  • Object
show all
Defined in:
lib/smartest/fixture.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(fixture_set:, context:) ⇒ Fixture

Returns a new instance of Fixture.



53
54
55
56
# File 'lib/smartest/fixture.rb', line 53

def initialize(fixture_set:, context:)
  @fixture_set = fixture_set
  @context = context
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args, &block) ⇒ Object (private)



66
67
68
69
70
71
72
# File 'lib/smartest/fixture.rb', line 66

def method_missing(method_name, *args, &block)
  if @context.respond_to?(method_name, true)
    @context.__send__(method_name, *args, &block)
  else
    super
  end
end

Class Method Details

.fixture(name, scope: :test, &block) ⇒ Object



6
7
8
9
10
11
12
13
# File 'lib/smartest/fixture.rb', line 6

def fixture(name, scope: :test, &block)
  define_fixture(
    name,
    scope: scope,
    block: block,
    location: caller_locations(1, 1).first
  )
end

.fixture_definitionsObject



24
25
26
27
28
29
30
31
32
33
# File 'lib/smartest/fixture.rb', line 24

def fixture_definitions
  inherited =
    if superclass.respond_to?(:fixture_definitions)
      superclass.fixture_definitions
    else
      {}
    end

  inherited.merge(own_fixture_definitions)
end

.suite_fixture(name, &block) ⇒ Object



15
16
17
18
19
20
21
22
# File 'lib/smartest/fixture.rb', line 15

def suite_fixture(name, &block)
  define_fixture(
    name,
    scope: :suite,
    block: block,
    location: caller_locations(1, 1).first
  )
end