モデル(RoR 3.0.x)には、多かれ少なかれ次のようなコードがあります。
class Message
after_create :notify
protected
def notify
if visible?
Notifier.message_from_portfolio( user, self ).deliver
else
Notifier.invisible_message_from_portfolio( user, self ).deliver
end
end
end
そして、私はそれをテストするために最新のrspecgemを使用しています。問題は、notifyメソッドをテストできないことです。直接テストすると、保護されているためテストできません。メッセージを作成して期待値を設定すると、rspecがnotifyメソッドを実行しているにもかかわらず機能しないようです。時間内に電話に出られません。
私のスペックは:
describe :notification do
it "should send the whole message by email when visible" do
u = Factory.create( :user, :account_type => 1 )
message = u.messages.build( :body => "Whatever", :author => "Nobody", :email => "test@example.com" )
Notifier.should_receive( :message_from_portfolio )
message.save
end
end
オブジェクトNotifierはmessage_from_portfolioを受信しません。私は何が間違っているのですか?提案?