[rspec-users] Testing a before_filter with a Rails.env condition
Shane Mingins
elc at mingins.com
Mon Aug 29 19:09:39 EDT 2011
Hi
We have the occasional ApplicationController before_filter that is
conditioned by the Rails.env and we like the following style:
before_filter :check_for_something if Rails.env == 'production'
And wish to spec this in an ApplicationController spec using an anonymous
controller (e.g.
http://relishapp.com/rspec/rspec-rails/docs/controller-specs/anonymous-controller
)
*Q. Just wondering how we can Rails.stub(:env).and_return('production') to
trigger the before_filter?*
As it stands we have moved the conditional down into the method and stub in
the before(:each)
e.g.
before_filter :check_for_something
def check_for_something
if Rails.env == 'production'
...
end
end
before(:each) do
Rails.stub(:env).and_return('production')
end
Cheers
Shane
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20110830/5abea807/attachment.html>
More information about the rspec-users
mailing list