Skip to content

Commit

Permalink
Expose RSpec::Core::Example#attempts via Procsy
Browse files Browse the repository at this point in the history
This is useful for around/after hooks to check how many retries are actually attempted.
  • Loading branch information
knu committed Jul 24, 2019
1 parent e3191f7 commit 4259458
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/rspec_ext/rspec_ext.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ class Procsy
def run_with_retry(opts = {})
RSpec::Retry.new(self, opts).run
end

def attempts
@example.attempts
end
end
end
end
Expand Down
31 changes: 31 additions & 0 deletions spec/lib/rspec/retry_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,37 @@ def self.===(other)
end
end

describe 'Example::Procsy#attempts' do
let!(:example_group) do
RSpec.describe do
before :all do
@@results = {}
end

around do |example|
example.run_with_retry
@@results[example.description] = [example.exception.nil?, example.attempts]
end

specify 'without retry option' do
expect(true).to be(true)
end

specify 'with retry option', retry: 3 do
expect(true).to be(false)
end
end
end

it 'should be exposed' do
example_group.run
expect(example_group.class_variable_get(:@@results)).to eq({
'without retry option' => [true, 1],
'with retry option' => [false, 3]
})
end
end

describe 'output in verbose mode' do

line_1 = __LINE__ + 8
Expand Down

0 comments on commit 4259458

Please sign in to comment.