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

Jonathan Linowes jonathan at parkerhill.com
Mon Sep 8 22:56:03 EDT 2008


never mind, i misread your question, thought you were talking about a  
controller spec
rather than a story

stories are intended to exercise the full stack, so I actually log  
in, with a step like this:

   Given "I am logged in " do
     user = create_registered_user( :login => 'user', :password =>  
'secret')
     post_via_redirect "/sessions", :login => 'user', :password =>  
"secret",
     response.should be_success
     session[:user].should == user.id
   end



On Sep 8, 2008, at 10:47 PM, Jonathan Linowes wrote:

>
> On Sep 8, 2008, at 8:49 PM, 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
>
> If your controller has this
>
> 	:before_filter :login_required
>
> and say, login_required is defined in application.rb, then your  
> controller spec can stub it out
>
> 	controller.stub!(:login_required).and_return(true)
>
>



More information about the rspec-users mailing list