Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9156837
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T12:51:58+00:00 2026-06-17T12:51:58+00:00

Here is the failing test: context when password does not match confirmation do before

  • 0

Here is the failing test:

context "when password does not match confirmation" do
  before { build(:user, :password_confirmation => 'mismatch') }
  it { should_not be_valid }
end

I am using Factory Girl’s build method for this test suite.

My user model:

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

UPDATE: you don’t need to mark :password field with :confirmation => true when using has_secure_password. It’s taken care of: see source code: https://github.com/rails/rails/blob/master/activemodel/lib/active_model/secure_password.rb

The validation is working just fine – I get the right error message when I try creating a new user at the console. So why is the test failing? Where is the bug?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T12:52:00+00:00Added an answer on June 17, 2026 at 12:52 pm

    The validation is not working just fine, you are not validating that the password_confirmation matches the password. See http://guides.rubyonrails.org/active_record_validations_callbacks.html#confirmation for more information.

    Also, you need to make sure that you’re actually testing what you want to be testing – your subject for these tests is build(:user) when it needs to be the build(:user, password_confirmation: 'mismatch'). Change the before in your above code to a subject, to set the subject for the test correctly.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is the test that is failing: before(:each) do @attr = { :user_id =>
I do not get any error here but i am failing to display anything
Here is the code: create table `team`.`User`( `UserID` bigint NOT NULL AUTO_INCREMENT , `Username`
Edit: A minimal failing test case is now on github here: https://github.com/shadowmint/Panda-setRamImage-problem -- I
My google-fu and so-fu is failing me here, so I might as well ask.
Here is my MySQL Query that im trying to execute. it keeps failing with
I am trying to play with jQuery mouseenter and mouseleave events but failing. Here
I have a test that's failing even though the operation actually works when I
The best way (IMO): test.add(Expect job not to be done., function(expect){ expect(job.done).toBe(false); }) This
I have a project in my programming class and I'm failing a test case.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.