Class: Protest::Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/protest/runner.rb

Instance Method Summary collapse

Constructor Details

#initialize(report) ⇒ Runner

Set up the test runner. Takes in a report that will be passed to test cases for reporting.



5
6
7
# File 'lib/protest/runner.rb', line 5

def initialize(report)
  @report = report
end

Instance Method Details

#report(test, running_global_setup_or_teardown = false) ⇒ Object

Run a test and report if it passes, fails, or is pending. Takes the name of the test as an argument. By passing true as the second argument, you force any exceptions to be re-raied and the test not reported as a pass after it finishes (for global setup/teardown blocks)



26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/protest/runner.rb', line 26

def report(test, running_global_setup_or_teardown=false)
  @report.on_test(Test.new(test)) if @report.respond_to?(:on_test) && !running_global_setup_or_teardown
  test.run(@report)
  @report.on_pass(PassedTest.new(test)) unless running_global_setup_or_teardown
rescue Pending => e
  @report.on_pending(PendingTest.new(test, e))
rescue AssertionFailed => e
  @report.on_failure(FailedTest.new(test, e))
rescue Exception => e
  @report.on_error(ErroredTest.new(test, e))
  raise if running_global_setup_or_teardown
end

#run(*test_cases) ⇒ Object

Run a set of test cases, provided as arguments. This will fire relevant events on the runner’s report, at the start and end of the test run, and before and after each test case (enter and exit.)



12
13
14
15
16
17
18
19
20
# File 'lib/protest/runner.rb', line 12

def run(*test_cases)
  @report.on_start if @report.respond_to?(:on_start)
  test_cases.each do |test_case|
    @report.on_enter(test_case) if @report.respond_to?(:on_enter)
    test_case.run(self)
    @report.on_exit(test_case) if @report.respond_to?(:on_exit)
  end
  @report.on_end if @report.respond_to?(:on_end)
end