Skip to content

Commit

Permalink
Merge pull request #106 from drummond-work/expose-retry-exceptions
Browse files Browse the repository at this point in the history
Expose retry exceptions to example metadata
  • Loading branch information
michaelglass committed Nov 21, 2019
2 parents f85628d + cea8597 commit d467b57
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/rspec/retry.rb
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ def run
end

example.metadata[:retry_attempts] = self.attempts
example.metadata[:retry_exceptions] ||= []

example.clear_exception
ex.run
Expand All @@ -126,6 +127,8 @@ def run

break if example.exception.nil?

example.metadata[:retry_exceptions] << example.exception

break if attempts >= retry_count

if exceptions_to_hard_fail.any?
Expand Down
13 changes: 13 additions & 0 deletions spec/lib/rspec/retry_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,19 @@ class SharedError < StandardError; end

expect(retry_attempts).to eq(2)
end

let(:retry_exceptions) do
example_group.examples.first.metadata[:retry_exceptions]
end

it 'should add exceptions into retry_exceptions metadata array' do
example_group.example { instance_eval($example_code) }
example_group.run

expect(retry_exceptions.count).to eq(2)
expect(retry_exceptions[0].class).to eq NameError
expect(retry_exceptions[1].class).to eq NameError
end
end

context "the example throws an exception contained in the retry list" do
Expand Down

0 comments on commit d467b57

Please sign in to comment.