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) ⇒ Object
Run a test and report if it passes, fails, or is pending.
-
#run(test_cases, options = {}) ⇒ Object
Run a set of test cases, provided as arguments.
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) ⇒ Object
Run a test and report if it passes, fails, or is pending. Takes the name of the test as an argument.
34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/protest/runner.rb', line 34 def report(test) fire_event(:test, Test.new(test)) test.run(@report) fire_event(:pass, PassedTest.new(test)) rescue Pending => e fire_event :pending, PendingTest.new(test, e) rescue AssertionFailed => e fire_event :failure, FailedTest.new(test, e) exit 1 if Protest.fail_early? rescue Exception => e raise if e.is_a?(Interrupt) fire_event :error, ErroredTest.new(test, e) exit 1 if Protest.fail_early? end |
#run(test_cases, options = {}) ⇒ 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 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/protest/runner.rb', line 12 def run(test_cases, = {}) fire_event :start if [:line_numbers] test_groups = nearest_test_groups(test_cases, [:line_numbers]) else test_groups = test_cases.zip(test_cases.map(&:tests)) end test_groups.each do |test_case, tests| fire_event :enter, test_case tests.each { |test| report(test) } fire_event :exit, test_case end rescue Interrupt $stderr.puts "Interrupted!" ensure fire_event :end end |