title: How to test Devise Sessions Controller with RSpec
body: <p>I override SessionsController in my own controller and tried to test with RSpec. Fist, I setup devise with</p>
  
  <pre><code>@request.env["devise.mapping"] = Devise.mappings[:user]
  </code></pre>
  
  <p>my spec:</p>
  
  <pre><code>require 'rails_helper'
  </code></pre>
  
  <p>require 'authentication_helper'</p>
  
  <p>RSpec.describe Users::SessionsController, type: :controller do
    include AuthenticationHelper</p>
  
  <p>describe 'create new session' do</p>
  
  <pre><code>before(:each) do
    setup_auth
  end
  
  let(:user) {FactoryGirl.create(:user, username: 'john', email: 'john@gmail.com', password: 'pwd1234')}
  
  it 'should return 200 with valid username and password' do
    post :create, user: {login: 'john', password: 'pwd1234'}
  
    expect(response).to have_http_status 200
    expect(controller.current_user.id).to eq(user.id)
  end
  </code></pre>
  
  <p>end
  end</p>
  
  <p>my SessionsController just return http 401 or http 200.
  When I run my spec, I get this error:</p>
  
  <p>NoMethodError:
         undefined method <code>authenticate?' for nil:NilClass
       # /usr/local/bundle/gems/devise-3.5.6/app/controllers/devise_controller.rb:103:in</code>require_no_authentication'
       # ./spec/controllers/users/sessions_controller_spec.rb:16:in <code>block (3 levels) in &lt;top (required)&gt;'
       # ./spec/rails_helper.rb:45:in</code>block (3 levels) in '
       # /usr/local/bundle/gems/database_cleaner-1.6.0/lib/database_cleaner/generic/base.rb:16:in <code>cleaning'
       # /usr/local/bundle/gems/database_cleaner-1.6.0/lib/database_cleaner/base.rb:98:in</code>cleaning'
       # /usr/local/bundle/gems/database_cleaner-1.6.0/lib/database_cleaner/configuration.rb:86:in <code>block (2 levels) in cleaning'
       # /usr/local/bundle/gems/database_cleaner-1.6.0/lib/database_cleaner/configuration.rb:87:in</code>call'
       # /usr/local/bundle/gems/database_cleaner-1.6.0/lib/database_cleaner/configuration.rb:87:in <code>cleaning'
       # ./spec/rails_helper.rb:44:in</code>block (2 levels) in '</p>
  
  <p>What am I doing wrong?</p>