开发者

Rspec 2 'should_receive' not working with Mongoid::Document class

I'm facing some problems when trying to assert that a method in a Mongoid::Document class is invoked by my controller code:

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
  e开发者_StackOverflownd

end

Looking at test.log i can see the the query being executed against the database. BUT, the test fails with rspec complaining that Model.find(:all) was expected once, but received 0 times. Anyone got an idea of what is happening here? It seems to me that Rspec is not being able to stub classes that include Mongoid::Document.

Thanks!


Sorry, i screwed up, the expectation was supposed to be set before the get

Correct way:

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜