ruby-on-rails - rspec-rails:未定义方法 `true?' for true:TrueClass 更新到 3.0.0.beta2 版本后

标签 ruby-on-rails rspec rspec-rails

将 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 会返回有关此内容的任何信息!

最佳答案

从 3.0 版开始,RSpec 更名为 be_truebe_truthybe_falsebe_falseyhttps://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))。

关于ruby-on-rails - rspec-rails:未定义方法 `true?' for true:TrueClass 更新到 3.0.0.beta2 版本后,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22303068/

相关文章:

ruby-on-rails - 在单个应用程序上保护多个域

ruby-on-rails - Rspec 和 Rspec-Rails Gem 之间有什么区别?

ruby-on-rails - Rspec stub 操作变量

ruby-on-rails - 从 View 设置标题状态

javascript - 如何在 Ruby on Rails 中设置 'bootstrap tour'

ruby-on-rails - 格式化 JSON API 的 Active Record 时间戳

RSpec + capybara : How do I test a Bootstrap progress bar

ruby-on-rails - 有没有办法在请求规范中模拟 Pundit 政策授权?

ruby - 使用 RSpec 上传图像在 Controller 上有意外的类

ruby-on-rails - ActiveRecord::QueryMethod 'includes' 忽略了我的选择方法。我该如何处理?