0
我的設計用戶是:confirmable
,我想測試用戶在註冊後重定向到設計登錄頁面。它在我手動測試時正常工作,但在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
故障恢復:
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)>'
好像page
被卡在後路徑,或者被重定向到/users
不正確?我知道表單接受輸入是因爲我的理智檢查用戶是否存在。