title: Rails 3.1 Rspec Creating test case validate field for Model
body: <p>I'm trying to create a test case for User model. Basically, it will validate first_name and last_name to be present. </p>
  
  <p>What I am trying to do is to check whether the error on a specific field is empty or not and it should be empty. However it always fails.</p>
  
  <p>What is the correct way to do this? </p>
  
  <p>Here is my code</p>
  
  <p>On my user_spec.rb</p>
  
  <pre><code>require 'spec_helper'
  
  describe User do
  
    before do
      @user = User.new
    end
  
    it "must have a first name" do
      @user.errors[:first_name].should_not be_empty
    end
  
    it "must have a last name" do
      @user.errors[:last_name].should_not be_empty
    end
  end
  </code></pre>
  
  <p>On my user.rb file</p>
  
  <pre><code>class User &lt; ActiveRecord::Base
    validates :first_name, :presence =&gt; true
    validates :last_name, :presence =&gt; true
  end
  </code></pre>