2012-07-03 5 views
0

내 레일 애플리케이션의 사용자 로그인에 대한 통합 테스트에 문제가 있습니다. 내가 RSpec에와 카피 바라를 사용하여뿐만 아니라, 사용자 인증 여기rspec/devise로 로그인 통합 테스트

를 위해 고안하고있어

내 코드입니다 :

요청/authentications_spec.rb

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 

공장/user_factory.rb

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 

_login_form.html.erb, 이 fo rm은 응용 프로그램 레이아웃 머리글에 렌더링됩니다.

if user_signed_in? 
    render 'devise/menu/logout_button' 
else 
    render 'devise/menu/login_form' 
end 

시험은 나에게주고있다

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 <top (required)>' 

Finished in 0.71406 seconds 
8 examples, 2 failures, 2 pending 

내 테스트를 통과하지 왜 내가하지 않습니다 : 레이아웃에서

<%= form_for(resource, as: resource_name, url: session_path(resource_name), html: { id: 'login-mini-form' }) do |f| %> 
    <%= f.email_field :email,  placeholder: 'Your email' %> 
    <%= f.password_field :password, placeholder: '******' %> 
    <%= f.submit "Log in", id: 'login-button' %> 

    <%- if devise_mapping.rememberable? -%> 
    <%= f.check_box :remember_me %> <%= f.label :remember_me %> 
    <%- end -%> 

<% end %> 

나는 그런 일이있다. 어떤 아이디어?

고맙습니다.

편집 : 테스트를 반환 expect { click_button register_button }.to change(User, :count).by 1 : 나는 함께 등록을 테스트 같은 동작을 얻을 당신은 당신의 기대의 제목을 제공하지 않았다

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 
+0

전체 RSpec 출력을 제공해 주시겠습니까? – tsm

+0

개업식을 편집했습니다 :) –

+0

로깅을 확인할 수 있습니까? 명백한 오류가 있는지'log/test.log'를 확인하십시오. – nathanvda

답변

1

그래서, 난 작동하지 않는 것을 발견 :의 인수로 기호를 고려하지 않습니다 카피 바라의 FILL_IN 방법을 보인다

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 
end 

:

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 

올바른 코드는 사실이다 ids하지만 문자열 만. 어리석은 나를.

0

, 그래서 RSpec에이 결과를 사용하는 것 같습니다 마지막 표현. 마지막 표현은 click_button이며 아무 것도 반환하지 않습니다. should에 전화 할 수 없습니다.

이 문제를 해결하려면 페이지에 링크를 지정해야합니다. 나는 Capybara와 Selenium-Webdriver를 사용하므로 나를 위해 page.should have_link...처럼 보일 것입니다. RSpec-fu는 page도 사용해야하는지 알 수 없거나 response, session 등으로 대체해야합니다.

+0

아니요. @paperwork이 'subject'를 선언 했으므로 rspec이이를 사용합니다. – nathanvda