期望真实回应真实吗?

Lui*_* E. 46 rspec ruby-on-rails rspec-rails ruby-on-rails-4 rspec3

我将我升级rspec-rails到3.0.1,现在我在所有测试中都看到了这个错误

 Failure/Error: Sidekiq::Status::complete?(json.jid).should be_true
  expected true to respond to `true?`
Run Code Online (Sandbox Code Playgroud)

我找不到解决方案,也找不到我所缺少的.

San*_*osh 92

从RSpec的3.0,be_true重命名为be_truthybe_falsebe_falsey

行为没有改变.所以

(nil).should be_falsey
(false).should be_falsey
Run Code Online (Sandbox Code Playgroud)

将通过,和

(anything other than nil or false).should be_truthy
Run Code Online (Sandbox Code Playgroud)

也会通过

来自changelog 3.0.0.beta1/2013-11-07

将be_true和be_false重命名为be_truthy和be_falsey.(Sam Phippen)

  • 从技术上讲,这个答案是错误的 rspec 3.0`be_truthy`与`be true`不同.如果你真的想要检查值是否为真,而不仅仅是真实,那么你应该使用`expect(true).to true`(注意be和true之间缺少下划线).参考:https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers (36认同)