【发布时间】:2017-04-02 02:56:17
【问题描述】:
我的设计用户是:confirmable,我想测试用户在注册后是否被重定向到设计登录页面。当我手动测试它时它可以工作,但在 rspec/capybara 功能规范中失败。我正在按照these 的说明设置重定向。
# 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: 'user123@email.com'
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 "/users/sign_in"
# ./spec/features/registration_spec.rb:19:in `block (2 levels) in <top (required)>'
page 似乎卡在帖子路径中,或者被错误地重定向到 /users?我知道表单正在接受输入,因为我检查了用户是否存在。
【问题讨论】:
标签: ruby-on-rails rspec devise capybara devise-confirmable