Rspec feature specs not working with Devise sign up

Viewed 118

I want to test that a user can log in and that a visitor can sign up. The log in works well but for sign up it is not working for some reason. This is my feature spec:

require 'rails_helper'

RSpec.feature "Devise interactions", type: :feature do
    let(:user) { FactoryBot.create(:non_admin_user) }

    scenario "user logs in sucessfully" do
        visit new_user_session_path

        fill_in "Email", with: user.email
        fill_in "Password", with: user.password
        click_button "Log in"

        expect(page).to have_current_path "/"
    end

    scenario "user logs in unsuccesfully" do
        visit new_user_session_path

        fill_in "Password", with: user.password
        click_button "Log in"

        expect(page).to have_text('Invalid Email or password')
    end

    scenario "visitor signs up succesfully", js:true do
        visit new_user_registration_path

        fill_in "Username", with: "josem"
        fill_in "Email", with: "abcd@test.com"
        within ".user_password" do
            fill_in 'Password', with: 'testing'
        end
        within ".user_password_confirmation" do
            fill_in 'Password confirmation', with: 'testing'
        end

        #save_and_open_screenshot

        click_button "Sign up"

        #save_and_open_screenshot

        expect(page).to have_text('Welcome! You have signed up successfully.')
    end

    scenario "visitor signs up unsuccesfully" do
        visit new_user_registration_path

        fill_in "Username", with: "josem"
        fill_in "Email", with: "abcd"
        within ".user_password" do
            fill_in 'Password', with: 'password'
        end
        within ".user_password_confirmation" do
            fill_in 'Password confirmation', with: 'password'
        end
        click_button "Sign up"

        expect(page).to have_text('Email is invalid')
    end
end

The third scenario:

scenario "visitor signs up succesfully", js:true do
        visit new_user_registration_path

        fill_in "Username", with: "josem"
        fill_in "Email", with: "abcd@test.com"
        within ".user_password" do
            fill_in 'Password', with: 'testing'
        end
        within ".user_password_confirmation" do
            fill_in 'Password confirmation', with: 'testing'
        end

        #save_and_open_screenshot

        click_button "Sign up"

        #save_and_open_screenshot

        expect(page).to have_text('Welcome! You have signed up successfully.')
    end

Is the one that is not working. Been trying to debug:

  1. Before the Sign up button is clicked, everything is written correctly
  2. After the Sign up button is clicked, I only get an error of Please review the problems below: but it doesn´t say what type of error (there shouldn't be any error since the validations are all successful).
  3. When I go to my Rails app and try to sign up manually, every time I have an error, it will point it out but it doesn't in the spec.

Since the log in is working, I doubt it is an error from the Devise config and I can´t find out why. Any ideas on why is it happening? Thanks!!

1 Answers

I feel the error that you are getting is not from the device. Because devise doesn't have any error with message Please review the problems below. Possibly the error is from the simple_form gem which you might be using(check your Gemfile.lock). simple_form gem has the same error notification which you have mentioned. Please refer to the code Please review the problems below.

Also, you can see the feature test log tail -f log/test.log.

Related