rspec2 - Rspec request specs and session values -


i writing request specs (rspec 2.13.1) , directly access session hash. think syntax possible in controller specs not sure if can can done in request specs.

describe 'api'   let(:user) { factorygirl.create(:user) }   session[:auth_token]=user.auth_token 

i following error:

 failure/error: session[:auth_token]=user.auth_token                              │lock (2 levels) in top_level'                                                           nomethoderror:                                                                   │/users/jt/.rvm/gems/ruby-1.9.3-p392/gems/rake-10.0.4/lib/rake/application.rb:101:in `e    undefined method `session' nil:nilclass                                    │ach'                                                                                    # ./spec/requests/api_spec.rb:7:in `block (2 levels) in <top (required)>'   

i have seen following question access session hash in request spec not sure if accurate.

thx in advance

there several small mistakes

  1. you should describe api_controller
  2. variable assignments requests should within before(:each) block.
  3. you lacking it block
  4. when file not placed within spec/controllers, need specify, controller test :type => :controller

here example of that:

require 'spec_helper'  describe apicontroller, :type => :controller   let(:user) { factorygirl.create(:user) }    before :each     session[:auth_token]=user.auth_token   end    'should something'     :index     response.status.should_not eq 401   end end 

Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -