0
我不明白爲什麼驗證?對於沒有摘要的用戶來說不是錯誤的。 當我運行MODELTEST下面我得到以下錯誤:未定義的方法/變量錯誤,找不到原因
ERROR["test_authenticated?_should_return_false_for_a_stakeholder_with_nil_digest", StakeholderTest, 0.906488841]
test_authenticated?_should_return_false_for_a_stakeholder_with_nil_digest#StakeholderTest (0.91s)
NoMethodError: NoMethodError: undefined method `authenticated?' for nil:NilClass
test/models/stakeholder_test.rb:126:in `block in <class:StakeholderTest>'
test/models/stakeholder_test.rb:126:in `block in <class:StakeholderTest>'
這是相應的測試(線126指assert_not線):
test "authenticated? should return false for a stakeholder with nil digest" do
assert_not @stakeholder.authenticated?('')
end
這是經認證的?方法:
def authenticated?(remember_token)
return false if remember_digest.nil?
BCrypt::Password.new(remember_digest).is_password?(remember_token)
end
方法以及檢驗從哈特爾的教程已經從字面上通過(僅替換爲利益相關者的用戶),所以我不明白我可能做錯了。