Skip to content

Commit

Permalink
Show failure message with actual arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
kyanny committed Nov 11, 2013
1 parent c4ceed5 commit 14243db
Showing 1 changed file with 38 additions and 6 deletions.
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(' ')
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

0 comments on commit 14243db

Please sign in to comment.