我有以下rspec代码:
require 'spec_helper'
require 'mocha'
require 'rr'
describe ProjectsController, "creating a new project" do
integrate_views
it "should redirect to project with a notice on successful save" do
Project.any_instance.stubs(:valid?).returns(true)
#mock.instance_of(Project).valid? {true}
Project.any_instance.stubs(:create_default_packets)
#mock.instance_of(Project).create_default_packets
post 'create'
assigns[:project].should_not be_new_record
end
end
它成功传递(RR语法已注释掉),但当我切换到RR语法时,它失败了:
'ProjectsController创建一个新项目应该重定向到项目,并通知成功保存'FAILED预期new_record?返回false,得到了真实
RR会失败的两者之间有什么区别?
答案 0 :(得分:0)
看来不同的是你不能用rr调用instance_of两次。请参阅以下git问题:http://github.com/btakita/rr/issues#issue/17