Rspec 相等法 [英] Rspec equal method

查看:27
本文介绍了Rspec 相等法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

据我所知,equal方法检查对象是否相同.

From what I have understood, the equal method checks if the object is the same.

person = Person.create!(:name => "David")
Person.find_by_name("David").should equal(person)

这应该是真的.

但是这里不是有两个不同的对象吗?

But aren't there two different objects here?

两个对象怎么可能相同?我不明白.

How could two objects be the same? I don't understand that.

推荐答案

equal 检查引用是否相同.它对应于 Object#equal? 方法.您想使用 == 来比较这些对象.

equal checks if the reference is the same. It corresponds to the Object#equal? method. You want to use == to compare these objects.

这篇关于Rspec 相等法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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