Q:

RSpec Test Skip Filter

I'm using a gem that should only be run in production. 
skip_after_filter :kachow_auto_include unless Rails.env.production?

How can I test that this is skipped during test and development in RSpec.
Thanks

A:

Stub the method call on Rails.env, then call the action, e.g.:
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

