Skip to content

Commit

Permalink
RSpec 3.3.0 alterations
Browse files Browse the repository at this point in the history
Mock "receive" calls appear to use a stronger interpretation of
equality.

Also altered assertions around raised errors to suppress new warnings.
  • Loading branch information
gshutler authored and mariokostelac committed Dec 13, 2016
1 parent 1fd45b0 commit 314038d
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 10 deletions.
6 changes: 6 additions & 0 deletions lib/shoryuken/polling.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
module Shoryuken
module Polling
QueueConfiguration = Struct.new(:name, :options) do
def hash
name.hash
end

def ==(other)
case other
when String
Expand All @@ -13,6 +17,8 @@ def ==(other)
super
end
end

alias_method :eql?, :==
end

class WeightedRoundRobin
Expand Down
8 changes: 4 additions & 4 deletions spec/shoryuken/fetcher_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
it 'calls pause when no message' do
allow(queue).to receive(:receive_messages).with(max_number_of_messages: 1, attribute_names: ['All'], message_attribute_names: ['All']).and_return([])

expect(manager).to receive(:queue_empty).with(queue_name)
expect(manager).to receive(:queue_empty).with(queue_config)
expect(manager).to receive(:dispatch)

subject.fetch(queue_config, 1)
Expand All @@ -36,7 +36,7 @@
it 'assigns messages' do
allow(queue).to receive(:receive_messages).with(max_number_of_messages: 5, attribute_names: ['All'], message_attribute_names: ['All']).and_return(sqs_msg)

expect(manager).to receive(:messages_present).with(queue_name)
expect(manager).to receive(:messages_present).with(queue_config)
expect(manager).to receive(:assign).with(queue_name, sqs_msg)
expect(manager).to receive(:dispatch)

Expand All @@ -48,7 +48,7 @@

allow(queue).to receive(:receive_messages).with(max_number_of_messages: described_class::FETCH_LIMIT, attribute_names: ['All'], message_attribute_names: ['All']).and_return(sqs_msg)

expect(manager).to receive(:messages_present).with(queue_name)
expect(manager).to receive(:messages_present).with(queue_config)
expect(manager).to receive(:assign).with(queue_name, [sqs_msg])
expect(manager).to receive(:dispatch)

Expand All @@ -61,7 +61,7 @@
it 'ignores batch' do
allow(queue).to receive(:receive_messages).with(max_number_of_messages: 5, attribute_names: ['All'], message_attribute_names: ['All']).and_return(sqs_msg)

expect(manager).to receive(:messages_present).with(queue_name)
expect(manager).to receive(:messages_present).with(queue_config)
expect(manager).to receive(:assign).with(queue_name, sqs_msg)
expect(manager).to receive(:dispatch)

Expand Down
4 changes: 2 additions & 2 deletions spec/shoryuken/middleware/server/auto_delete_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ def build_message
expect(sqs_queue).to_not receive(:delete_messages)

expect {
subject.call(TestWorker.new, queue, sqs_msg, sqs_msg.body) { raise 'Error' }
}.to raise_error(RuntimeError, 'Error')
subject.call(TestWorker.new, queue, sqs_msg, sqs_msg.body) { raise 'failed' }
}.to raise_error('failed')
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
allow(sqs_msg).to receive(:queue){ sqs_queue }
expect(sqs_msg).to receive(:change_visibility).with(visibility_timeout: 300)

expect { subject.call(TestWorker.new, queue, sqs_msg, sqs_msg.body) { raise } }.not_to raise_error
expect { subject.call(TestWorker.new, queue, sqs_msg, sqs_msg.body) { raise 'failed' } }.not_to raise_error
end

it 'retries the job with exponential backoff' do
Expand All @@ -56,7 +56,7 @@
allow(sqs_msg).to receive(:queue){ sqs_queue }
expect(sqs_msg).to receive(:change_visibility).with(visibility_timeout: 1800)

expect { subject.call(TestWorker.new, queue, sqs_msg, sqs_msg.body) { raise } }.not_to raise_error
expect { subject.call(TestWorker.new, queue, sqs_msg, sqs_msg.body) { raise 'failed' } }.not_to raise_error
end

it 'uses the last retry interval when :receive_count exceeds the size of :retry_intervals' do
Expand All @@ -66,7 +66,7 @@
allow(sqs_msg).to receive(:queue){ sqs_queue }
expect(sqs_msg).to receive(:change_visibility).with(visibility_timeout: 1800)

expect { subject.call(TestWorker.new, queue, sqs_msg, sqs_msg.body) { raise } }.not_to raise_error
expect { subject.call(TestWorker.new, queue, sqs_msg, sqs_msg.body) { raise 'failed' } }.not_to raise_error
end

it 'limits the visibility timeout to 12 hours from receipt of message' do
Expand All @@ -75,7 +75,7 @@
allow(sqs_msg).to receive(:queue){ sqs_queue }
expect(sqs_msg).to receive(:change_visibility).with(visibility_timeout: 43198)

expect { subject.call(TestWorker.new, queue, sqs_msg, sqs_msg.body) { raise } }.not_to raise_error
expect { subject.call(TestWorker.new, queue, sqs_msg, sqs_msg.body) { raise 'failed' } }.not_to raise_error
end
end
end

0 comments on commit 314038d

Please sign in to comment.