即使在阅读了几十个线程和博客文章之后,我仍然无法存根控制器方法,所以这是我的情况:
我的控制器:app/controllers/my_controller.rb
class MyController < ApplicationController
before_filter :my_private_method, only:[:new]
# ...
private
# This should be stubbed and not fire
def my_private_method
binding.pry
redirect_to '/failure.html'
end
end
我的规格:spec/controllers/my_spec.rb
describe MyController do
before :each do
controller.stub!(:my_private_method).and_return(true)
end
it 'should load' do
binding.pry
visit new_my_path
response.status.should == 200
end
end
我的系统:
ruby 1.9.3p448(2013-06-27 修订版 41675)[x86_64-linux]
导轨 3.2.13
有什么帮助吗?
顺便说一句,我发现当我binding.pry
用来签controller.object_id
入我的it 'should load'
块时,我得到的object_id 与我签入时不同。self.object_id
my_private_method