Change the test string before to this:
before { @user = User.new( name: 'joe', email: ' joe@mail.com ', password: 'foo', password_confirmation: 'foo')
That should fix it.
What it is:
Do you know how, when creating a new account on any website, they ask you to enter a password and enter it twice? What it is. When you create a new user, has_secure_password wants a password twice to make sure that you did not make a typo.
If password ! = password_confirmation , it will throw an exception and the user will not be created.
Again, this is used only for user creation . You do not need to enter two passwords in the form of login or something else. You do not need to add this field to your model or database.
If you have a user creation form, and you do not want to have a password_confirmation field, then you do not need this. You can set password_confirmation = password in your controller before you call save or something else.
But for the creation user, password_confirmation should be present.
source share