mardi 18 avril 2017

RSpec/Shoulda-Matchers: validate_confirmation_of(:password) errors

When I run the following rspec-test:

require 'rails_helper'

describe User do
  before { @user = FactoryGirl.build(:user) }
  subject { @user }

  it { should respond_to(:email) }
  it { should respond_to(:password) }
  it { should respond_to(:password_confirmation) }
  it { should be_valid }
  it { should validate_presence_of(:email) }
  it { should validate_uniqueness_of(:email) }
  it { should validate_confirmation_of(:password_confirmation) }
  it { should allow_value('example@mail.com').for(:email) }
end

I get the error:

  3) User should require password_confirmation_confirmation to match password_confirmation
     Failure/Error: it { should validate_confirmation_of(:password_confirmation) }
     Expected errors to include "doesn't match Password confirmation" when password_confirmation is set to "different value", got errors: ["password_confirmation doesn't match Password (\"different value\")"]

The User model was created with devise and I didn't changed anything with the code. Changing :password_confimation to :password resulted in the same error.

I've installed RSpec and Shoulda-Matchers like this in the Gemfile:

  group :development, :test do
    ...
    gem 'rspec-rails', '~> 3.5', '>= 3.5.2'
    ....
  end

  group :test do
    ...
    gem 'shoulda-matchers'
    ...
  end

Aucun commentaire:

Enregistrer un commentaire