Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/rstacruz/rspec-repeat
Repeats an RSpec example until it succeeds.
https://github.com/rstacruz/rspec-repeat
rails rspec
Last synced: 18 days ago
JSON representation
Repeats an RSpec example until it succeeds.
- Host: GitHub
- URL: https://github.com/rstacruz/rspec-repeat
- Owner: rstacruz
- License: mit
- Created: 2015-09-24T15:47:55.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2024-04-26T15:29:24.000Z (9 months ago)
- Last Synced: 2025-01-01T04:49:11.352Z (25 days ago)
- Topics: rails, rspec
- Language: Ruby
- Size: 21.5 KB
- Stars: 24
- Watchers: 4
- Forks: 9
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Changelog: HISTORY.md
- License: LICENSE.md
Awesome Lists containing this project
README
# RSpec::Repeat
> Repeats an RSpec example until it succeeds
```rb
# spec_helper.rb# Example: Repeat all tests in CI
if ENV['CI']
require 'rspec/repeat'RSpec.configure do |config|
config.include RSpec::Repeat
config.around :each do |example|
repeat example, 3.times, verbose: true
end
end
end
```
[![Status](https://travis-ci.org/rstacruz/rspec-repeat.svg?branch=master)](https://travis-ci.org/rstacruz/rspec-repeat "See test builds")
## Advanced usage
### Options
```
repeat example, 3.times, { options }
```You can pass an `options` hash:
- __clear_let__ *(Boolean)* — if *false*, `let` declarations will not be cleared.
- __exceptions__ *(Array)* — if given, it will only retry exception classes from this list.
- __wait__ *(Numeric)* — seconds to wait between each retry.
- __verbose__ *(Boolean)* — if *true*, it will print messages upon failure.### Attaching to tags
This will allow you to repeat any example multiple times by tagging it.
```rb
# rails_helper.rb or spec_helper.rb
require 'rspec/repeat'RSpec.configure do |config|
config.include RSpec::Repeat
config.around :each, :stubborn do |example|
repeat example, 3.times
end
end
``````rb
describe 'stubborn tests', :stubborn do
# ...
end
```### Attaching to features
This will make all `spec/features/` retry thrice. Perfect for Poltergeist/Selenium tests that intermittently fail for no reason.
```rb
# rails_helper.rb or spec_helper.rb
require 'rspec/repeat'RSpec.configure do |config|
config.include RSpec::Repeat
config.around :each, type: :feature do |example|
repeat example, 3.times
end
end
```In these cases, it'd be smart to restrict which exceptions to be retried.
```rb
repeat example, 3.times, verbose: true, exceptions: [
Net::ReadTimeout,
Selenium::WebDriver::Error::WebDriverError
]
```### Repeating a specific test
You can also include RSpec::Repeat in just a single test block.
```rb
require 'rspec/repeat'describe 'a stubborn test' do
include RSpec::Repeataround do |example|
repeat example, 10.times
endit 'works, eventually' do
expect(rand(2)).to eq 0
end
end
```
## Acknowledgement
Much of this code has been refactored out of [rspec-retry](https://github.com/NoRedInk/rspec-retry) by [@NoRedInk](https://github.com/NoRedInk).
## Thanks
**rspec-repeat** © 2015-2017, Rico Sta. Cruz. Released under the [MIT] License.
Authored and maintained by Rico Sta. Cruz with help from contributors ([list][contributors]).> [ricostacruz.com](http://ricostacruz.com) ·
> GitHub [@rstacruz](https://github.com/rstacruz) ·
> Twitter [@rstacruz](https://twitter.com/rstacruz)[MIT]: http://mit-license.org/
[contributors]: http://github.com/rstacruz/rspec-repeat/contributors