Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

One method of running one RSpec example concurrently multiple times to eliminate flakiness is using the "flaky" gem. The gem wraps the example with a retry block to rerun the test multiple times, with a specified number of attempts, using randomized seed.

To use the "flaky" gem, you can follow the steps below:

  1. Install the gem by adding it to your Gemfile and running bundle install.

    gem 'flaky'
    
  2. Add the flaky tag to the RSpec example you want to run concurrently.

    it "is a flaky example", flaky: 3 do
     # Example code here
    end
    

    In this example, flaky: 3 means the example will be run three times.

  3. Run your RSpec tests using the --tag flaky option.

    bundle exec rspec --tag flaky
    

    This will run all RSpec examples with the flaky tag concurrently multiple times as specified by the flaky tag option.