Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better specs for on_max_attempts_exceeded proc #6

Merged
merged 6 commits into from
Apr 1, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/pester.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ def self.retry_action(opts = {}, &block)
opts[:logger].warn("Failure encountered: #{e}, backing off and trying again #{attempts_left} more times. Trace: #{trace}")
opts[:on_retry].call(attempt_num, opts[:delay_interval])
else
# Careful here because you will get back the return value of the on_max_attempts_exceeded proc!
return opts[:on_max_attempts_exceeded].call(opts[:logger], opts[:max_attempts], e)
end
end
Expand Down
25 changes: 21 additions & 4 deletions spec/pester_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,17 +107,34 @@ class UnmatchedError < RuntimeError; end
it_has_behavior 'raises an error'
end

context 'with on_max_attempts_exceeded specified (which does not raise)' do
let(:do_nothing_proc) { proc {} }
context 'with on_max_attempts_exceeded proc specified' do
let(:options) do
{
max_attempts: max_attempts,
on_max_attempts_exceeded: do_nothing_proc,
on_max_attempts_exceeded: proc_to_call,
logger: null_logger
}
end

it_has_behavior "doesn't raise an error"
context 'which does not do anything' do
let(:proc_to_call) { proc {} }
it_has_behavior "doesn't raise an error"
end

context 'which reraises' do
let(:proc_to_call) { Behaviors::WarnAndReraise }
it_has_behavior 'raises an error'
end

context 'which returns a value' do
let(:return_value) { 'return_value' }
let(:proc_to_call) { proc { return_value } }
it_has_behavior "doesn't raise an error"

it 'should return the result of the proc' do
expect(Pester.retry_action(options) { action }).to eq(return_value)
end
end
end
end

Expand Down