rspec-retry 0.4.5 → 0.4.6

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 08f3170cb5eb3a96fbf45a6facaac88f02261c99
4
- data.tar.gz: a7831c2d528f9fb89f04aba2da2d0caf989741a3
3
+ metadata.gz: 80a92fbfbdc8b02950034f0bb7bdd72128e4cfc5
4
+ data.tar.gz: ee08ca136b1b395852588248cba85979e98addc3
5
5
  SHA512:
6
- metadata.gz: 345abf819be3c81a57da26220b46c6d19441d012350d101ff97ecec3d98e1d6d9f552ecb18e62600827fb3beb76911937a13e15f097ad1338e4a25650e4c7ce0
7
- data.tar.gz: 21c46735aac3ae909c27b162b65eff164a4a7bb36233efdf55f65b6fcfbd3bd35a3775b58dbbb5a870ce8c09369559f75ccd52f9eccef90ba00e9ce46fd1693a
6
+ metadata.gz: a4bde86cebd9d880131499789b673b2466ef4a75269084bcd28e82810bd35d07bc091cceb420c06bef1559701301c2275930eba94e9ff2274f8cf5b53ddd4b16
7
+ data.tar.gz: 0fa26f941a2cba998405e42d07c8d962a909ead3e015f40182db03b0c8d2a2d78f136ccb74ab19bddf88d0033c3c88cdc21e1856837c5eb9169ca5618f7ac7a0
data/README.md CHANGED
@@ -64,6 +64,7 @@ You can call `ex.run_with_retry(opts)` on an individual example.
64
64
  - __:default_retry_count__(default: *1*) If retry count is not set in an example, this value is used by default
65
65
  - __:default_sleep_interval__(default: *0*) Seconds to wait between retries
66
66
  - __:clear_lets_on_failure__(default: *true*) Clear memoized values for ``let``s before retrying
67
+ - __:exceptions_to_hard_fail__(default: *[]*) List of exceptions that will trigger an immediate test failure without retry. Takes precedence over __:exceptions_to_retry__
67
68
  - __:exceptions_to_retry__(default: *[]*) List of exceptions that will trigger a retry (when empty, all exceptions will)
68
69
 
69
70
  ## Environment Variables
@@ -1,8 +1,12 @@
1
+ # 0.4.6 - 2016-8-8
2
+ failure message was off by 1 (thanks @anthonywoo, @vgrigoruk / #57)
3
+ add the `exceptions_to_hard_fail` options (thanks @james-dominy, @ShockwaveNN / #59)
4
+ add retry reporter & api for accessing retry from reporter (thanks @tdeo / #54)
5
+
1
6
  # 0.4.5 - 2015-11-4
2
7
  ## enhancements
3
8
  retry can be called programmatically (thanks, @dwbutler / #45)
4
9
 
5
-
6
10
  # 0.4.4 - 2015-9-9
7
11
  ## bugfixes
8
12
  fix gem permissions to be readable (thanks @jdelStrother / #42)
@@ -11,6 +11,14 @@ module RSpec
11
11
  config.add_setting :default_sleep_interval, :default => 0
12
12
  config.add_setting :clear_lets_on_failure, :default => true
13
13
  config.add_setting :display_try_failure_messages, :default => false
14
+
15
+ # If a list of exceptions is provided and 'retry' > 1, we only retry if
16
+ # the exception that was raised by the example is NOT in that list. Otherwise
17
+ # we ignore the 'retry' value and fail immediately.
18
+ #
19
+ # If no list of exceptions is provided and 'retry' > 1, we always retry.
20
+ config.add_setting :exceptions_to_hard_fail, :default => []
21
+
14
22
  # If a list of exceptions is provided and 'retry' > 1, we only retry if
15
23
  # the exception that was raised by the example is in that list. Otherwise
16
24
  # we ignore the 'retry' value and fail immediately.
@@ -69,6 +77,11 @@ module RSpec
69
77
  RSpec.configuration.default_sleep_interval
70
78
  end
71
79
 
80
+ def exceptions_to_hard_fail
81
+ ex.metadata[:exceptions_to_hard_fail] ||
82
+ RSpec.configuration.exceptions_to_hard_fail
83
+ end
84
+
72
85
  def exceptions_to_retry
73
86
  ex.metadata[:exceptions_to_retry] ||
74
87
  RSpec.configuration.exceptions_to_retry
@@ -86,8 +99,9 @@ module RSpec
86
99
  example = current_example
87
100
 
88
101
  loop do
89
- if verbose_retry?
90
- if attempts > 0
102
+ if attempts > 0
103
+ RSpec.configuration.formatters.each { |f| f.retry(example) if f.respond_to? :retry }
104
+ if verbose_retry?
91
105
  message = "RSpec::Retry: #{ordinalize(attempts + 1)} try #{example.location}"
92
106
  message = "\n" + message if attempts == 1
93
107
  RSpec.configuration.reporter.message(message)
@@ -103,6 +117,12 @@ module RSpec
103
117
 
104
118
  break if attempts >= retry_count
105
119
 
120
+ if exceptions_to_hard_fail.any?
121
+ break if exceptions_to_hard_fail.any? do |exception_klass|
122
+ example.exception.is_a?(exception_klass)
123
+ end
124
+ end
125
+
106
126
  if exceptions_to_retry.any?
107
127
  break unless exceptions_to_retry.any? do |exception_klass|
108
128
  example.exception.is_a?(exception_klass)
@@ -110,8 +130,8 @@ module RSpec
110
130
  end
111
131
 
112
132
  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"
133
+ if attempts != retry_count
134
+ try_message = "#{ordinalize(attempts)} Try error in #{example.location}:\n #{example.exception.to_s} \n"
115
135
  RSpec.configuration.reporter.message(try_message)
116
136
  end
117
137
  end
@@ -0,0 +1,56 @@
1
+ require 'rspec/core/formatters/base_text_formatter'
2
+
3
+ class RSpec::Retry::Formatter < RSpec::Core::Formatters::BaseTextFormatter
4
+ RSpec::Core::Formatters.register self, :example_passed
5
+
6
+ def initialize(output)
7
+ super(output)
8
+ @tries = Hash.new { |h, k| h[k] = { successes: 0, tries: 0 } }
9
+ end
10
+
11
+ def seed(_); end
12
+
13
+ def message(_message); end
14
+
15
+ def close(_); end
16
+
17
+ def dump_failures(_); end
18
+
19
+ def dump_pending(_); end
20
+
21
+ def dump_summary(notification)
22
+ output = "\nRSpec Retry Summary:\n"
23
+ @tries.each do |key, retry_data|
24
+ next if retry_data[:successes] < 1 || retry_data[:tries] <= 1
25
+ output += "\t#{key.location}: #{key.full_description}: passed at attempt #{retry_data[:tries]}\n"
26
+ end
27
+ retried = @tries.count { |_, v| v[:tries] > 1 && v[:successes] > 0 }
28
+ output += "\n\t#{retried} of #{notification.example_count} tests passed with retries.\n"
29
+ output += "\t#{notification.failure_count} tests failed all retries.\n"
30
+ puts output
31
+ end
32
+
33
+ def example_passed(notification)
34
+ increment_success notification.example
35
+ end
36
+
37
+ def retry(example)
38
+ increment_tries example
39
+ end
40
+
41
+ private
42
+
43
+ def increment_success(example)
44
+ # debugger
45
+ previous = @tries[example]
46
+ @tries[example] = {
47
+ successes: previous[:successes] + 1, tries: previous[:tries] + 1 }
48
+ end
49
+
50
+ def increment_tries(example)
51
+ # debugger
52
+ previous = @tries[example]
53
+ @tries[example] = {
54
+ successes: previous[:successes], tries: previous[:tries] + 1 }
55
+ end
56
+ end
@@ -1,5 +1,5 @@
1
1
  module RSpec
2
2
  class Retry
3
- VERSION = "0.4.5"
3
+ VERSION = "0.4.6"
4
4
  end
5
5
  end
@@ -19,6 +19,13 @@ describe RSpec::Retry do
19
19
  @expectations.shift
20
20
  end
21
21
 
22
+ class RetryError < StandardError; end
23
+ class RetryChildError < RetryError; end
24
+ class HardFailError < StandardError; end
25
+ class HardFailChildError < HardFailError; end
26
+ class OtherError < StandardError; end;
27
+ class SharedError < StandardError; end;
28
+
22
29
  before(:all) do
23
30
  ENV.delete('RSPEC_RETRY_RETRY_COUNT')
24
31
  end
@@ -77,17 +84,42 @@ describe RSpec::Retry do
77
84
  end
78
85
  end
79
86
 
80
- describe "with a list of exceptions", :retry => 2, :exceptions_to_retry => [NameError] do
87
+ describe "with a list of exceptions to immediately fail on", :retry => 2, :exceptions_to_hard_fail => [HardFailError] do
88
+ context "the example throws an exception contained in the hard fail list" do
89
+ it "does not retry" do
90
+ expect(count).to be < 2
91
+ pending "This should fail with a count of 1: Count was #{count}"
92
+ raise HardFailError unless count > 1
93
+ end
94
+ end
95
+
96
+ context "the example throws a child of an exception contained in the hard fail list" do
97
+ it "does not retry" do
98
+ expect(count).to be < 2
99
+ pending "This should fail with a count of 1: Count was #{count}"
100
+ raise HardFailChildError unless count > 1
101
+ end
102
+ end
103
+
104
+ context "the throws an exception not contained in the hard fail list" do
105
+ it "retries the maximum number of times" do
106
+ raise OtherError unless count > 1
107
+ expect(count).to eq(2)
108
+ end
109
+ end
110
+ end
111
+
112
+ describe "with a list of exceptions to retry on", :retry => 2, :exceptions_to_retry => [RetryError] do
81
113
  context "the example throws an exception contained in the retry list" do
82
114
  it "retries the maximum number of times" do
83
- raise NameError unless count > 1
115
+ raise RetryError unless count > 1
84
116
  expect(count).to eq(2)
85
117
  end
86
118
  end
87
119
 
88
120
  context "the example throws a child of an exception contained in the retry list" do
89
121
  it "retries the maximum number of times" do
90
- raise NoMethodError unless count > 1
122
+ raise RetryChildError unless count > 1
91
123
  expect(count).to eq(2)
92
124
  end
93
125
  end
@@ -99,6 +131,39 @@ describe RSpec::Retry do
99
131
  end
100
132
  end
101
133
  end
134
+
135
+ describe "with both hard fail and retry list of exceptions", :retry => 2, :exceptions_to_retry => [SharedError, RetryError], :exceptions_to_hard_fail => [SharedError, HardFailError] do
136
+ context "the exception thrown exists in both lists" do
137
+ it "does not retry because the hard fail list takes precedence" do
138
+ expect(count).to be < 2
139
+ pending "This should fail with a count of 1: Count was #{count}"
140
+ raise SharedError unless count > 1
141
+ end
142
+ end
143
+
144
+ context "the example throws an exception contained in the hard fail list" do
145
+ it "does not retry because the hard fail list takes precedence" do
146
+ expect(count).to be < 2
147
+ pending "This should fail with a count of 1: Count was #{count}"
148
+ raise HardFailError unless count > 1
149
+ end
150
+ end
151
+
152
+ context "the example throws an exception contained in the retry list" do
153
+ it "retries the maximum number of times because the hard fail list doesn't affect this exception" do
154
+ raise RetryError unless count > 1
155
+ expect(count).to eq(2)
156
+ end
157
+ end
158
+
159
+ context "the example throws an exception contained in neither list" do
160
+ it "does not retry because the the exception is not in the retry list" do
161
+ expect(count).to be < 2
162
+ pending "This should fail with a count of 1: Count was #{count}"
163
+ raise OtherError unless count > 1
164
+ end
165
+ end
166
+ end
102
167
  end
103
168
 
104
169
  describe 'clearing lets' do
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.5
4
+ version: 0.4.6
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-11-04 00:00:00.000000000 Z
12
+ date: 2016-08-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec-core
@@ -102,6 +102,7 @@ files:
102
102
  - gemfiles/rspec_3.3.gemfile
103
103
  - gemfiles/rspec_3.3.gemfile.lock
104
104
  - lib/rspec/retry.rb
105
+ - lib/rspec/retry/formatter.rb
105
106
  - lib/rspec/retry/version.rb
106
107
  - lib/rspec_ext/rspec_ext.rb
107
108
  - rspec-retry.gemspec
@@ -126,7 +127,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
126
127
  version: '0'
127
128
  requirements: []
128
129
  rubyforge_project:
129
- rubygems_version: 2.2.2
130
+ rubygems_version: 2.4.5.1
130
131
  signing_key:
131
132
  specification_version: 4
132
133
  summary: retry intermittently failing rspec examples