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:, helper_modules: [], &block) ⇒ TestRun

Returns a new instance of TestRun.



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

def initialize(fixture_classes:, matcher_modules:, helper_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) }

  @helper_modules = HelperRegistry.new
  helper_modules.each { |helper_module| @helper_modules.add(helper_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:



37
38
39
40
41
42
# File 'lib/smartest/test_run.rb', line 37

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_helper_module(helper_module) ⇒ Object

Raises:



50
51
52
53
54
# File 'lib/smartest/test_run.rb', line 50

def add_helper_module(helper_module)
  raise AroundTestRunError, "use_helper must be called before test.run" if ran?

  @helper_modules.add(helper_module)
end

#add_matcher_module(matcher_module) ⇒ Object

Raises:



44
45
46
47
48
# File 'lib/smartest/test_run.rb', line 44

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)


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

def ran?
  @ran
end

#runObject

Raises:



22
23
24
25
26
27
28
29
30
31
# File 'lib/smartest/test_run.rb', line 22

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,
    helper_modules: @helper_modules
  )
end