Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7278435
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T22:52:27+00:00 2026-05-28T22:52:27+00:00

First of all I agree that mocking external API calls is the right thing

  • 0

First of all I agree that mocking external API calls is the right thing to do most of the times. However not in this case.

I’m getting random Timeout::Error exceptions in some of my tests and I would like to be able to ignore them and automatically re-run the example. Failure should be reported only after 10 unsuccessful attempts.

Any other exceptions & failures should be reported.

I’ve tried to implement this behavior using a global around(:each) hook in spec/spec_helper.rb file:

RSpec.configure do |config|
  config.around(:each) do |example|
    attempts = 0
    passed = false

    begin
      attempts +=1
      example.run
      passed = true

    rescue Timeout::Error => e
      raise e if attempts >= 10

    end until passed
  end
end

However the rescue part never gets executed when an exception occurs. Any idea why?

Thanks!
Dorian

P.S. I’m using rspec 2.6.0

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T22:52:28+00:00Added an answer on May 28, 2026 at 10:52 pm

    You cannot rescue exceptions in around blocks because they do not propagate. However, if you absolutely must re-run failing examples, you can pry the current exception out of @example, like here:

    https://github.com/jnicklas/capybara/blob/c21d5eb2375b610ac13f54cf240e59c80918a2f1/spec/spec_helper.rb#L16

    It looks pretty nasty. Our excuse was a bug in our upstream library, but I would generally avoid this if at all possible.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

First of all there is a partial question regarding this, but it is not
First, I know this question has been asked several times before and that in
First of all, I'm fairly sure snapping to grid is fairly easy, however I've
First of all: I am not an experienced ClearCase user, but I have lots
First of all (in case this is important) I'm using ActiveState's Perl (v5.8.7 built
First of all, I'm not looking for miracle... I know how PHP works and
So I keep getting this error that when I Google for it, the most
I imagine we all agree that it is considered idiomatic C to access a
I think most C++ programmers here would agree that polluting the global namespace is
First, I have to say that I really like Groovy and all the good

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.