title: Accessing session from a helper spec in rspec
body: <p>I have a method in my ApplicationHelper that checks to see if there are any items in my basket</p>
  
  <pre><code>module ApplicationHelper
    def has_basket_items?
      basket = Basket.find(session[:basket_id])
      basket ? !basket.basket_items.empty? : false
    end
  end
  </code></pre>
  
  <p>Here is my helper spec that I have to test this:</p>
  
  <pre><code>require 'spec_helper'
  
  describe ApplicationHelper do
    describe 'has_basket_items?' do
      describe 'with no basket' do
  
        it "should return false" do
          helper.has_basket_items?.should be_false
        end
  
      end
    end
  end
  </code></pre>
  
  <p>however when I run the test i get </p>
  
  <pre><code>SystemStackError: stack level too deep
  /home/user/.rvm/gems/ruby-1.9.3-p194/gems/actionpack-3.2.8/lib/action_dispatch/testing/test_process.rb:13:
  </code></pre>
  
  <p>From debugging this i see that <em>session</em> is being accessed in ActionDispatch::TestProcess from @request.session, and @request is nil. When i access the session from my request specs @request is an instance of ActionController::TestRequest.</p>
  
  <p>My question is can I access the session object from a helper spec? If I can, how? And if I cant what is the best practice to test this method?</p>
  
  <p><em><strong></em>****</strong><em>UPDATE</em><strong><em>*</em>***</strong></p>
  
  <p>This was down to having <code>include ActionDispatch::TestProcess</code> in my factories. Removing this include sorts the problem.</p>