ruby on rails - How to test via rspec that session variables updated in controller -


i trying write test using rspec tests if the session variable correctly changed:

this part of gamescontroller want test:

def change_player   if session[:player] == 0     session[:player] = 1   else     session[:player] = 0   end     end 

this game_spec.rb file:

require "spec_helper"  describe gamescontroller  describe "#change_player"    "should change player 1"      session[:player] = 0       :change_player       assigns(session[:player]).should == 1    end  end end 

this error message when run test:

failures:    1) gamescontroller#change_player should set player 0      failure/error: session[:player] = 0      nameerror:        undefined local variable or method `session' #<rspec::core::examplegroup::nested_1::nested_1:0x00000103b3b0d8>      # ./spec/features/game_spec.rb:6:in `block (3 levels) in <top (required)>'  finished in 0.01709 seconds 1 example, 1 failure  failed examples:  rspec ./spec/features/game_spec.rb:5 # gamescontroller#change_player should set player 0 

thanks

the problem rspec doesn't know controller test (is not in spec/controllers folder)

you need specify that

describe gamescontroller, :type => :controller     ... end 

Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

.htaccess - Matching full URL in RewriteCond -