[rspec-users] help on skipping a before_filter for a story

Matt Wynne matt at mattwynne.net
Wed Sep 17 15:32:03 EDT 2008

We just write a step that says 'Given I am logged in' which actually  
walks through the login process on the screens (fills_in :username etc).

However you could have another step like 'Given authenication is  
disabled on the site' which does something dirty to your  
ApplicationController using mocks to replace the function you're  
calling from the before filter with a mocked response.

Something like


I don't think is is recommended though as these are meant to be full- 
stack integration tests - using mocking is a bad habit to get into.

On 9 Sep 2008, at 01:33, Eric Harris-Braun wrote:

> Hi folks,
> I'm hoping for a bit of help on best-practices for skipping a
> before_filter when running a particular step.  Specifically the
> authentication filter.  What happens is that the post (see code below)
> returns a redirect response to the login page triggered by the of my
> authentication filter, rather than the contents of what I'd like to be
> testing.
> How do people handle temporarily turning of this kind of thing that's
> not relevant to the test?  Temporarily I've just put an unless  
> == 'test' after it, but obviouly that won't work for the specs that
> actually test that before filter!
> Thanks for any help!
> -Eric
>   Given "$field in new entry is $field_value" do |field,field_value|
>     @params ||= {}
>     @params[field.intern] = field_value
>   end
>   When "submitting the new entry" do
>     post "/entry", :record => @params
>   end
>   Then "should include confirmation: $message" do |message|
>     response.should have_text(/#{message}/)
>   end
> -- 
> He who is content with his lot probably has a lot.
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users


In case you wondered: The opinions expressed in this email are my own  
and do not necessarily reflect the views of any former, current or  
future employers of mine.

More information about the rspec-users mailing list