rspec-retry 0.4.4 → 0.4.5

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: 008b1a27e8172edef3f280100e8c09e5ff1de464
4
- data.tar.gz: 1f3fd40fb38f9153c54cdef670afbe11c28fef63
3
+ metadata.gz: 08f3170cb5eb3a96fbf45a6facaac88f02261c99
4
+ data.tar.gz: a7831c2d528f9fb89f04aba2da2d0caf989741a3
5
5
  SHA512:
6
- metadata.gz: 40448141b2e12f26154857e1d01405f0f1ea419bd0098d773f5a56f13e566d1d19192e07b23498008c4c248a0de5edf6d397b3a9a9139192417846af1d64d8ea
7
- data.tar.gz: be2f5439c48af600527aedb9bce67e846c13a62005eb153aca13ef6279146da41815f6e0520b7d3674e290f8e679ac2134365b53e973c0d678685f878aa2b287
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
@@ -1,3 +1,8 @@
1
+ # 0.4.5 - 2015-11-4
2
+ ## enhancements
3
+ retry can be called programmatically (thanks, @dwbutler / #45)
4
+
5
+
1
6
  # 0.4.4 - 2015-9-9
2
7
  ## bugfixes
3
8
  fix gem permissions to be readable (thanks @jdelStrother / #42)
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ../
3
3
  specs:
4
- rspec-retry (0.4.4)
4
+ rspec-retry (0.4.5)
5
5
  rspec-core
6
6
 
7
7
  GEM
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ../
3
3
  specs:
4
- rspec-retry (0.4.4)
4
+ rspec-retry (0.4.5)
5
5
  rspec-core
6
6
 
7
7
  GEM
@@ -4,7 +4,7 @@ require 'rspec_ext/rspec_ext'
4
4
 
5
5
  module RSpec
6
6
  class Retry
7
- def self.apply
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
- example = fetch_current_example.call(self)
22
+ ex.run_with_retry
23
+ end
24
+ end
25
+ end
26
+
27
+ attr_reader :context, :ex
28
28
 
29
- retry_count = [
30
- (
31
- ENV['RSPEC_RETRY_RETRY_COUNT'] ||
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
- ).to_i,
35
- 1
36
- ].max
37
-
38
- sleep_interval = ex.metadata[:retry_wait] || RSpec.configuration.default_sleep_interval
39
- exceptions_to_retry = ex.metadata[:exceptions_to_retry] || RSpec.configuration.exceptions_to_retry
40
-
41
- clear_lets = ex.metadata[:clear_lets_on_failure]
42
- clear_lets = RSpec.configuration.clear_lets_on_failure if clear_lets.nil?
43
-
44
- retry_count.times do |i|
45
- if RSpec.configuration.verbose_retry?
46
- if i > 0
47
- message = "RSpec::Retry: #{RSpec::Retry.ordinalize(i + 1)} try #{example.location}"
48
- message = "\n" + message if i == 1
49
- RSpec.configuration.reporter.message(message)
50
- end
51
- end
52
- example.clear_exception
53
- ex.run
54
-
55
- break if example.exception.nil?
56
-
57
- if exceptions_to_retry.any?
58
- break unless exceptions_to_retry.any? do |exception_klass|
59
- example.exception.is_a?(exception_klass)
60
- end
61
- end
62
-
63
- if RSpec.configuration.verbose_retry? && RSpec.configuration.display_try_failure_messages?
64
- if i != (retry_count-1)
65
- try_message = "#{RSpec::Retry.ordinalize(i + 1)} Try error in #{example.location}:\n #{example.exception.to_s} \n"
66
- RSpec.configuration.reporter.message(try_message)
67
- end
68
- end
69
-
70
- self.clear_lets if clear_lets
71
- sleep sleep_interval if sleep_interval.to_i > 0
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 self.ordinalize(number)
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.apply
143
+ RSpec::Retry.setup
@@ -1,5 +1,5 @@
1
1
  module RSpec
2
2
  class Retry
3
- VERSION = "0.4.4"
3
+ VERSION = "0.4.5"
4
4
  end
5
5
  end
@@ -1,9 +1,17 @@
1
1
  module RSpec
2
2
  module Core
3
3
  class Example
4
+ attr_accessor :attempts
5
+
4
6
  def clear_exception
5
7
  @exception = nil
6
8
  end
9
+
10
+ class Procsy
11
+ def run_with_retry(opts = {})
12
+ RSpec::Retry.new(self, opts).run
13
+ end
14
+ end
7
15
  end
8
16
  end
9
17
  end
@@ -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
@@ -8,4 +8,9 @@ end
8
8
 
9
9
  RSpec.configure do |config|
10
10
  config.verbose_retry = true
11
+ config.display_try_failure_messages = true
12
+
13
+ config.around :each, :overridden do |ex|
14
+ ex.run_with_retry retry: 3
15
+ end
11
16
  end
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
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-09-09 00:00:00.000000000 Z
12
+ date: 2015-11-04 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec-core