[rspec-users] controller.session not same as session?

David Chelimsky dchelimsky at gmail.com
Wed Nov 8 04:55:43 EST 2006


> context "A user logging out" do
>    fixtures :users
>    controller_name :account
>
>    setup do
>      login_as :quentin
>      users(:quentin).remember_me
>      request.cookies["auth_token"] = cookie_for(:quentin)
>    end
>
>    def logout
>      get :logout
>    end
>
>    specify "should unset :user in session" do
>      logout
>      controller.session[:user].should_be_nil
>    end
>
>    specify "should unset :user in controller.session" do
>      logout
>      controller.session[:user].should_be_nil
>    end
> end
>
> The result:
>
> A user logging out
> - should unset :user in controller.session
> - should unset :user in session (FAILED - 1)
> - should be redirected
> - should delete remember_me token
>
> 1)
> Spec::Expectations::ExpectationNotMetError in 'A user logging out
> should unset :user in session'
> 1 should be nil
> ./spec/controllers/account_controller_spec.rb:149:in `should
> unset :user in session'
>
> Throwing a breakpoint in and examining the two reveals:
>
>  >> session
> => #<ActionController::TestSession:0x3a8e794 @attributes={:user=>1,
> "flash"=>{}}>
>  >> controller.session
> => #<ActionController::TestSession:0x3a797e0 @attributes=
> {:return_to=>nil, "flash"=>{:notice=>"You have been logged out."}}>
>  >>
>
> Am I doing something wrong?

The spec names say "session" and "controller.session", but both are
coded to go after "controller.session". Since each spec gets run in a
brand new instance of the context, it makes sense that these would be
two different objects. What doesn't make sense is that one passes and
one fails.

Would you kindly file a bug?

Thanks,
David

>
> Brandon


More information about the rspec-users mailing list