rspec-retry 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8f84a3f3775b6c16acbc11baa98c1920f6465dd6
4
- data.tar.gz: bf3b2b1fb8d7173d336c68987f29a4b8927a40bf
3
+ metadata.gz: 1db7f147ccb0d1a7fbb75a43d92110234719c60f
4
+ data.tar.gz: a544084a1ef008516ed74d783dca544729bd087e
5
5
  SHA512:
6
- metadata.gz: 97b01e500f2413ddcb66c94abc0b168dbace57d96685f76540f5d6ca443bbed7b673261165e052cb432ba80e40cd79ec3007e5136c12905295d96ea2e125eb26
7
- data.tar.gz: 76c096d54dac36b2383acfb7fac67222f5eb481cfd15af1193c1c23407e9b9960e552a20f678acde34ebc5021da7a98d0f238ab3c8bb67d7419593cb32ac868d
6
+ metadata.gz: 799571f04199b51356a85617e9cb6fb1a5bc9a7b0e745ed2449b43640e7849859da8a2caf94a0ca3a37a6b36b4f6983ee13bc416c8c126c036d04930d755e459
7
+ data.tar.gz: 517dcc387d8bf603bda9cbdb6bf8fd631f7b31d5f6e13aecdb07f89d25c5af3adf17ea241dd74f1e9767e356e4239ba5e7b4493326a2808bf3ddebb0939034f1
data/README.md CHANGED
@@ -1,8 +1,8 @@
1
1
  # RSpec::Retry
2
2
 
3
- RSpec::Retry adds ``:retry`` option to rspec example.
4
- It is for randomly failing example.
5
- If example has ``:retry``, rspec retry specified times until success.
3
+ RSpec::Retry adds a ``:retry`` option for intermittently failing rspec examples.
4
+ If an example has the ``:retry`` option, rspec will retry the example the
5
+ specified number of times until the example succeeds.
6
6
 
7
7
  ## Installation
8
8
 
@@ -32,12 +32,12 @@ end
32
32
  ## Usage
33
33
 
34
34
  ```ruby
35
- it 'should randomly success', :retry => 3 do
36
- rand(2).should == 1
35
+ it 'should randomly succeed', :retry => 3 do
36
+ expect(rand(2)).to eq(1)
37
37
  end
38
38
 
39
- it 'should succeed after a while', :retry => 3, :retry_wait=>10 do
40
- command('service myservice status').should == 'started'
39
+ it 'should succeed after a while', :retry => 3, :retry_wait => 10 do
40
+ expect(command('service myservice status')).to eq('started')
41
41
  end
42
42
  # run spec (following log is shown if verbose_retry options is true)
43
43
  # RSpec::Retry: 2nd try ./spec/lib/random_spec.rb:49
@@ -47,9 +47,10 @@ end
47
47
  ## Configuration
48
48
 
49
49
  - __:verbose_retry__(default: *false*) Print retry status
50
- - __:default_retry_count__(default: *1*) If retry count is not set in example, this value is used by default
51
- - __:retry_wait__(default: *0*) Seconds to wait between retries
52
- - __:clear_lets_on_failure__(default: *true*) Clear memoized value for ``let`` before retrying
50
+ - __:default_retry_count__(default: *1*) If retry count is not set in an example, this value is used by default
51
+ - __:default_sleep_interval__(default: *0*) Seconds to wait between retries
52
+ - __:clear_lets_on_failure__(default: *true*) Clear memoized values for ``let``s before retrying
53
+ - __:exceptions_to_retry__(default: *[]*) List of exceptions that will trigger a retry (when empty, all exceptions will)
53
54
 
54
55
  ## Contributing
55
56
 
@@ -57,4 +58,4 @@ end
57
58
  2. Create your feature branch (`git checkout -b my-new-feature`)
58
59
  3. Commit your changes (`git commit -am 'Added some feature'`)
59
60
  4. Push to the branch (`git push origin my-new-feature`)
60
- 5. Create new Pull Request
61
+ 5. Create a pull request
data/lib/rspec/retry.rb CHANGED
@@ -10,6 +10,12 @@ module RSpec
10
10
  config.add_setting :default_retry_count, :default => 1
11
11
  config.add_setting :default_sleep_interval, :default => 0
12
12
  config.add_setting :clear_lets_on_failure, :default => true
13
+ # If a list of exceptions is provided and 'retry' > 1, we only retry if
14
+ # the exception that was raised by the example is in that list. Otherwise
15
+ # we ignore the 'retry' value and fail immediately.
16
+ #
17
+ # If no list of exceptions is provided and 'retry' > 1, we always retry.
18
+ config.add_setting :exceptions_to_retry, :default => []
13
19
 
14
20
  # context.example is deprecated, but RSpec.current_example is not
15
21
  # available until RSpec 3.0.
@@ -20,6 +26,7 @@ module RSpec
20
26
  example = fetch_current_example.call(self)
21
27
  retry_count = ex.metadata[:retry] || RSpec.configuration.default_retry_count
22
28
  sleep_interval = ex.metadata[:retry_wait] || RSpec.configuration.default_sleep_interval
29
+ exceptions_to_retry = ex.metadata[:exceptions_to_retry] || RSpec.configuration.exceptions_to_retry
23
30
 
24
31
  clear_lets = ex.metadata[:clear_lets_on_failure]
25
32
  clear_lets = RSpec.configuration.clear_lets_on_failure if clear_lets.nil?
@@ -37,6 +44,10 @@ module RSpec
37
44
 
38
45
  break if example.exception.nil?
39
46
 
47
+ if exceptions_to_retry.any?
48
+ break unless exceptions_to_retry.include?(example.exception.class)
49
+ end
50
+
40
51
  self.clear_lets if clear_lets
41
52
  sleep sleep_interval if sleep_interval.to_i > 0
42
53
  end
@@ -1,5 +1,5 @@
1
1
  module RSpec
2
2
  class Retry
3
- VERSION = "0.3.0"
3
+ VERSION = "0.4.0"
4
4
  end
5
5
  end
data/rspec-retry.gemspec CHANGED
@@ -4,8 +4,8 @@ require File.expand_path('../lib/rspec/retry/version', __FILE__)
4
4
  Gem::Specification.new do |gem|
5
5
  gem.authors = ["Yusuke Mito"]
6
6
  gem.email = ["y310.1984@gmail.com"]
7
- gem.description = %q{retry randomly failing example}
8
- gem.summary = %q{retry randomly failing example}
7
+ gem.description = %q{retry intermittently failing rspec examples}
8
+ gem.summary = %q{retry intermittently failing rspec examples}
9
9
  gem.homepage = "http://github.com/y310/rspec-retry"
10
10
 
11
11
  gem.files = `git ls-files`.split($\)
@@ -14,7 +14,12 @@ Gem::Specification.new do |gem|
14
14
  gem.name = "rspec-retry"
15
15
  gem.require_paths = ["lib"]
16
16
  gem.version = RSpec::Retry::VERSION
17
- gem.add_runtime_dependency %{rspec}
17
+ gem.add_runtime_dependency %{rspec-core}
18
+ gem.add_development_dependency %q{rspec}
18
19
  gem.add_development_dependency %q{guard-rspec}
19
- gem.add_development_dependency %q{pry-debugger}
20
+ if Gem::Version.new(RUBY_VERSION) < Gem::Version.new('2')
21
+ gem.add_development_dependency %q{pry-debugger}
22
+ else
23
+ gem.add_development_dependency %q{pry-byebug}
24
+ end
20
25
  end
@@ -21,7 +21,7 @@ describe RSpec::Retry do
21
21
 
22
22
  context 'no retry option' do
23
23
  it 'should work' do
24
- true.should be true
24
+ expect(true).to be(true)
25
25
  end
26
26
  end
27
27
 
@@ -32,8 +32,8 @@ describe RSpec::Retry do
32
32
  before(:all) { set_expectations([false, false, true]) }
33
33
 
34
34
  it 'should run example until :retry times', :retry => 3 do
35
- true.should == shift_expectation
36
- count.should == 3
35
+ expect(true).to be(shift_expectation)
36
+ expect(count).to eq(3)
37
37
  end
38
38
  end
39
39
 
@@ -41,8 +41,24 @@ describe RSpec::Retry do
41
41
  before(:all) { set_expectations([false, true, false]) }
42
42
 
43
43
  it 'should stop retrying if example is succeeded', :retry => 3 do
44
- true.should == shift_expectation
45
- count.should == 2
44
+ expect(true).to be(shift_expectation)
45
+ expect(count).to eq(2)
46
+ end
47
+ end
48
+
49
+ describe "with a list of exceptions", :retry => 2, :exceptions_to_retry => [NoMethodError] do
50
+ context "the example throws an exception contained in the retry list" do
51
+ it "retries the maximum number of times" do
52
+ raise NoMethodError unless count > 1
53
+ expect(count).to eq(2)
54
+ end
55
+ end
56
+
57
+ context "the example fails (with an exception not in the retry list)" do
58
+ it "only runs once" do
59
+ set_expectations([false])
60
+ expect(count).to eq(1)
61
+ end
46
62
  end
47
63
  end
48
64
  end
@@ -59,11 +75,11 @@ describe RSpec::Retry do
59
75
  end
60
76
 
61
77
  it 'should clear the let when the test fails so it can be reset', :retry => 2 do
62
- let_based_on_control.should == false
78
+ expect(let_based_on_control).to be(false)
63
79
  end
64
80
 
65
81
  it 'should not clear the let when the test fails', :retry => 2, :clear_lets_on_failure => false do
66
- let_based_on_control.should == !@control
82
+ expect(let_based_on_control).to be(!@control)
67
83
  end
68
84
  end
69
85
  end
data/spec/spec_helper.rb CHANGED
@@ -1,6 +1,10 @@
1
1
  require 'rspec'
2
2
  require 'rspec/retry'
3
- require 'pry-debugger'
3
+ if Gem::Version.new(RUBY_VERSION) < Gem::Version.new('2')
4
+ require "pry-debugger"
5
+ else
6
+ require "pry-byebug"
7
+ end
4
8
 
5
9
  RSpec.configure do |config|
6
10
  config.verbose_retry = true
metadata CHANGED
@@ -1,65 +1,79 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec-retry
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yusuke Mito
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-23 00:00:00.000000000 Z
11
+ date: 2015-03-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: rspec
14
+ name: rspec-core
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '>='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - '>='
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
25
39
  - !ruby/object:Gem::Version
26
40
  version: '0'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: guard-rspec
29
43
  requirement: !ruby/object:Gem::Requirement
30
44
  requirements:
31
- - - '>='
45
+ - - ">="
32
46
  - !ruby/object:Gem::Version
33
47
  version: '0'
34
48
  type: :development
35
49
  prerelease: false
36
50
  version_requirements: !ruby/object:Gem::Requirement
37
51
  requirements:
38
- - - '>='
52
+ - - ">="
39
53
  - !ruby/object:Gem::Version
40
54
  version: '0'
41
55
  - !ruby/object:Gem::Dependency
42
- name: pry-debugger
56
+ name: pry-byebug
43
57
  requirement: !ruby/object:Gem::Requirement
44
58
  requirements:
45
- - - '>='
59
+ - - ">="
46
60
  - !ruby/object:Gem::Version
47
61
  version: '0'
48
62
  type: :development
49
63
  prerelease: false
50
64
  version_requirements: !ruby/object:Gem::Requirement
51
65
  requirements:
52
- - - '>='
66
+ - - ">="
53
67
  - !ruby/object:Gem::Version
54
68
  version: '0'
55
- description: retry randomly failing example
69
+ description: retry intermittently failing rspec examples
56
70
  email:
57
71
  - y310.1984@gmail.com
58
72
  executables: []
59
73
  extensions: []
60
74
  extra_rdoc_files: []
61
75
  files:
62
- - .gitignore
76
+ - ".gitignore"
63
77
  - Gemfile
64
78
  - Guardfile
65
79
  - LICENSE
@@ -80,20 +94,21 @@ require_paths:
80
94
  - lib
81
95
  required_ruby_version: !ruby/object:Gem::Requirement
82
96
  requirements:
83
- - - '>='
97
+ - - ">="
84
98
  - !ruby/object:Gem::Version
85
99
  version: '0'
86
100
  required_rubygems_version: !ruby/object:Gem::Requirement
87
101
  requirements:
88
- - - '>='
102
+ - - ">="
89
103
  - !ruby/object:Gem::Version
90
104
  version: '0'
91
105
  requirements: []
92
106
  rubyforge_project:
93
- rubygems_version: 2.0.14
107
+ rubygems_version: 2.2.2
94
108
  signing_key:
95
109
  specification_version: 4
96
- summary: retry randomly failing example
110
+ summary: retry intermittently failing rspec examples
97
111
  test_files:
98
112
  - spec/lib/rspec/retry_spec.rb
99
113
  - spec/spec_helper.rb
114
+ has_rdoc: