rspec-retry 0.4.4 → 0.4.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +9 -0
- data/changelog.md +5 -0
- data/gemfiles/rspec_3.2.gemfile.lock +1 -1
- data/gemfiles/rspec_3.3.gemfile.lock +1 -1
- data/lib/rspec/retry.rb +100 -50
- data/lib/rspec/retry/version.rb +1 -1
- data/lib/rspec_ext/rspec_ext.rb +8 -0
- data/spec/lib/rspec/retry_spec.rb +16 -0
- data/spec/spec_helper.rb +5 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 08f3170cb5eb3a96fbf45a6facaac88f02261c99
|
4
|
+
data.tar.gz: a7831c2d528f9fb89f04aba2da2d0caf989741a3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 345abf819be3c81a57da26220b46c6d19441d012350d101ff97ecec3d98e1d6d9f552ecb18e62600827fb3beb76911937a13e15f097ad1338e4a25650e4c7ce0
|
7
|
+
data.tar.gz: 21c46735aac3ae909c27b162b65eff164a4a7bb36233efdf55f65b6fcfbd3bd35a3775b58dbbb5a870ce8c09369559f75ccd52f9eccef90ba00e9ce46fd1693a
|
data/README.md
CHANGED
@@ -30,6 +30,11 @@ RSpec.configure do |config|
|
|
30
30
|
config.verbose_retry = true
|
31
31
|
# show exception that triggers a retry if verbose_retry is set to true
|
32
32
|
config.display_try_failure_messages = true
|
33
|
+
|
34
|
+
# run retry only on features
|
35
|
+
config.around :each, :js do |ex|
|
36
|
+
ex.run_with_retry retry: 3
|
37
|
+
end
|
33
38
|
end
|
34
39
|
```
|
35
40
|
|
@@ -48,6 +53,10 @@ end
|
|
48
53
|
# RSpec::Retry: 3rd try ./spec/lib/random_spec.rb:49
|
49
54
|
```
|
50
55
|
|
56
|
+
### Calling `run_with_retry` programmatically
|
57
|
+
|
58
|
+
You can call `ex.run_with_retry(opts)` on an individual example.
|
59
|
+
|
51
60
|
## Configuration
|
52
61
|
|
53
62
|
- __:verbose_retry__(default: *false*) Print retry status
|
data/changelog.md
CHANGED
data/lib/rspec/retry.rb
CHANGED
@@ -4,7 +4,7 @@ require 'rspec_ext/rspec_ext'
|
|
4
4
|
|
5
5
|
module RSpec
|
6
6
|
class Retry
|
7
|
-
def self.
|
7
|
+
def self.setup
|
8
8
|
RSpec.configure do |config|
|
9
9
|
config.add_setting :verbose_retry, :default => false
|
10
10
|
config.add_setting :default_retry_count, :default => 1
|
@@ -18,64 +18,114 @@ module RSpec
|
|
18
18
|
# If no list of exceptions is provided and 'retry' > 1, we always retry.
|
19
19
|
config.add_setting :exceptions_to_retry, :default => []
|
20
20
|
|
21
|
-
# context.example is deprecated, but RSpec.current_example is not
|
22
|
-
# available until RSpec 3.0.
|
23
|
-
fetch_current_example = RSpec.respond_to?(:current_example) ?
|
24
|
-
proc { RSpec.current_example } : proc { |context| context.example }
|
25
|
-
|
26
21
|
config.around(:each) do |ex|
|
27
|
-
|
22
|
+
ex.run_with_retry
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
attr_reader :context, :ex
|
28
28
|
|
29
|
-
|
30
|
-
|
31
|
-
|
29
|
+
def initialize(ex, opts = {})
|
30
|
+
@ex = ex
|
31
|
+
@ex.metadata.merge!(opts)
|
32
|
+
current_example.attempts ||= 0
|
33
|
+
end
|
34
|
+
|
35
|
+
# context.example is deprecated, but RSpec.current_example is not
|
36
|
+
# available until RSpec 3.0.
|
37
|
+
def current_example
|
38
|
+
RSpec.respond_to?(:current_example) ?
|
39
|
+
RSpec.current_example : @ex.example
|
40
|
+
end
|
41
|
+
|
42
|
+
def retry_count
|
43
|
+
[
|
44
|
+
(
|
45
|
+
ENV['RSPEC_RETRY_RETRY_COUNT'] ||
|
32
46
|
ex.metadata[:retry] ||
|
33
47
|
RSpec.configuration.default_retry_count
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
48
|
+
).to_i,
|
49
|
+
1
|
50
|
+
].max
|
51
|
+
end
|
52
|
+
|
53
|
+
def attempts
|
54
|
+
current_example.attempts ||= 0
|
55
|
+
end
|
56
|
+
|
57
|
+
def attempts=(val)
|
58
|
+
current_example.attempts = val
|
59
|
+
end
|
60
|
+
|
61
|
+
def clear_lets
|
62
|
+
!ex.metadata[:clear_lets_on_failure].nil? ?
|
63
|
+
ex.metadata[:clear_lets_on_failure] :
|
64
|
+
RSpec.configuration.clear_lets_on_failure
|
65
|
+
end
|
66
|
+
|
67
|
+
def sleep_interval
|
68
|
+
ex.metadata[:retry_wait] ||
|
69
|
+
RSpec.configuration.default_sleep_interval
|
70
|
+
end
|
71
|
+
|
72
|
+
def exceptions_to_retry
|
73
|
+
ex.metadata[:exceptions_to_retry] ||
|
74
|
+
RSpec.configuration.exceptions_to_retry
|
75
|
+
end
|
76
|
+
|
77
|
+
def verbose_retry?
|
78
|
+
RSpec.configuration.verbose_retry?
|
79
|
+
end
|
80
|
+
|
81
|
+
def display_try_failure_messages?
|
82
|
+
RSpec.configuration.display_try_failure_messages?
|
83
|
+
end
|
84
|
+
|
85
|
+
def run
|
86
|
+
example = current_example
|
87
|
+
|
88
|
+
loop do
|
89
|
+
if verbose_retry?
|
90
|
+
if attempts > 0
|
91
|
+
message = "RSpec::Retry: #{ordinalize(attempts + 1)} try #{example.location}"
|
92
|
+
message = "\n" + message if attempts == 1
|
93
|
+
RSpec.configuration.reporter.message(message)
|
72
94
|
end
|
73
95
|
end
|
96
|
+
|
97
|
+
example.clear_exception
|
98
|
+
ex.run
|
99
|
+
|
100
|
+
self.attempts += 1
|
101
|
+
|
102
|
+
break if example.exception.nil?
|
103
|
+
|
104
|
+
break if attempts >= retry_count
|
105
|
+
|
106
|
+
if exceptions_to_retry.any?
|
107
|
+
break unless exceptions_to_retry.any? do |exception_klass|
|
108
|
+
example.exception.is_a?(exception_klass)
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
if verbose_retry? && display_try_failure_messages?
|
113
|
+
if attempts != (retry_count-1)
|
114
|
+
try_message = "#{ordinalize(attempts + 1)} Try error in #{example.location}:\n #{example.exception.to_s} \n"
|
115
|
+
RSpec.configuration.reporter.message(try_message)
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
example.example_group_instance.clear_lets if clear_lets
|
120
|
+
|
121
|
+
sleep sleep_interval if sleep_interval.to_i > 0
|
74
122
|
end
|
75
123
|
end
|
76
124
|
|
125
|
+
private
|
126
|
+
|
77
127
|
# borrowed from ActiveSupport::Inflector
|
78
|
-
def
|
128
|
+
def ordinalize(number)
|
79
129
|
if (11..13).include?(number.to_i % 100)
|
80
130
|
"#{number}th"
|
81
131
|
else
|
@@ -90,4 +140,4 @@ module RSpec
|
|
90
140
|
end
|
91
141
|
end
|
92
142
|
|
93
|
-
RSpec::Retry.
|
143
|
+
RSpec::Retry.setup
|
data/lib/rspec/retry/version.rb
CHANGED
data/lib/rspec_ext/rspec_ext.rb
CHANGED
@@ -120,4 +120,20 @@ describe RSpec::Retry do
|
|
120
120
|
expect(let_based_on_control).to be(!@control)
|
121
121
|
end
|
122
122
|
end
|
123
|
+
|
124
|
+
describe 'running example.run_with_retry in an around filter', retry: 2 do
|
125
|
+
before(:each) { count_up }
|
126
|
+
before(:all) do
|
127
|
+
set_expectations([false, false, true])
|
128
|
+
end
|
129
|
+
|
130
|
+
it 'allows retry options to be overridden', :overridden do
|
131
|
+
expect(RSpec.current_example.metadata[:retry]).to eq(3)
|
132
|
+
end
|
133
|
+
|
134
|
+
it 'uses the overridden options', :overridden do
|
135
|
+
expect(true).to be(shift_expectation)
|
136
|
+
expect(count).to eq(3)
|
137
|
+
end
|
138
|
+
end
|
123
139
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rspec-retry
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yusuke Mito
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2015-
|
12
|
+
date: 2015-11-04 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec-core
|