In RSpec, what's the difference between using should == ...
and should eql(...)
? I noticed that the RSpec documentation always uses eql
, but ==
is less typing and easier to read. What am I missing?
views:
42answers:
3
A:
I believe == and eql are interchangeable, just user preference.
Matthew J Morrison
2010-07-19 21:27:35
+3
A:
They are usually equivalent, but not always:
1 == 1.0 # => true
1.eql? 1.0 # => false
Marc-André Lafortune
2010-07-19 21:41:53
touche... touche...
Matthew J Morrison
2010-07-19 22:35:05
+3
A:
It's rather simple, really: should ==
sends the ==
message to the test subject, should eql
sends the eql?
message to the test subject. In other words: the two different tests send two completely different messages which invoke two completely different methods and thus do two completely different things. In particular, eql?
is stricter than ==
but less strict than equals?
.
Jörg W Mittag
2010-07-20 07:31:32