2011-03-31 54 views
2

試圖斷言,在一個Mongoid ::文檔類的方法是通過我的控制器代碼中調用時,我面臨着一些問題:Rspec的2「should_receive」不Mongoid :: Document類工作

require 'spec_helper' 

describe AController do 

    describe 'GET index' do 
    it 'returns the full list' do 
     get :index 
     Model.should_receive(:find).with(:all) 
     response.code.should eq ("200")  
    end 
    end 

end 

看看test.log我可以看到對數據庫執行的查詢。但是,測試失敗,rspec抱怨Model.find(:all)預期會發生一次,但收到0次。任何人都知道這裏發生了什麼?在我看來,Rspec無法存儲包含Mongoid :: Document的類。

謝謝!

回答

4

對不起,我搞砸了,期望本來之前獲得

正確的方式來進行設置:

Model.should_receive(:find).with(:all) 
    get :index  
    response.code.should eq ("200")