title: How to test via rspec that session variables updated in controller
body: <p>I am trying to write a test using rspec that tests if the the session variable was correctly changed:</p>
  
  <p>This is the part of the GamesController I want to test:</p>
  
  <pre><code>def change_player
    if session[:player] == 0
      session[:player] = 1
    else
      session[:player] = 0
    end    
  end
  </code></pre>
  
  <p>This is my game_spec.rb file:</p>
  
  <pre><code>require "spec_helper"
  
  describe GamesController do
   describe "#change_player" do
     it "should change player to 1" do
       session[:player] = 0
  
       get :change_player
  
       assigns(session[:player]).should == 1
     end
   end
  end
  </code></pre>
  
  <p>This is the error message I get when I run the test:</p>
  
  <pre><code>Failures:
  
    1) GamesController#change_player should set player to 0
       Failure/Error: session[:player] = 0
       NameError:
         undefined local variable or method `session' for #&lt;RSpec::Core::ExampleGroup::Nested_1::Nested_1:0x00000103b3b0d8&gt;
       # ./spec/features/game_spec.rb:6:in `block (3 levels) in &lt;top (required)&gt;'
  
  Finished in 0.01709 seconds
  1 example, 1 failure
  
  Failed examples:
  
  rspec ./spec/features/game_spec.rb:5 # GamesController#change_player should set player to 0
  </code></pre>
  
  <p>Thanks</p>