Hey Jon,
Pretty solid idea! I didn't think of this.
Unfortunately it doesn't look to catch the exception though. Tested
with RSpec::Expectations::ExpectationNotMetError
This was a snippet of my code (which never printed 'In here!' when the
exception was raised - I tried simply rescue Exception as well):
RSpec.configure do |config|
config.around(:each) do |example|
begin
example.run
rescue RSpec::Expectations::ExpectationNotMetError
puts 'In here!'
raise
end
end
end
On Wednesday, July 22, 2015 at 6:11:44 PM UTC-7, Jon Rowe wrote:
>
> Not specifically, but you can configure an around hook to do what you want:
>
> Rspec.configure do |config|
> config.around(:example) do |example|
> begin
> example.run
> rescue Net::ReadTimeout
> # … your code
> raise
> end
> end
> end
>
> Jon Rowe
> ---------------------------
> [email protected] <javascript:>
> jonrowe.co.uk
>
> On Thursday, 23 July 2015 at 11:06, Dylan Reichstadt wrote:
>
> Hey All,
>
> I am looking to add better instrumentation around exceptions thrown in
> rspec. For example, I want to track how many times I get a Net::ReadTimeout
> error from Capybara/Rspec.
>
> In a limited scope, I have been:
>
> - Rescuing this exception
> - Incrementing a global variable
> - Re-raising that exception again (after incrementing)
>
>
> However, this exception can happen across all examples. I don't want to
> wrap every scenario in a Begin & Rescue block - that sounds extremely messy.
>
> Does rspec have something to help with this, or does anyone have any ideas
> I can achieve better tracking of exceptions? I have been googling around
> RSpec and Catching All Exceptions, but can't find anything.
>
> --
> 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 [email protected] <javascript:>.
> To post to this group, send email to [email protected] <javascript:>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/rspec/88d51b4d-2bb3-4391-bffd-476663474a07%40googlegroups.com
>
> <https://groups.google.com/d/msgid/rspec/88d51b4d-2bb3-4391-bffd-476663474a07%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>
>
>
--
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 [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/rspec/ad47b93c-b440-4591-9af5-98f49b0aad1f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.