title: Rspec/ Capybara simulate session (stub or mock?)
body: <p>I'm trying to <code>visit '/requests/new</code>. Now in the controller code, I've written it so that if a session doesn't exist, the user is redirected back to the home page. like so:</p>
  
  <pre><code>def new
  @pagetitle = "What would you like to borrow?"
  
  if session[:signup_email].nil?
    flash[:danger] = "Please enter your email to get started"
    redirect_to root_path
  else
    @signup_parent = Signup.find_by_email(session[:signup_email].downcase)
    if @signup_parent.tos != true || @signup_parent.streetone.blank? || @signup_parent.streettwo.blank? || @signup_parent.zipcode.blank?
      flash[:danger] = "Almost there! We just need a little more info"
      redirect_to edit_signup_path
    else
      @requestrecord = @signup_parent.requests.build 
    end
  end
  </code></pre>
  
  <p>end</p>
  
  <p>But the problem is that now in testing, I can't simulate a session. I tried to write:</p>
  
  <pre><code>    before do
          session[:signup_email] = Signup.find_by_id(@signup_ana.id)
          visit '/requests/new'
          save_and_open_page
          fill_in '#borrow__1', :with =&gt; 1
          click_button
      end
  </code></pre>
  
  <p>But that threw an error: <code>undefined local variable or method</code>session' for #`</p>
  
  <p>Yet if I don't try to simulate it, the <code>save_and_open_page</code> shows me that I just get re-routed back to home. How should I do this? Is there a way to stub/ mock this out??</p>