2017-04-02 2 views
0

내 생각한 사용자는 :confirmable이며 가입 한 후 사용자가 devise 로그인 페이지로 리디렉션되는지 테스트하고 싶습니다. 수동으로 테스트 할 때 작동하지만 rspec/capybara 기능 사양에서는 실패합니다. 리디렉션을 설정하려면 these 안내를 따르고 있습니다.확인할 수있는 리디렉션 after_inactive_sign_up_path_for 확인 가능한 리디렉션

# registrations_controller.rb 
class RegistrationsController < Devise::RegistrationsController 
    protected 

    def after_inactive_sign_up_path_for(_resource) 
     new_user_session_path # redirect to login 
    end 
end 



# registration_spec.rb 
RSpec.describe 'registration process', type: feature do 
    it 'works' do 
     visit new_user_registration_path 
     fill_in 'Username', with: 'user123' 
     fill_in 'Email', with: '[email protected]' 
     fill_in 'Password', with: 'password123' 
     fill_in 'Password confirmation', with: 'password123' 
     click_on 'Sign up' 
     expect(User.find_by(username: 'user123')).not_to be_nil # sanity check 
     expect(page).to have_current_path(new_user_session_path) # failure here 
    end 
end 

않으면 반환 page 것 같다

Failure/Error: expect(page).to have_current_path(new_user_session_path) 
     expected "/users" to equal "https://stackoverflow.com/users/sign_in" 
    # ./spec/features/registration_spec.rb:19:in `block (2 levels) in <top (required)>' 

는 포스트 경로에 갇혀있다, 또는 잘못 /users로 리디렉션되고있다? 나는 사용자가 존재한다는 나의 온 전성 체크 때문에 폼이 입력을 받아들이는 것을 안다.

답변

0

기존 사용자 또는 최소 보안 요구 사항을 충족하지 못하는 암호 등으로 인해 사용자 작성이 실패 할 가능성이 큽니다. 확실하지 않습니다. 클릭 후 page.html을 출력하면 유효성 검사 오류가 표시되거나 test.log에도 오류가 표시됩니다.

또한 click_on은 JS 가능 드라이버를 사용하는 경우 비동기적일 수 있으므로 have_current_path는 사용자 변경이 완료되었음을 나타내는 페이지 변경이 발생할 때까지 기다리기 때문에 테스트의 마지막 두 줄을 스왑해야합니다. 그래도 현재의 문제는 해결되지 않지만 직접 데이터베이스 쿼리를 실행하기 전에 작업이 완료되었는지 확인하기 위해 Capybara matchers를 사용하면 장래에 발생할 수있는 문제를 줄일 수 있습니다 (단, 직접 데이터베이스 쿼리는 일반적으로 잘못된 코드 냄새입니다. 기능 테스트).