set_headers
以下のRspecでクラスメソッドをスタブするにはどうすればよいですか?
application_controller.rb
class ApplicationController < ActionController::Base
def self.set_headers(name)
after_filter do
object = instance_variable_get("@#{name}")
headers['fancy'] = object.fancy_header
end
end
end
regular_controller.rb
class RegularController < ApplicationController
set_headers :regular
def index
# do regular stuff
end
end
以下を試しましたが、動作しません。
regular_controller_spec.rb
describe RegularController do
before(:each) do
ApplicationController.any_instance.stub(:set_headers).and_return({this: 'params'})
end
end