Rspec 2“应该接收”不使用 Mongoid::Document 类
当我尝试断言 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 的类。
谢谢!
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
end
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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
抱歉,我搞砸了,期望应该在获得
正确方法之前设定:
Sorry, i screwed up, the expectation was supposed to be set before the get
Correct way: