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

Show failure message with actual arguments #79

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
44 changes: 38 additions & 6 deletions lib/resque_spec/matchers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,22 @@ def queue(actual)
end
end

def actual_args(actual)
if queue(actual).first
queue(actual).first[:args]
else
[]
end
end

def actual_args_str(actual)
if actual_args(actual).empty?
'no args'
else
actual_args(actual).join(', ')
end
end

end

RSpec::Matchers.define :have_queued do |*expected_args|
Expand Down Expand Up @@ -54,11 +70,11 @@ def queue(actual)
end

failure_message_for_should do |actual|
"expected that #{actual} would have [#{expected_args.join(', ')}] queued#{@times_info}"
"expected that #{actual} would have [#{expected_args.join(', ')}] queued#{@times_info} but actually #{actual} with [#{actual_args_str(actual)}]"
end

failure_message_for_should_not do |actual|
"expected that #{actual} would not have [#{expected_args.join(', ')}] queued#{@times_info}"
"expected that #{actual} would not have [#{expected_args.join(', ')}] queued#{@times_info} but actually #{actual} with [#{actual_args_str(actual)}]"
end

description do
Expand Down Expand Up @@ -128,6 +144,22 @@ def schedule_queue_for(actual)
end
end

def actual_args(actual)
if schedule_queue_for(actual).first
schedule_queue_for(actual).first[:args]
else
[]
end
end

def actual_args_str(actual)
if actual_args(actual).empty?
'no args'
else
actual_args(actual).join(', ')
end
end

end

RSpec::Matchers.define :have_scheduled do |*expected_args|
Expand Down Expand Up @@ -163,11 +195,11 @@ def schedule_queue_for(actual)
end

failure_message_for_should do |actual|
["expected that #{actual} would have [#{expected_args.join(', ')}] scheduled", @time_info].join(' ')
["expected that #{actual} would have [#{expected_args.join(', ')}] scheduled but actually #{actuall} with [#{actual_args_str(actual)}]", @time_info].join(' ')
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actuall should be actual.

end

failure_message_for_should_not do |actual|
["expected that #{actual} would not have [#{expected_args.join(', ')}] scheduled", @time_info].join(' ')
["expected that #{actual} would not have [#{expected_args.join(', ')}] scheduled but actually #{actuall} with [#{actual_args_str(actual)}]", @time_info].join(' ')
end

description do
Expand All @@ -186,11 +218,11 @@ def schedule_queue_for(actual)
end

failure_message_for_should do |actual|
"expected that #{actual} would have [#{expected_args.join(', ')}] scheduled"
"expected that #{actual} would have [#{expected_args.join(', ')}] scheduled but actually #{actual} with [#{actual_args_str(actual)}]"
end

failure_message_for_should_not do |actual|
"expected that #{actual} would not have [#{expected_args.join(', ')}] scheduled"
"expected that #{actual} would not have [#{expected_args.join(', ')}] scheduled but actually #{actual} with [#{actual_args_str(actual)}]"
end

description do
Expand Down