My devise user is :confirmable
, and I want to test that the user is redirected to the devise login page after signing up. It works when I manually test it, but fails in rspec/capybara feature spec. I'm following these instructions to setup the redirect.
# 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 returned:
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)>'
It seems like page
is stuck in the post path, or is being redirected to /users
incorrectly? I know the form is accepting the input because of my sanity check that the user exists.