[rspec-devel] actual.should != not_expected
dchelimsky at gmail.com
Tue Oct 17 05:54:36 EDT 2006
In dealing with the changes to should in the
should_be_working_like_ruby branch, I am reminded that while we got
the following to work ...
actual.should_be < value
actual.should_be <= value
actual.should == value
actual.should =~ value
actual.should_be >= value
actual.should_be > value
... we were not able to get this to work:
actual.should != value
Here's what the test looked like:
context "should[_be] <arbitrary operator>:" do
specify "should pass when != operator returns true" do
(2+2).should != 3
and the result.
$ bin/spec spec/spec/expectations/helper/ \
-s "should pass when != operator returns true"
Spec::Expectations::ExpectationNotMetError in 'should[_be] <arbitrary
operator>: should pass when != operator returns true'
4 should == 3
`should pass when != operator returns true'
Finished in 0.000647 seconds
1 specification, 1 failure
NOTE that the error reads "4 should == 3". It looks as though ruby is
actually delivering the == operator instead of !=. Now if you do this:
=> ["<", "<=", "<=>", "==", "===", "=~", ">", ">=",...]
... you'll note that != is not an actual operator. So I'm not
convinced that we can get this to work without a big change to rspec's
So the challenge is on. If any one is interested in making this work,
please check out the should_be_working_like_ruby branch or the trunk,
give it a shot, and submit a patch (with specs!) if you succeed. If
you do submit a patch, please make sure that the spec above and all
other specs are passing.
Also - I view this as a bell (or whistle, if you prefer). Specifying
something as vague as != seems almost useless to me to begin with, but
if you really do need to specify inequality you'll be ableto do it
with should_not_eql or should_not_equal. That said, we will reserve
the right to not incorporate a working solution if we feel that it is
not cleanly aligned with the rest of RSpec's internals, or makes us
all go "wow, that's cool, but what a hack!". So please do not submit
anything unless the sheer satisfaction of having gotten it to work
will be enough for you to feel that the effort was worthwhile.
More information about the rspec-devel