title: RSpec and Rails 3 - Simple tests failing
body: <p>RSpec 2.5, Rails 3.0.6 - git://github.com/stevecastaneda/project.git</p>
  
  <p>I'm doing a few simple tests to make sure users are valid when registering.  The test that is failing is "should require username".  The resulting error is:</p>
  
  <pre><code>Failure/Error: new_user(:username =&gt; '').should have(1).error_on(:username)
         expected 1 error on :username, got 0
  </code></pre>
  
  <p><strong>user_spec.rb</strong></p>
  
  <pre><code>require File.dirname(__FILE__) + '/../spec_helper'
  
  describe User do
    def new_user(attributes = {})
      attributes[:username] ||= 'foo'
      attributes[:email] ||= 'foo@example.com'
      attributes[:password] ||= 'abc123'
      attributes[:password_confirmation] ||= attributes[:password]
      User.new(attributes)
    end
  
    before(:each) do
      User.delete_all
    end
  
    it "should be valid" do
      new_user.should be_valid
    end
  
    it "should require username" do
      new_user(:username =&gt; '').should have(1).error_on(:username)
    end
  end
  </code></pre>
  
  <p><strong>User.rb</strong></p>
  
  <pre><code>class User &lt; ActiveRecord::Base
    # new columns need to be added here to be writable through mass assignment
    attr_accessible :username, :email, :password, :password_confirmation
  
    attr_accessor :password
    before_save :prepare_password
  
    validates_presence_of :username
    validates_uniqueness_of :username, :email, :allow_blank =&gt; true
    validates_format_of :username, :with =&gt; /^[-\w\._@]+$/i, :allow_blank =&gt; true, :message =&gt; "should only contain letters, numbers, or .-_@"
    validates_format_of :email, :with =&gt; /^[-a-z0-9_+\.]+\@([-a-z0-9]+\.)+[a-z0-9]{2,4}$/i
    validates_presence_of :password, :on =&gt; :create
    validates_confirmation_of :password
    validates_length_of :password, :minimum =&gt; 4, :allow_blank =&gt; true
  
    # login can be either username or email address
    def self.authenticate(login, pass)
      user = find_by_username(login) || find_by_email(login)
      return user if user &amp;&amp; user.password_hash == user.encrypt_password(pass)
    end
  
    def encrypt_password(pass)
      BCrypt::Engine.hash_secret(pass, password_salt)
    end
  
    private
  
    def prepare_password
      unless password.blank?
        self.password_salt = BCrypt::Engine.generate_salt
        self.password_hash = encrypt_password(password)
      end
    end
  end
  </code></pre>
  
  <p>As you can see I'm simply creating a new user (not using factories just yet, just simple tests) with an empty username and because of <code>validates_presence_of :username</code> it should have errors.</p>
  
  <p>What am I missing?</p>