1
我试图做到这一点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)
的问题是串VS号。不幸的是,你为这个问题提供了零环境。 –