title: Login integration test with rspec/devise
body: <p>I'm having troubles making an integration test, for the user login in my rails application, pass.</p>
  
  <p>I'm using Rspec and capybara, as well as devise for user authentication</p>
  
  <p>Here is my code :</p>
  
  <p>requests/authentications_spec.rb</p>
  
  <pre><code>describe 'log in' do
    before { visit root_path }
    subject { page }
  
    describe 'should be able to log in' do
      before do
        user = FactoryGirl.create(:user)
        fill_in :user_email, with: user.email
        fill_in :user_password, with: user.password
        click_on 'Log in'
      end
      it { should have_link 'Log out' }
    end
  end
  </code></pre>
  
  <p>factories/user_factory.rb</p>
  
  <pre><code>FactoryGirl.define do
    factory :user do
      sequence( :first_name )  { |n| "FirstName#{n}" }
      sequence( :last_name )  { |n| "LastName#{n}" }
      sequence( :email ) { |n| "foo#{n}@example.com" }
      password              'foobar'
      password_confirmation 'foobar'
      created_at            Time.now
      updated_at            Time.now
    end
  end
  </code></pre>
  
  <p>_login_form.html.erb,
  This form is rendered in the application layout header.</p>
  
  <pre><code>&lt;%= form_for(resource, as: resource_name, url: session_path(resource_name), html: { id: 'login-mini-form' }) do |f| %&gt;
    &lt;%= f.email_field :email,       placeholder: 'Your email' %&gt;
    &lt;%= f.password_field :password, placeholder: '******' %&gt;
    &lt;%= f.submit "Log in", id: 'login-button' %&gt;
  
    &lt;%- if devise_mapping.rememberable? -%&gt;
      &lt;%= f.check_box :remember_me %&gt; &lt;%= f.label :remember_me %&gt;
    &lt;%- end -%&gt;
  
  &lt;% end %&gt;
  </code></pre>
  
  <p>In the layout I have something like that : </p>
  
  <pre><code>if user_signed_in?
    render 'devise/menu/logout_button'
  else
    render 'devise/menu/login_form'
  end
  </code></pre>
  
  <p>The test is giving me </p>
  
  <pre><code>1) User should be able to log in with valid credentials 
       Failure/Error: it { should have_link 'Log out' }
         expected link "Log out" to return something
       # ./spec/requests/authentications_spec.rb:117:in `block (6 levels) in &lt;top (required)&gt;'
  
  Finished in 0.71406 seconds
  8 examples, 2 failures, 2 pending
  </code></pre>
  
  <p>I don't get why my test is not passing. Any ideas ?</p>
  
  <p>Thanks a lot !</p>
  
  <p>Edit : I get the same behavior testing the registration with : <code>expect { click_button register_button }.to change(User, :count).by 1</code>, the test returns : </p>
  
  <pre><code>Failure/Error: expect { click_button register_button }.to change(User, :count).by 1
         count should have been changed by 1, but was changed by 0
  </code></pre>