【发布时间】:2013-05-30 03:55:22
【问题描述】:
我正在尝试这样做user.abc_id.should == 0,但它错误地说
expected: 0
got: "0" (using ==) (RSpec::Expectations::ExpectationNotMetError)
【问题讨论】:
-
问题是字符串与数字。不幸的是,您为该问题提供了零上下文。
我正在尝试这样做user.abc_id.should == 0,但它错误地说
expected: 0
got: "0" (using ==) (RSpec::Expectations::ExpectationNotMetError)
【问题讨论】:
正如戴夫在评论中所说,问题是字符串与数字。如果你look at the rspec documentation你会看到
a == b # object equivalence - a and b have the same value with type conversions
string object 和 integer object不等效。
所以你可以试试类似的东西
a.eql?(b) # object equivalence - a and b have the same value
在你的情况下这可能有效
user.abc_id.should eql(0)
【讨论】: