0

我正在阅读 Hartl 的 RoR 教程,在 rspec 测试中有一个块可以检查密码是否匹配。在这个块是这一行:

     expect(@user.has_password?(@attr[:password])).to be_true

失败了。但我知道代码有效,因为如果我输入以下代码:

puts @user.has_password?(@attr[:password])

在块中它输出“真”。真正让我震惊的是我把这条线:

     expect(true).to be_true

代替上面的行......并且测试仍然失败。那是怎么回事?

4

1 回答 1

0

好像be_true改名为be_truthy. 尝试以下变体之一:

expect(true).to be true
expect(true).to be_truthy

第一个仅适用于true. 第二个用于任何不是false或的东西nil

于 2014-10-16T18:24:58.513 回答