嘿大家我想讓Rspec測試一個動作是否調用了我從ActiveMailer繼承但是一直沒有運氣的模型中的特定方法。所以作爲一個快速樣機我有以下情況。型號UserNotifier:RSpec測試調用到ActiveMailer模型
class UserNotifier < ActionMailer::Base
def foobaz
end
end
控制器密碼控制器:
class PasswordsController < ApplicationController
def foobar
UserNotifier.foobaz
end
而且規格:
describe "GET 'foobar'" do
it "should call the UserNotifier foobaz method" do
UserNotifier.should_receive(:foobaz)
get :foobar
end
end
,但我總是與這個失敗而告終:
1) PasswordsController GET 'foobar' should call the UserNotifier foobaz method
Failure/Error: UserNotifier.should_receive(:foobaz)
(<UserNotifier (class)>).foobaz(any args)
expected: 1 time
received: 0 times
能
人啓發我爲什麼RSpec不註冊UserNotifier.foobaz方法被調用?
我重複了這一點,並通過示例。也許你應該在發現問題的地方發佈原始代碼。 – zetetic 2011-02-24 00:12:54
這是原始代碼 - 我沒有改變一件事,也無法通過。 – 2011-02-24 02:24:32
我認爲它沒有進入'PasswordsController',因爲你在那裏或在它的一個超級控制器中進行了某種登錄檢查。 – 2011-02-24 04:39:30