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

Clean up change_queue_size_of matcher, fix Time#to_s deprecation #23

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
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
36 changes: 26 additions & 10 deletions lib/queue_classic_matchers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -105,20 +105,36 @@ def amount
@amount || 1
end

match do |actual|
old = expected.queue.count
actual.call
new = expected.queue.count
match do |block|
old_count = expected.queue.count
block.call
new_count = expected.queue.count

new - old == (amount || 1)
@actual = new_count - old_count
@actual == amount
end

failure_message do |actual|
"should have a queue size of #{expected} by #{amount}"
match_when_negated do |block|
old_count = expected.queue.count
block.call
new_count = expected.queue.count

if @amount
@actual = new_count - old_count
@actual != amount
else
new_count == old_count
end
end

failure_message_when_negated do |actual|
"should not have a queue size of #{expected} by #{amount}"
failure_message do
change = @actual.zero? ? "did not change" : "changed by #{@actual}"
"should have changed queue size of #{expected} by #{amount} but #{change}"
end

failure_message_when_negated do
chain = @amount.nil? ? "" : " by #{@amount}"
"should not have changed queue size of #{expected}#{chain}"
end

description do
Expand All @@ -130,7 +146,7 @@ def amount
RSpec::Matchers.define :have_scheduled do |*expected_args|
chain :at do |timestamp|
@time = timestamp
@time_info = "at #{@time}"
@time_info = "at #{@time.to_fs}"
end

match do |actual|
Expand Down
2 changes: 1 addition & 1 deletion lib/queue_classic_matchers/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module QueueClassicMatchers
VERSION = '4.0.0.alpha2'
VERSION = '4.0.0.alpha3'
end
13 changes: 13 additions & 0 deletions spec/queue_classic_matchers_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,17 @@ def self.perform
end
end
end

describe 'change_queue_size_of' do
it 'works' do
expect { TestJob.do }.to change_queue_size_of(TestJob)
expect { TestJob.do }.to change_queue_size_of(TestJob).by(1)
expect { TestJob.do; TestJob.do }.to change_queue_size_of(TestJob).by(2)
expect { TestJob }.to_not change_queue_size_of(TestJob)
expect { TestJob.do; TestJob.do }.to_not change_queue_size_of(TestJob).by(1)
expect do
expect { TestJob.do; TestJob.do }.to_not change_queue_size_of(TestJob)
end.to raise_error(RSpec::Expectations::ExpectationNotMetError)
end
end
end