私はレールに比較的慣れていないため、この rspec テストが失敗する理由がわかりません。
モデルクラス
class Invitation < ActiveRecord::Base
belongs_to :sender, :class_name => "User"
before_create :generate_token
private
def generate_token
self.token = Digest::SHA1.hexdigest([Time.now, rand].join)
end
end
テスト
it "should create a hash for the token" do
invitation = Invitation.new
Digest::SHA1.stub(:hexdigest).and_return("some random hash")
invitation.token.should == "some random hash"
end
エラー:
Failure/Error: invitation.token.should == "some random hash"
expected: "some random hash"
got: nil (using ==)
招待モデルには token:string 属性があります。何か案は?ありがとう!