resque_spec icon indicating copy to clipboard operation
resque_spec copied to clipboard

Show failure message with actual arguments

Open kyanny opened this issue 12 years ago • 2 comments

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

kyanny avatar Nov 11 '13 04:11 kyanny

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?

leshill avatar Nov 11 '13 04:11 leshill

Hi @leshill

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

kyanny avatar Nov 11 '13 05:11 kyanny