Class: Smartest::TestRun

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(fixture_classes:, matcher_modules:, &block) ⇒ TestRun

Returns a new instance of TestRun.



7
8
9
10
11
12
13
14
15
16
17
# File 'lib/smartest/test_run.rb', line 7

def initialize(fixture_classes:, matcher_modules:, &block)
  @fixture_classes = FixtureClassRegistry.new
  fixture_classes.each { |fixture_class| @fixture_classes.add(fixture_class) }

  @matcher_modules = MatcherRegistry.new
  matcher_modules.each { |matcher_module| @matcher_modules.add(matcher_module) }

  @block = block
  @ran = false
  @result = nil
end

Instance Attribute Details

#resultObject (readonly)

Returns the value of attribute result.



5
6
7
# File 'lib/smartest/test_run.rb', line 5

def result
  @result
end

Instance Method Details

#add_fixture_class(klass) ⇒ Object

Raises:



33
34
35
36
37
38
# File 'lib/smartest/test_run.rb', line 33

def add_fixture_class(klass)
  raise AroundTestRunError, "use_fixture must be called before test.run" if ran?

  reject_suite_fixture_class!(klass)
  @fixture_classes.add(klass)
end

#add_matcher_module(matcher_module) ⇒ Object

Raises:



40
41
42
43
44
# File 'lib/smartest/test_run.rb', line 40

def add_matcher_module(matcher_module)
  raise AroundTestRunError, "use_matcher must be called before test.run" if ran?

  @matcher_modules.add(matcher_module)
end

#ran?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/smartest/test_run.rb', line 29

def ran?
  @ran
end

#runObject

Raises:



19
20
21
22
23
24
25
26
27
# File 'lib/smartest/test_run.rb', line 19

def run
  raise AroundTestRunError, "around_test hook called test.run more than once" if ran?

  @ran = true
  @result = @block.call(
    fixture_classes: @fixture_classes,
    matcher_modules: @matcher_modules
  )
end