将 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_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_true
和 be_false
在 2.99 中被弃用并在 3.00 中被删除,因为它们不只是匹配 true
和 false
,因此具有误导性。您收到的错误消息是因为缺少任何特定的 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/