Forum: RSpec How to stub ApplicationController method in request spec

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
mattf (Guest)
on 2011-09-25 08:50
(Received via mailing list)
Hey there,

I am needing to stub a 'current_user' method in an Rspec/capybara
request spec. The method is defined in ApplicationController and is
using helper_method. The method should simply return a user id.

Alternatively, I could fix my problem by setting 'session[:user_id]'
in the spec (which is what 'current_user' returns)... but that doesn't
seem to work either.

Are either of these possible? Thanks!!!
Justin Ko (Guest)
on 2011-09-25 09:16
(Received via mailing list)
On Sep 16, 2011, at 12:33 PM, mattf wrote:

> Are either of these possible? Thanks!!!
> _______________________________________________
> rspec-users mailing list

Capybara was designed to force the dev to build true request specs.
Meaning, you cannot tamper with cookies, request headers, etc. directly.
You have to go through the app - clicking links, visiting paths, etc.

So, you're going to have to go to the authentication page and login
before hitting the pages you actually want to test.
This topic is locked and can not be replied to.