[rspec-users] should !=
dchelimsky at gmail.com
Thu Oct 9 20:07:53 EDT 2008
On Thu, Oct 9, 2008 at 6:47 PM, Mark Wilden <mark at mwilden.com> wrote:
> I expected 'should !=' to act the same as 'should_not =='. That turned out
> to be incorrect (by design?):
We'd love to do that, but Ruby doesn't provide us the tools we need.
As far as we know, the only way to do that would be to do string evals
on the files instead of using actual code.
=> ["==", "===", "=~", "taguri="]
Note the absence of "!=".
Try this in irb:
SyntaxError: compile error
(irb):2: syntax error, unexpected tNEQ
Essentially, ruby interprets this:
5.should == 5
but it interprets this:
5.should != 4
And since 5 has no way of knowing that it's part of a negated
expression, there's no way for rspec (that I know of) to handle this
as you would expect.
Sorry - we all wish it could be so. I imagine the rubinius extended
version will support it though ;)
> require 'spec'
> require 'spec/rails'
> describe "using 'should !='" do
> it "seems to treat != as the same as ==" do
> 1.should != 1 # passes
> 1.should != 2 # fails
> rspec-users mailing list
> rspec-users at rubyforge.org
More information about the rspec-users