--
You received this message because you are subscribed to the Google Groups "rspec" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rspec+un...@googlegroups.com.
To post to this group, send email to rs...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rspec/88d51b4d-2bb3-4391-bffd-476663474a07%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
RSpec.configure do |config|
config.around(:each) do |example|
begin
example.run
rescue RSpec::Expectations::ExpectationNotMetError
puts 'In here!'
raise
end
end
endRescuing exceptions in an around hook won’t work because within example.run RSpec rescues the exception as part of tracking the example state, notifying formatters, etc.
Are you looking to track all raised exceptions (even if something rescues them and/or retries)? Or just all the example failure exceptions?
If you’re looking for the former, you’ll probably have to monkey patch Kernel#raise or use a tracepoint.
If you’re looking for the latter, you can implement a listener/formatter that registers the :example_failed event with RSpec so that it is notified every time an example fails, and then you can do whatever you want when notified.
HTH,
Myron
To view this discussion on the web visit https://groups.google.com/d/msgid/rspec/ad47b93c-b440-4591-9af5-98f49b0aad1f%40googlegroups.com.
require 'rspec/core/formatters/base_formatter'
$read_timeout_count = 0 # Used to track Net::ReadTimeout Exceptions
module RSpec module Stats class Formatter < RSpec::Core::Formatters::BaseFormatter
def example_failed(notification) if notification.exception.to_s.include?('Net::ReadTimeout') $read_timeout_count += 1 end end
end endend