Class: RSpecQ::Formatters::FailureRecorder
- Inherits:
-
Object
- Object
- RSpecQ::Formatters::FailureRecorder
- Defined in:
- lib/rspecq/formatters/failure_recorder.rb
Overview
Persists failed examples information (i.e. message and backtrace), so that they can be reported to the end user by the Reporter.
Also persists non-example error information (e.g. a syntax error that in a spec file).
Instance Method Summary collapse
- #example_failed(notification) ⇒ Object
-
#initialize(queue, job, max_requeues) ⇒ FailureRecorder
constructor
A new instance of FailureRecorder.
-
#message(n) ⇒ Object
Here we’re notified about errors occuring outside of examples.
Constructor Details
#initialize(queue, job, max_requeues) ⇒ FailureRecorder
Returns a new instance of FailureRecorder.
9 10 11 12 13 14 15 |
# File 'lib/rspecq/formatters/failure_recorder.rb', line 9 def initialize(queue, job, max_requeues) @queue = queue @job = job @colorizer = RSpec::Core::Formatters::ConsoleCodes @non_example_error_recorded = false @max_requeues = max_requeues end |
Instance Method Details
#example_failed(notification) ⇒ Object
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 |
# File 'lib/rspecq/formatters/failure_recorder.rb', line 30 def example_failed(notification) example = notification.example rerun_cmd = "bin/rspec --seed #{RSpec.configuration.seed} #{example.location_rerun_argument}" if @queue.requeue_job(example.id, @max_requeues) # Save the rerun command for later. It will be used if this is # a flaky test for more user-friendly reporting. @queue.save_rerun_command(example.id, rerun_cmd) # HACK: try to avoid picking the job we just requeued; we want it # to be picked up by a different worker sleep 0.5 return end presenter = RSpec::Core::Formatters::ExceptionPresenter.new( example.exception, example ) msg = presenter.fully_formatted(nil, @colorizer) msg << "\n" msg << @colorizer.wrap( rerun_cmd, RSpec.configuration.failure_color ) msg << @colorizer.wrap( " # #{example.full_description}", RSpec.configuration.detail_color ) @queue.record_example_failure(notification.example.id, msg) end |
#message(n) ⇒ Object
Here we’re notified about errors occuring outside of examples.
NOTE: Upon such an error, RSpec emits multiple notifications but we only want the first, which is the one that contains the error backtrace. That’s why have to keep track of whether we’ve already received the needed notification and act accordingly.
23 24 25 26 27 28 |
# File 'lib/rspecq/formatters/failure_recorder.rb', line 23 def (n) if RSpec.world.non_example_failure && !@non_example_error_recorded @queue.record_non_example_error(@job, n.) @non_example_error_recorded = true end end |