【发布时间】:2012-10-28 00:54:00
【问题描述】:
如何在 Rspec 中存根 set_headers 类方法?
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
【问题讨论】:
标签: ruby-on-rails rspec tdd