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

aslak hellesoy aslak.hellesoy at gmail.com
Wed Sep 17 15:58:10 EDT 2008


On Tue, Sep 9, 2008 at 2:33 AM, Eric Harris-Braun <eric at harris-braun.com> wrote:
> Hi folks,
>
> I'm hoping for a bit of help on best-practices for skipping a

There are no practices for this (or anything else) that are better
than any other practice.

> 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.
>

My general advice is to not futz around with your application's
behaviour when you're running stories (or cucumber features).
Why? Because stories/features are intended to be end-to-end tests of
the unaltered app. This was recently discussed in a thread about
mocking/stubbing from steps.

If the application wants you to log in, then log in from one of your steps.

If for whatever reason this is impractical I would recommend doing
something like:

unless ENV['SKIP_LOGIN_IN_STORIES']

-and set that env var from one of the ruby files that get loaded
before your story/feature runs.
(but I would consider this a test smell)

Cheers,
Aslak

> 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
>
> --
> 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
>


More information about the rspec-users mailing list