Class: Assert::Runner

Inherits:
Object
  • Object
show all
Includes:
ConfigHelpers
Defined in:
lib/assert/runner.rb

Direct Known Subclasses

DefaultRunner

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from ConfigHelpers

#all_pass?, #error_result_count, #fail_result_count, #formatted_result_rate, #formatted_run_time, #formatted_suite_result_rate, #formatted_suite_run_time, #formatted_suite_test_rate, #formatted_test_rate, #ignore_result_count, #ocurring_result_types, #pass_result_count, #result_count, #runner_seed, #show_test_profile_info?, #show_test_verbose_info?, #single_test?, #single_test_file_line, #skip_result_count, #suite, #test_count, #tests_to_run?, #tests_to_run_count, #view

Constructor Details

#initialize(config) ⇒ Runner

Returns a new instance of Runner.


13
14
15
# File 'lib/assert/runner.rb', line 13

def initialize(config)
  @config = config
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.


11
12
13
# File 'lib/assert/runner.rb', line 11

def config
  @config
end

Instance Method Details

#after_loadObject


90
91
# File 'lib/assert/runner.rb', line 90

def after_load
end

#after_test(test) ⇒ Object


102
103
# File 'lib/assert/runner.rb', line 102

def after_test(test)
end

#before_load(test_files) ⇒ Object

define callback handlers to do special behavior during the test run. These will be called by the test runner


87
88
# File 'lib/assert/runner.rb', line 87

def before_load(test_files)
end

#before_test(test) ⇒ Object


96
97
# File 'lib/assert/runner.rb', line 96

def before_test(test)
end

#on_finishObject


105
106
# File 'lib/assert/runner.rb', line 105

def on_finish
end

#on_info(test) ⇒ Object


108
109
# File 'lib/assert/runner.rb', line 108

def on_info(test)
end

#on_interrupt(err) ⇒ Object


111
112
# File 'lib/assert/runner.rb', line 111

def on_interrupt(err)
end

#on_result(result) ⇒ Object


99
100
# File 'lib/assert/runner.rb', line 99

def on_result(result)
end

#on_startObject


93
94
# File 'lib/assert/runner.rb', line 93

def on_start
end

#runObject


21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/assert/runner.rb', line 21

def run
  on_start
  suite.on_start
  view.on_start

  if single_test?
    view.print "Running test: #{single_test_file_line}"
  elsif tests_to_run?
    view.print "Running tests in random order"
  end
  view.puts ", seeded with \"#{runner_seed}\"" if tests_to_run?

  @current_running_test = nil

  # if SIGINFO available (ie on OSX, not on BSD) and if SIGINFO requested
  # (Ctrl+T on Macs), process it
  if Signal.list.keys.include?("INFO")
    Signal.trap("INFO") do
      on_info(@current_running_test)
      suite.on_info(@current_running_test)
      view.on_info(@current_running_test)
    end
  end

  begin
    suite.start_time = Time.now
    suite.setups.each(&:call)
    tests_to_run.tap{ suite.clear_tests_to_run }.delete_if do |test|
      @current_running_test = test

      before_test(test)
      suite.before_test(test)
      view.before_test(test)
      test.run do |result|
        on_result(result)
        suite.on_result(result)
        view.on_result(result)
      end
      after_test(test)
      suite.after_test(test)
      view.after_test(test)

      # always delete `test` from `tests_to_run` since it has been run
      true
    end
    suite.teardowns.each(&:call)
    suite.end_time = Time.now
  rescue Interrupt => ex
    on_interrupt(ex)
    suite.on_interrupt(ex)
    view.on_interrupt(ex)
    raise(ex)
  end

  (fail_result_count + error_result_count).tap do
    view.on_finish
    suite.on_finish
    on_finish
  end
end

#runnerObject


17
18
19
# File 'lib/assert/runner.rb', line 17

def runner
  self
end