【问题标题】:How to compare zero using cucumber?如何使用黄瓜比较零?
【发布时间】:2013-05-30 03:55:22
【问题描述】:

我正在尝试这样做user.abc_id.should == 0,但它错误地说

expected: 0
 got: "0" (using ==) (RSpec::Expectations::ExpectationNotMetError)

【问题讨论】:

  • 问题是字符串与数字。不幸的是,您为该问题提供了零上下文。

标签: ruby-on-rails cucumber


【解决方案1】:

正如戴夫在评论中所说,问题是字符串与数字。如果你look at the rspec documentation你会看到

 a == b # object equivalence - a and b have the same value with type conversions

string objectinteger object不等效

所以你可以试试类似的东西

a.eql?(b) # object equivalence - a and b have the same value

在你的情况下这可能有效

user.abc_id.should eql(0)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-04-17
    • 1970-01-01
    • 2013-05-23
    • 1970-01-01
    相关资源
    最近更新 更多