【发布时间】:2013-08-05 16:36:57
【问题描述】:
即使在阅读了几十个线程和博客文章之后,我仍然无法存根控制器方法,所以这是我的情况:
我的控制器: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]
Rails 3.2.13
有什么帮助吗?
顺便说一句,我发现当我在it 'should load' 块中使用binding.pry 检查controller.object_id 时,我得到一个不同 object_id,而不是在my_private_method 中检查self.object_id。
【问题讨论】:
标签: ruby-on-rails rspec stub