0.0
Low commit activity in last 3 years
No release in over a year
retry rspec one target `expect` instead of one `secenario` or `it`
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

Runtime

 Project Readme

RSpec::RetryEx

CircleCI Maintainability Test Coverage

RSpec::RetryEx retrys failing rspec "expect" instead of "example", "it" or "scenario".

Motivation

Feature test or System test sometimes fails randomely. There are so many reasons for failing. One of them is that the browser does not response smoothly to JavaScript animation. However it responses somoothly in a few tries. As a result, a few retries should be executed in feature test of system test.

Thanks to rspec-retry gem, a few retries can be executed by "scenario" unit. However we sometimes want to try to retry by "expect" unit because the scenario is so long and most "expect"s usually pass and specific "expect" often fails.

Installation

Add this line to your application's Gemfile:

gem 'rspec-retry_ex'

And then execute:

$ bundle

Or install it yourself as:

$ gem install rspec-retry_ex

require in spec_helper.rb or rails_helper.rb

include RSpec::RetryEx

Usage

Surround target "expect" with retry_ex method.

scenario "Some scenario" do
  visit "/some_page"

  fill_in "postcode", with: "1300012"
  retry_ex(count: 3) do
    expect(page).to have_select("ward", selected: "Sumida")
  end
end

Some codes can be added when the test fails with "before_retry" or "after_retry" option.

scenario "Some scenario" do
  visit "/some_page"

  fill_in "postcode", with: "1300012"

  # These codes are executed after the retry fails
  after_retry = -> {
    fill_in "postcode", with: "1000004"
    fill_in "postcode", with: "1300012"
  }
  retry_ex(count: 3, after_retry: after_retry) do
    expect(page).to have_select("ward", selected: "Sumida")
  end
end

Configuration

Errors to retry is customizable.

Only RSpec::Expectations::ExpectationNotMetError is retried by default.

Here is an example of configuration in spec_helper.rb or rails_helper.rb.

RSpec.configure do |config|
  config.rspec_retry_ex_retry_errors = [
    RSpec::Expectations::ExpectationNotMetError,
    Selenium::WebDriver::Error::WebDriverError
  ]
end

Or options for retry_ex.

scenario "Some scenario" do
  visit "/some_page"

  fill_in "postcode", with: "1300012"
  retry_ex(count: 3, retry_errors: [Selenium::WebDriver::Error::WebDriverError]) do
    expect(page).to have_select("ward", selected: "Sumida")
  end
end

Contributing

You should follow the steps below:

  1. Fork the repository
  2. Create a feature branch: git checkout -b add-new-feature
  3. Commit your changes: git commit -am 'Add new feature'
  4. Push the branch: git push origin add-new-feature
  5. Send us a pull request

License

The gem is available as open source under the terms of the MIT License.