I'm learning TDD with Rails 4 and rspec. I've made some test cases for my user model to check the password lengths. I have two tests so far that checks whether a user input a password that was too short and one where the password is between 6 - 10 characters.

So far, the "password is too short" test passes:

```
it "validation says password too short if password is less than 6 characters" do
  short_password = User.create(email: "tester@gmail.com", password: "12345")
  expect(short_password).not_to be_valid
end  

```

However, on the test where I do have a valid password, it fails:

```
it "validation allows passwords larger than 6 and less than 10" do
  good_password = User.create(email: "tester2@gmail.com", password: "blahblah")
  expect(good_password).to be_valid
end

```

And I get this error:

```
Failure/Error: expect(good_password).to be_valid
   expected #<User id: 1, email: "tester2@gmail.com", 
   created_at: "2014-06-21 02:43:42", updated_at: "2014-06-21 02:43:42",
   password_digest: nil, password: nil, password_hash: "$2a$10$7u0xdDEcc6KJcAi32LBW7uzV9n7xYbfOhZWdcOnU5Cdm...",
   password_salt: "$2a$10$7u0xdDEcc6KJcAi32LBW7u"> to be valid, 
   but got errors: Password can't be blank, Password is too short (minimum is 6 characters)
 # ./spec/models/user_spec.rb:12:in `block (3 levels) in <top (required)>'

```

EDIT: Here's my model code:

```
class User < ActiveRecord::Base

  has_many :pets, dependent: :destroy
  accepts_nested_attributes_for :pets, :allow_destroy => true
  VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i
  validates :email, presence: true, format: { with: VALID_EMAIL_REGEX },
  uniqueness: true

  validates :password, presence: true, :length => 6..10, :confirmation => true

  #callbacks
  before_save :encrypt_password
  after_save :clear_password

  #method to authenticate the user and password
  def self.authenticate(email, password)
    user = find_by_email(email)
    if user && user.password_hash == BCrypt::Engine.hash_secret(password, user.password_salt)
      user
    else
      nil
    end
  end

  #method to encrypt password
  def encrypt_password
    if password.present?
      self.password_salt = BCrypt::Engine.generate_salt
      self.password_hash = BCrypt::Engine.hash_secret(password, password_salt)
    end
  end

  #clears password
  def clear_password
    self.password = nil
  end
end

```

I'm confused on why the password is nil when I create the test object.

Thanks!