我使用的gem应该只在生产环境中运行。
skip_after_filter :kachow_auto_include unless Rails.env.production?
如何在RSpec的测试和开发过程中测试这是跳过的?
谢谢
在Rails上存根方法调用。Env,然后调用动作,例如:
it "should run in production environment" do
Rails.env.stub(:production?) { true }
MyController.should_receive(:kachow_auto_include)
get :action_that_triggers_after_filter
end
it "should not run unless in production" do
Rails.env.stub(:production?) { false }
MyController.should_not_receive(:kachow_auto_include)
get :action_that_triggers_after_filter
end