Set a session var in Rspec Request spec : <p>I am trying to set a session variable in a request spec.</p>

<p>I have tried the following things to do this:</p>

<pre><code>RSpec.describe 'Application Controller' do
  context 'updating an application' do
    before :each do
      @app = create(:application, step: 'investigation')
    end

    it 'should update app status' do
      Status.create(app_id: @app.id, name: Status.names[:start])
      request.session[:app_id] = @app.id
      patch "/applications/start",
            params: s_params
      expect(response).to redirect_to(offers_path)
    end
  end
end
</code></pre>

<p>I have tried substituting <code>request</code> with <code>@request</code> both result in the same output.</p>

<pre><code>NoMethodError:
  undefined method `session' for nil:NilClass
</code></pre>

<p>then I have tried just setting as:</p>

<pre><code>session[:app_id] = @app.id
</code></pre>

<p>which will yield:</p>

<pre><code>NoMethodError:
  undefined method `session' for nil:NilClass
</code></pre>

<p>and also setting it like this:</p>

<pre><code>patch "/applications/start",
      params: s_params,
      session: {"app_id" =&gt; @app.id}
</code></pre>

<p>which will yield:</p>

<pre><code> ArgumentError:
   unknown keyword: session
</code></pre>

<p>My versions:</p>

<pre><code>╰&gt;&gt;&gt; ruby -v
ruby 2.4.5p335 (2018-10-18 revision 65137) [x86_64-darwin18]

╰&gt;&gt;&gt; rails -v
Rails 5.2.1

╰&gt;&gt;&gt; rspec -v
RSpec 3.8
  - rspec-core 3.8.0
  - rspec-expectations 3.8.1
  - rspec-mocks 3.8.0
  - rspec-rails 3.8.0
  - rspec-support 3.8.0
</code></pre>

<p>Looking at the <a href="https://relishapp.com/rspec/rspec-rails/v/3-8/docs/request-specs/request-spec" rel="noreferrer">documentation</a> it suggests we could leverage the sessions but does not give a clear example of how we would do this. </p>
