spec/retriable_spec.rb in retriable-3.0.0 vs spec/retriable_spec.rb in retriable-3.0.1
- old
+ new
@@ -41,11 +41,11 @@
tries = 0
expect do
subject.retriable do
tries += 1
- raise StandardError.new
+ raise StandardError.new, "StandardError occurred"
end
end.must_raise StandardError
expect(tries).must_equal 3
end
@@ -54,11 +54,11 @@
tries = 0
expect do
subject.retriable do
tries += 1
- raise TestError.new
+ raise TestError.new, "TestError occurred"
end
end.must_raise TestError
expect(tries).must_equal 1
end
@@ -67,26 +67,24 @@
tries = 0
expect do
subject.retriable on: TestError do
tries += 1
- raise TestError.new
+ raise TestError.new, "TestError occurred"
end
end.must_raise TestError
expect(tries).must_equal 3
end
it "#retriable tries 10 times" do
tries = 0
expect do
- subject.retriable(
- tries: 10,
- ) do
+ subject.retriable(tries: 10) do
tries += 1
- raise StandardError.new
+ raise StandardError.new, "StandardError occurred"
end
end.must_raise StandardError
expect(tries).must_equal 10
end
@@ -101,11 +99,11 @@
it "applies a randomized exponential backoff to each try" do
tries = 0
time_table = []
- handler = ->(exception, try, elapsed_time, next_interval) do
+ handler = lambda do |exception, _try, _elapsed_time, next_interval|
expect(exception.class).must_equal ArgumentError
time_table << next_interval
end
expect do
@@ -113,11 +111,11 @@
on: [EOFError, ArgumentError],
on_retry: handler,
tries: 10,
) do
tries += 1
- raise ArgumentError.new
+ raise ArgumentError.new, "ArgumentError occurred"
end
end.must_raise ArgumentError
expect(time_table).must_equal([
0.5244067512211441,
@@ -139,11 +137,11 @@
before do
tries = 6
@try_count = 0
@time_table = {}
- handler = ->(exception, try, elapsed_time, next_interval) do
+ handler = lambda do |exception, try, _elapsed_time, next_interval|
expect(exception.class).must_equal ArgumentError
@time_table[try] = next_interval
end
Retriable.retriable(
@@ -151,34 +149,34 @@
on_retry: handler,
rand_factor: 0.0,
tries: tries,
) do
@try_count += 1
- raise ArgumentError.new if @try_count < tries
+ raise ArgumentError.new, "ArgumentError occurred" if @try_count < tries
end
end
it "makes 6 tries" do
expect(@try_count).must_equal 6
end
it "applies a non-randomized exponential backoff to each try" do
- expect(@time_table).must_equal({
+ expect(@time_table).must_equal(
1 => 0.5,
2 => 0.75,
3 => 1.125,
4 => 1.6875,
5 => 2.53125,
- })
+ )
end
end
it "#retriable has a max interval of 1.5 seconds" do
tries = 0
time_table = {}
- handler = ->(exception, try, elapsed_time, next_interval) do
+ handler = lambda do |_exception, try, _elapsed_time, next_interval|
time_table[try] = next_interval
end
expect do
subject.retriable(
@@ -187,21 +185,21 @@
rand_factor: 0.0,
tries: 5,
max_interval: 1.5,
) do
tries += 1
- raise StandardError.new
+ raise StandardError.new, "StandardError occurred"
end
end.must_raise StandardError
- expect(time_table).must_equal({
+ expect(time_table).must_equal(
1 => 0.5,
2 => 0.75,
3 => 1.125,
4 => 1.5,
5 => nil,
- })
+ )
end
it "#retriable with custom defined intervals" do
intervals = [
0.5,
@@ -210,11 +208,11 @@
1.5,
1.5,
]
time_table = {}
- handler = ->(exception, try, elapsed_time, next_interval) do
+ handler = lambda do |_exception, try, _elapsed_time, next_interval|
time_table[try] = next_interval
end
try_count = 0
@@ -222,44 +220,49 @@
subject.retriable(
on_retry: handler,
intervals: intervals,
) do
try_count += 1
- raise StandardError.new
+ raise StandardError.new, "StandardError occurred"
end
end.must_raise StandardError
- expect(time_table).must_equal({
+ expect(time_table).must_equal(
1 => 0.5,
2 => 0.75,
3 => 1.125,
4 => 1.5,
5 => 1.5,
6 => nil,
- })
+ )
expect(try_count).must_equal(6)
end
it "#retriable with a hash exception where the value is an exception message pattern" do
e = expect do
subject.retriable on: { TestError => /something went wrong/ } do
- raise TestError.new('something went wrong')
+ raise TestError, "something went wrong"
end
end.must_raise TestError
expect(e.message).must_equal "something went wrong"
end
it "#retriable with a hash exception list matches exception subclasses" do
class SecondTestError < TestError; end
+ class DifferentTestError < Exception; end
tries = 0
e = expect do
- subject.retriable on: { TestError => /something went wrong/ }, tries: 4 do
+ subject.retriable on: {
+ DifferentTestError => /should never happen/,
+ TestError => /something went wrong/,
+ DifferentTestError => /also should never happen/,
+ }, tries: 4 do
tries += 1
- raise SecondTestError.new('something went wrong')
+ raise SecondTestError, "something went wrong"
end
end.must_raise SecondTestError
expect(e.message).must_equal "something went wrong"
expect(tries).must_equal 4
@@ -267,39 +270,39 @@
it "#retriable with a hash exception list does not retry matching exception subclass but not message" do
class SecondTestError < TestError; end
tries = 0
- e = expect do
+ expect do
subject.retriable on: { TestError => /something went wrong/ }, tries: 4 do
tries += 1
- raise SecondTestError.new('not a match')
+ raise SecondTestError, "not a match"
end
end.must_raise SecondTestError
expect(tries).must_equal 1
end
it "#retriable with a hash exception list where the values are exception message patterns" do
tries = 0
exceptions = []
- handler = ->(exception, try, elapsed_time, next_interval) do
+ handler = lambda do |exception, try, _elapsed_time, _next_interval|
exceptions[try] = exception
end
e = expect do
subject.retriable tries: 4, on: { StandardError => nil, TestError => [/foo/, /bar/] }, on_retry: handler do
tries += 1
case tries
when 1
- raise TestError.new('foo')
+ raise TestError, "foo"
when 2
- raise TestError.new('bar')
+ raise TestError, "bar"
when 3
- raise StandardError.new
+ raise StandardError
else
- raise TestError.new('crash')
+ raise TestError, "crash"
end
end
end.must_raise TestError
expect(e.message).must_equal "crash"
@@ -322,11 +325,11 @@
tries = 0
expect do
retriable do
tries += 1
- raise StandardError.new
+ raise StandardError
end
end.must_raise StandardError
expect(tries).must_equal 3
end
@@ -340,11 +343,11 @@
expect(subject.config.sleep_disabled).must_equal false
tries = 0
time_table = {}
- handler = ->(exception, try, elapsed_time, next_interval) do
+ handler = lambda do |_exception, try, elapsed_time, _next_interval|
time_table[try] = elapsed_time
end
expect do
subject.retriable(
@@ -353,10 +356,10 @@
rand_factor: 0.0,
max_elapsed_time: 2.0,
on_retry: handler,
) do
tries += 1
- raise EOFError.new
+ raise EOFError
end
end.must_raise EOFError
expect(tries).must_equal 2
end