RSpec:“should == ..."之间的区别;和“应该 eql(...)"; [英] RSpec: difference between "should == ..." and "should eql(...)"

查看:29
本文介绍了RSpec:“should == ..."之间的区别;和“应该 eql(...)";的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 RSpec 中,使用 should == ...should eql(...) 有什么区别?我注意到 RSpec 文档总是使用 eql,但 == 输入更少且更易于阅读.我错过了什么?

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?

推荐答案

其实很简单:should ==== 消息发送给测试对象,should eql 向测试对象发送eql? 消息.换句话说:两个不同的测试发送两个完全不同的消息,它们调用两个完全不同的方法,从而做两个完全不同的事情.特别是,eql?== 更严格,但不如 equals? 严格.

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

这篇关于RSpec:“should == ..."之间的区别;和“应该 eql(...)";的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆