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

Conversation

kyanny
Copy link

@kyanny kyanny commented Nov 11, 2013

Some matchers of ResqueSpec shows expected arguments in failure message but not show actual arguments.
This change adds actual arguments in failure message to make debugging test with ResqueSpec more easier.

Sample code for this change is here. https://github.com/kyanny/resque_spec_test

Before this change, have_queued matcher shows these failure messages:

$ bundle exec rake spec
/Users/kyanny/.rbenv/versions/2.0.0-p247/bin/ruby -S rspec ./spec/app_spec.rb
Resque::Helpers will be gone with no replacement in Resque 2.0.0.

App
  with different args (FAILED - 1)
  with no args (FAILED - 2)

Failures:

  1) App with different args
     Failure/Error: Job.should have_queued('a', 'b', 'c')
       expected that Job would have [a, b, c] queued
     # ./spec/app_spec.rb:8:in `block (2 levels) in <top (required)>'

  2) App with no args
     Failure/Error: Job.should have_queued('a', 'b', 'c')
       expected that Job would have [a, b, c] queued
     # ./spec/app_spec.rb:13:in `block (2 levels) in <top (required)>'

Finished in 0.00171 seconds
2 examples, 2 failures

Failed examples:

rspec ./spec/app_spec.rb:6 # App with different args
rspec ./spec/app_spec.rb:11 # App with no args
/Users/kyanny/.rbenv/versions/2.0.0-p247/bin/ruby -S rspec ./spec/app_spec.rb failed

After this change, have_queued matcher shows more valuable failure messages: (see the difference in faillure message starts with but actually ...)

$ bundle exec rake spec
/Users/kyanny/.rbenv/versions/2.0.0-p247/bin/ruby -S rspec ./spec/app_spec.rb
Resque::Helpers will be gone with no replacement in Resque 2.0.0.

App
  with different args (FAILED - 1)
  with no args (FAILED - 2)

Failures:

  1) App with different args
     Failure/Error: Job.should have_queued('a', 'b', 'c')
       expected that Job would have [a, b, c] queued but actually Job with [1, 2, 3]
     # ./spec/app_spec.rb:8:in `block (2 levels) in <top (required)>'

  2) App with no args
     Failure/Error: Job.should have_queued('a', 'b', 'c')
       expected that Job would have [a, b, c] queued but actually Job with [no args]
     # ./spec/app_spec.rb:13:in `block (2 levels) in <top (required)>'

Finished in 0.00177 seconds
2 examples, 2 failures

Failed examples:

rspec ./spec/app_spec.rb:6 # App with different args
rspec ./spec/app_spec.rb:11 # App with no args
/Users/kyanny/.rbenv/versions/2.0.0-p247/bin/ruby -S rspec ./spec/app_spec.rb failed

@@ -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.

@leshill
Copy link
Owner

leshill commented Nov 11, 2013

Hi @kyanny,

Looks good once the commit is cleaned up. Would you create a spec to verify that the messages are being generated correctly in spec/resque_spec/matchers_spec.rb?

@kyanny
Copy link
Author

kyanny commented Nov 11, 2013

Hi @leshill

Thank you for your review! I'm going to figure out how to write test against failure messages and do it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants