[rspec-users] How to stub ApplicationController method in request spec

Justin Ko jko170 at gmail.com
Sun Sep 25 03:02:01 EDT 2011


On Sep 16, 2011, at 12:33 PM, mattf wrote:

> 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!!!
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users

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.


More information about the rspec-users mailing list