• Stars
    star
    578
  • Rank 74,302 (Top 2 %)
  • Language
    Ruby
  • License
    MIT License
  • Created almost 12 years ago
  • Updated 5 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

retry randomly failing rspec example

RSpec::Retry Build Status

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

Compatibility

Rspec Version Rspec-Retry Version
> 3.8 0.6.2 but untested
> 3.3, <= 3.8 0.6.2            
3.2       0.4.6            
2.14.8       0.4.4            

Maintenance Expectations

NoRedInk used to be a Ruby shop, and we open-sourced this in the hope that it will help other people. However, we've been moving away from Ruby for some time now, and only plan to do maintenance on this repo when we have an internal need for it. We don't plan to add any new functionality, and expect that it will fall behind the latest versions of Ruby and Rspec.

That said, if you're reading this and you need this gem to do something new, feel free to fork it and publish your own gem! If you open an issue here to let us know about your fork, we can add a link to it from this repo to help folks find something that's more actively maintained.

Installation

Add this line to your application's Gemfile:

gem 'rspec-retry', 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-retry

require in spec_helper.rb

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

RSpec.configure do |config|
  # show retry status in spec process
  config.verbose_retry = true
  # show exception that triggers a retry if verbose_retry is set to true
  config.display_try_failure_messages = true

  # 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
# run spec (following log is shown if verbose_retry options is true)
# RSpec::Retry: 2nd try ./spec/lib/random_spec.rb:49
# RSpec::Retry: 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

  • :verbose_retry(default: false) Print retry status
  • :display_try_failure_messages (default: false) If verbose retry is enabled, print what reason forced the retry
  • :default_retry_count(default: 1) If retry count is not set in an example, this value is used by default. Note that currently this is a 'try' count. If increased from the default of 1, all examples will be retried. We plan to fix this as a breaking change in version 1.0.
  • :default_sleep_interval(default: 0) Seconds to wait between retries
  • :clear_lets_on_failure(default: true) Clear memoized values for lets before retrying
  • :exceptions_to_hard_fail(default: []) List of exceptions that will trigger an immediate test failure without retry. Takes precedence over :exceptions_to_retry
  • :exceptions_to_retry(default: []) List of exceptions that will trigger a retry (when empty, all exceptions will)
  • :retry_callback(default: nil) Callback function to be called between retries

Environment Variables

  • RSPEC_RETRY_RETRY_COUNT can override the retry counts even if a retry count is set in an example or default_retry_count is set in a configuration.

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

More Repositories

1

elm-style-guide

NoRedInk style guide for our Elm code
312
star
2

elm-decode-pipeline

⚠️MOVED ⚠️ to NoRedInk/elm-json-decode-pipeline as of Elm 0.19!
Elm
251
star
3

elm-json-decode-pipeline

Use pipelines to build JSON Decoders in Elm.
Elm
139
star
4

noredink-ui

Component Library package & Component Catalog app code
Elm
128
star
5

elm-rails

Convenience functions for using Elm with Rails.
Elm
105
star
6

elm-ops-tooling

Tooling for Elm ops (no longer maintained)
Python
81
star
7

haskell-libraries

Libraries we use at NoRedInk
Haskell
75
star
8

jetpack

Haskell
65
star
9

elm-assets-loader

webpack loader for webpackifying asset references in Elm code
JavaScript
47
star
10

json-elm-schema

Elm
45
star
11

elm-html-widgets

An elm-html widget library
Elm
38
star
12

elm_sprockets

Sprockets preprocessor for Elm
Ruby
17
star
13

elm-simple-fuzzy

http://package.elm-lang.org/packages/NoRedInk/elm-simple-fuzzy/latest
Elm
17
star
14

rocket-update

A simpler alternative to (!)
Elm
17
star
15

elm-moment

A Moment port to Elm
JavaScript
15
star
16

elm-rollbar

Rollbar helpers for Elm
Elm
14
star
17

make-lambda-package

Bundle up Python deployment packages for AWS Lambda
Python
14
star
18

elm-asset-path

Elm
11
star
19

elm-string-extra

Convenience functions for working with Strings in Elm.
Elm
10
star
20

list-selection

A list with a selected item. Like a zipper, but optional.
Elm
10
star
21

elm-api-components

API components for use with Elm
Elm
8
star
22

elm-string-conversions

Elm
8
star
23

tracing-newrelic

A Haskell package to report to NewRelic using the New Relic C SDK
Haskell
6
star
24

find-elm-dependencies

Find elm dependencies for a given entry
JavaScript
6
star
25

view-extra

Tiny view helpers
Elm
6
star
26

npm-elm-rails

A Rails plugin for using Elm files with the asset pipeline.
Ruby
5
star
27

until_then

Calculates offsets to regularly scheduled events.
Elixir
5
star
28

drag-and-drop

Elm
5
star
29

elm-formatted-text

A type for representing formatted text
Elm
5
star
30

elm-plot-19

SVG charts in Elm 0.19
Elm
5
star
31

rails_edge_test

Generate json for front-end testing using your rails backend.
Ruby
5
star
32

nri-elm-css

Colors, fonts, etc for NRI branding
Elm
4
star
33

elm-sweet-poll

Elm
4
star
34

elm-compare

Tools for composing comparison functions
Elm
4
star
35

build-elm-assets

JavaScript
3
star
36

greenhouse-interview-analytics

Python
3
star
37

elm-review-extract-api

A rule to extract the API of Elm applications using elm-review's data extraction facilities
Elm
3
star
38

elm-table

Elm
2
star
39

elm-blog-engine

CSS
2
star
40

style-guide

2
star
41

http-upgrade-shim

Elm
2
star
42

deploy-complexity

Analyze the history and complexity of each deploy
Ruby
2
star
43

elm-draggable

Unfinished hackday project
Elm
2
star
44

noredink.github.io

HTML
2
star
45

string-conversions

Elm
2
star
46

elm-css-template

This is meant for designers and people who want to experiment with elm-css.
Elm
2
star
47

datetimepicker-legacy

NoRedInk/datetimepicker, published for 0.19. Not meant for community use.
Elm
1
star
48

hs-rs-notify

Haskell
1
star
49

epc

Haskell
1
star
50

first_after_created_at

Ruby
1
star
51

git-whatsup

List up remote branches that conflict with the current working copy
Python
1
star
52

open-source-mapper

Python
1
star
53

elm-review-html-lazy

Protects against incorrect usage of Html.Lazy and Html.Styled.Lazy
Elm
1
star
54

elm-formatted-text-19

A type for representing formatted text in Elm 0.19
Elm
1
star
55

elm-saved

A type keeping track of changes to a value since it was last saved.
Elm
1
star
56

localdoc

Plaintext documentation viewer and editor with diagram support
Ruby
1
star
57

elm-doodad

Deprecated in favour of noredink-ui!
Elm
1
star