【问题标题】:rspec-rails: undefined method `true?' for true:TrueClass after updating to 3.0.0.beta2 versionrspec-rails:未定义的方法“真?” for true:TrueClass 更新到 3.0.0.beta2 版本后
【发布时间】:2014-03-10 14:33:26
【问题描述】:

将 rspec-rails 从版本 2.14.0 更新到 3.0.0.beta2 后,所有使用 be_true 或 be_false 的测试都会失败。

 Failure/Error: user.new_record?.should be_true
 NoMethodError:
   undefined method `true?' for true:TrueClass

有什么建议吗? Google 会返回任何关于此的内容!

【问题讨论】:

    标签: ruby-on-rails rspec rspec-rails


    【解决方案1】:

    从 3.0 版开始,RSpec 将 be_true 重命名为 be_truthy 并将 be_false 重命名为 be_falsey,如 https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers/be-matchers 中所述并在 https://github.com/rspec/rspec-expectations/issues/283 中进行了讨论。

    be_truebe_false 在 2.99 中被弃用并在 3.00 中被删除,因为它们只是分别与 truefalse 匹配,因此具有误导性。您收到的错误消息是因为缺少任何特定的 be_xxxx 方法定义,be_xxxx 将在实际中查找并调用 xxxx?

    请注意,如果您想匹配true,则可以使用be true(或be(true))。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-04-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-06-14
      • 1970-01-01
      相关资源
      最近更新 更多