title: Stub current_user when testing devise views
body: <p>I am testesting my custom devise views with capybara and i need a logged in user in order to tests some views, for example:</p>
  
  <pre><code>feature 'user/edit' do
    describe "the edit profile process", :type =&gt; :feature do
      include Devise::TestHelpers
  
      let!(:user){ FactoryGirl.build(:user)
  
      def sign_in(user)
        if user.nil?
          request.env['warden'].stub(:authenticate!).
            and_throw(:warden, {:scope =&gt; :user})
            controller.stub :current_user =&gt; nil
        else
          request.env['warden'].stub :authenticate! =&gt; user
           controller.stub :current_user =&gt; user
        end
      end
  
      it "update " do
        sign_in(user)
        visit '/users/edit'
        within("#edit_user") do  
           #=&gt; something
        end
        click_on 'Update'
        page.should have_content("something")
      end
    end
  end
  </code></pre>
  
  <p>But i got this error</p>
  
  <pre><code>Failure/Error: request.env['warden'].stub :authenticate! =&gt; user
  
  NoMethodError: undefined method `env' for nil:NilClass
  </code></pre>