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

Ben Mabey ben at benmabey.com
Mon Sep 8 21:23:11 EDT 2008

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 RAILS_ENV
> == '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

Hi Eric,
The point of stories is to have them act as integration tests going
through the entire stack just like a typical user would.  So, you should
really be logging in to your app before you start submitting forms. So
doing something like:

 When "submitting the new entry" do
    User.create!(:login => 'james', :password => 'password')
    post "/sessions", :login => 'james', :passsword => 'password'
    post "/entry", :record => @params


I typically extract this out into a helper called 'login' where I can
simply pass a user object.

BTW, have you checked out webrat yet?  It makes submitting forms very easy.


More information about the rspec-users mailing list