Ruby on rails 期望true响应true?
我将我的Ruby on rails 期望true响应true?,ruby-on-rails,ruby-on-rails-4,rspec,rspec-rails,rspec3,Ruby On Rails,Ruby On Rails 4,Rspec,Rspec Rails,Rspec3,我将我的rspec-rails升级到3.0.1,现在我在所有测试中都看到了这个错误 Failure/Error: Sidekiq::Status::complete?(json.jid).should be_true expected true to respond to `true?` 我找不到解决办法,也找不到我缺少的东西 从rspec 3.0开始,be_true被重命名为be_truthy,be_false被重命名为be_false 行为没有改变。所以 (nil).should b
rspec-rails
升级到3.0.1,现在我在所有测试中都看到了这个错误
Failure/Error: Sidekiq::Status::complete?(json.jid).should be_true
expected true to respond to `true?`
我找不到解决办法,也找不到我缺少的东西 从rspec 3.0开始,
be_true
被重命名为be_truthy
,be_false
被重命名为be_false
行为没有改变。所以
(nil).should be_falsey
(false).should be_falsey
会过去的,而且
(anything other than nil or false).should be_truthy
也将通过
从
将be_true和be_false重命名为be_true和be_false。(山姆·菲彭)
要避免重写大量现有规范,您可以将其添加到spec_helper(这会损害我的和谐感,但节省时间):
从技术上讲,此答案可能重复不正确。rspec 3.0
be__\truthy
与be-true
不同。如果您确实希望检查该值是否为true而不仅仅是truthy,那么应该使用expect(true).to be true
(注意be和true之间没有下划线)。参考号:@LarryKyrala。关于真实
与真实
不同,你是对的。但是我的回答和OP的问题是关于be_true
(注意下划线的存在)你是对的,先生!对不起,我没有看到3.0文档中提到的重命名。但是它是在。这个问题的直接答案可能会非常误导,并且应该像LarryKyrala提到的那样附上一个明确的注释。如果@Santhosh在他的回答中添加一条注释来解释这个微妙的陷阱,那也没什么坏处。这将帮助许多人避免一些严重的误解。很容易找到并替换这种东西。例如:git grep-l be_-true | xargs sed-i's/be_-true/be_-truthy/”
def true.true?
true
end
def true.false?
false
end
def false.true?
false
end
def false.false?
true
end