title: Rails Rspec - undefined method `session'
body: <p>Im testing my Session Controller but Im getting this error, the log in feature works, I tested it on the browser but Im new to testing on Rspec and can't get this to work</p>
  
  <pre><code> Failure/Error: expect(response.session[:user_id]).to eq(@user_attr.id)
   NoMethodError:
     undefined method `session' for #&lt;ActionController::TestResponse:0xd30df10&gt;
   # ./spec/controllers/sessions_controller_spec.rb:20:in `block (3 levels) in &lt;top (required)&gt;'
  </code></pre>
  
  <p>This is the code of my controller:</p>
  
  <pre><code>def new
      @user = User.new
  end
  
  def create
      @user = User.find_by(username: params[:user][:username])
      if @user &amp;&amp; @user.authenticate(params[:user][:password])
          session[:user_id] = @user.id
          redirect_to root_path
      else
          render :new
      end
  end
  </code></pre>
  
  <p>Rspec code:</p>
  
  <pre><code>require 'rails_helper'
  
  RSpec.describe SessionsController, type: :controller do
  describe "get Login page" do
      it "returns http status" do
          get :new
          expect(response).to have_http_status(:success)
      end
  end
  
  describe "session" do
      before(:each) do
          @user = FactoryGirl.create(:user)
          @user_attr = FactoryGirl.attributes_for(:user) 
      end
  
      it "gives session" do
          request.session[:user_id] = nil
          post :create, user: @user_attr
          expect(response.session[:user_id]).to eq(@user_attr.id)
      end
  end
  end
  </code></pre>