失敗したテストは次のとおりです。
context "when password does not match confirmation" do
before { build(:user, :password_confirmation => 'mismatch') }
it { should_not be_valid }
end
build
このテストスイートにはファクトリーガールの方法を使用しています。
私のユーザーモデル:
class User < ActiveRecord::Base
attr_accessible :email, :name, :password, :password_confirmation
has_secure_password
validates :password_confirmation, presence: true
validates :password, presence: true, length: { minimum: 5 }
end
更新:has_secure_passwordを使用する場合、:passwordフィールドを:confirmation=>trueでマークする必要はありません。処理されます:ソースコードを参照してください:https ://github.com/rails/rails/blob/master/activemodel/lib/active_model/secure_password.rb
検証は正常に機能しています。コンソールで新しいユーザーを作成しようとすると、正しいエラーメッセージが表示されます。では、なぜテストが失敗するのでしょうか。バグはどこにありますか?