views:

47

answers:

2

In RSpec, if I have warnings on and have

x.should == 42
another_line_of_code

then I get a warning about

warning: useless use of == in void context

Is there anything I can do other than

  1. Turn warnings off
  2. Change it to bitbucket = (x.should == 42)
+1  A: 

It's a known issue (AFAIK without a good solution yet). There is an open ticket:

https://rspec.lighthouseapp.com/projects/5645/tickets/504-warning-free-rspec-a-solution-for-useless-use-of-in-a-void-context-warnings

A workaround using a check function is proposed there, though it's not very DRY.

tokland
+2  A: 

RSpec-2 has an eq(expected) matcher that works just like == without the warning:

actual.should eq(expected) 
David Chelimsky