How do I execute rspec with valid_session using Facebooker2 in rails 3?

I am new to Rails. I am developing my application with RSpec. I just completed a tutorial for Facebooker2 and added before_filter for authentication.

 #app/controller/application_controller.rb before_filter :ensure_authenticated 

However, my specifications, such as the ones below, failed because there is no valid session that is clear.

 #spec/controllers/answers_controller_spec.rb describe "GET index" do it "assigns all answers as @answers" do get :index, {}, valid_session assigns(:answers).should include(answers(:reading)) end end 

But I cannot find a way to fake a valid session for rspec for use in the following function.

 #spec/controllers/answers_controller_spec.rb def valid_session {} end 

Is there any way? If not, what is the rails way of doing things for such a case?

+4
source share
1 answer

If you are not interested in authentication and just want to simulate a valid session, you can turn off the filter:

 controller.stub(:ensure_authenticated).and_return(true) 

EDIT: you might need ApplicationController.stub (...)

0
source

All Articles