Class: Protest::Runner
- Inherits:
-
Object
- Object
- Protest::Runner
- Defined in:
- lib/protest/runner.rb
Instance Method Summary collapse
-
#initialize(report) ⇒ Runner
constructor
Set up the test runner.
-
#report(test, running_global_setup_or_teardown = false) ⇒ Object
Run a test and report if it passes, fails, or is pending.
-
#run(*test_cases) ⇒ Object
Run a set of test cases, provided as arguments.
-
#run_test_case(test_case) ⇒ Object
Run a test case, along with any child test cases.
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)
31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/protest/runner.rb', line 31 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 |
# File 'lib/protest/runner.rb', line 12 def run(*test_cases) @report.on_start if @report.respond_to?(:on_start) test_cases.each {|test_case| run_test_case(test_case) } @report.on_end if @report.respond_to?(:on_end) end |
#run_test_case(test_case) ⇒ Object
Run a test case, along with any child test cases. This will fire the enter
event before running the test case and the exit
event afterward.
20 21 22 23 24 25 |
# File 'lib/protest/runner.rb', line 20 def run_test_case(test_case) @report.on_enter(test_case) if @report.respond_to?(:on_enter) sub_test_cases = Protest.send(:available_test_cases).select {|tc| tc.superclass == test_case } test_case.run(self, sub_test_cases) @report.on_exit(test_case) if @report.respond_to?(:on_exit) end |