开发者

RSpec: difference between "should == ..." and "should eql(...)"

开发者 https://www.devze.com 2023-01-08 12:10 出处:网络
In RSpe开发者_开发问答c, 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

In RSpe开发者_开发问答c, 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?


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?.


They are usually equivalent, but not always:

1 ==   1.0 # => true
1.eql? 1.0 # => false
0

精彩评论

暂无评论...
验证码 换一张
取 消