rspec / rspec-core

RSpec runner and formatters
http://rspec.info
MIT License
1.23k stars 765 forks source link

Feature request: fail when a pending spec raises an exception #2986

Closed magni- closed 2 years ago

magni- commented 2 years ago

Right now, marking a test as pending causes it to swallow all exceptions, not just failed expectations.

I added the following to our spec_helper.rb as a hacky workaround:

config.after do |example|
  next unless example.pending?
  exception = example.execution_result.pending_exception
  next if exception.is_a?(RSpec::Expectations::ExpectationNotMetError)

  example.reporter.example_failed(example)
end

Users who want to use pending to silence an exception rather than a failed expectation could use expect ... to_not raise_error to get the same behavior they currently have.

JonRowe commented 2 years ago

Thanks for the suggestion but the current behaviour is by design, as typically it is something that is broken internally rather than an expectation that fails, I would say that if you know what the "anti" result is you should just negate the expectation, and your own suggestion works well to achieve what you want for a general catch all, (that is wrap the test in a expect ... to raise_error(RSpec::Expectations::ExpectationNotMetError))