Betterment / rspec-fortify

MIT License
3 stars 0 forks source link

RSpec::Fortify

RSpec::Fortify is a hard fork of rspec-retry

RSpec::Fortify adds a :retry option for intermittently failing rspec examples. If an example has the :retry option, rspec will run the example the specified number of times until the example succeeds.

Installation

Add this line to your application's Gemfile:

gem 'rspec-fortify', group: :test # Unlike rspec, this doesn't need to be included in development group

And then execute:

$ bundle

Or install it yourself as:

$ gem install rspec-fortify

require in spec_helper.rb

# spec/spec_helper.rb
require 'rspec/fortify'

RSpec.configure do |config|
  # run retry only on features
  config.around :each, :js do |ex|
    ex.run_with_retry retry: 3
  end

  # callback to be run between retries
  config.retry_callback = proc do |ex|
    # run some additional clean up task - can be filtered by example metadata
    if ex.metadata[:js]
      Capybara.reset!
    end
  end
end

Usage

it 'should randomly succeed', :retry => 3 do
  expect(rand(2)).to eq(1)
end

it 'should succeed after a while', :retry => 3, :retry_wait => 10 do
  expect(command('service myservice status')).to eq('started')
end
# RSpec::Fortify: 2nd try ./spec/lib/random_spec.rb:49
# RSpec::Fortify: 3rd try ./spec/lib/random_spec.rb:49

Calling run_with_retry programmatically

You can call ex.run_with_retry(opts) on an individual example.

Configuration

Environment Variables

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Added some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a pull request