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
- you should describe api_controller
- variable assignments requests should within before(:each) block.
- you lacking
it
block - 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
Post a Comment