[rspec-users] Can anyone tell me why this test is failing?

Mohamad El-Husseini husseini.mel at gmail.com
Wed Feb 29 04:43:24 UTC 2012

I ran this scenario in the console and it works as expected. But RSpec 
keeps failing the test and I can't understand why.

describe User do

  before do
    @user = User.new(name: "Mickey Mouse", email: "mickey at disney.com", 
password: "m1ckey", password_confirmation: "m1ckey")

    # Password
    describe "when password is not present" do
      before { @user.password = @user.password_confirmation = " " }
      it { should_not be_valid }

--> expected valid? to return false, got true

If I take out the @user.password_confirmation from the assignment, it works:

      before { @user.password = " " }
      it { should_not be_valid }

But, as I said, using the console I can verify that everything works as 
expected. Why does adding @password_confirmation break the test?

Here's my user model:

class User < ActiveRecord::Base
  attr_accessible :name, :email, :password, :password_confirmation
  validates :password,  length: { minimum: 6 }
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20120228/d031e148/attachment.html>

More information about the rspec-users mailing list