title: How do I test the assignment of an instance variable in the new action of my controller with rspec?
body: <p>I am fairly new to testing and have a UsersController that I want to test. I am starting with the new action and so far have the following;</p>
  
  <pre><code>require 'spec_helper'
  
  describe UsersController do
  
    describe "GET 'new'" do
      it "assigns a new User to @user" do
        user = User.new
        get :new
        assigns(:user).should eq(user)
      end
      it "renders the :new template"
    end
  
  end
  </code></pre>
  
  <p>My UsersController so far looks like this</p>
  
  <pre><code>class UsersController &lt; ApplicationController
    def new
      @user = User.new
    end
  end
  </code></pre>
  
  <p>I expected my first test to work but when I run it I get the following;</p>
  
  <pre><code>Failures:
  
    1) UsersController GET 'new' assigns a new User to @user
       Failure/Error: assigns(:user).should eq(user)
  
         expected: #&lt;User id: nil, email: nil, username: nil, password_digest: nil, created_at: nil, updated_at: nil&gt;
              got: #&lt;User id: nil, email: nil, username: nil, password_digest: nil, created_at: nil, updated_at: nil&gt;
  
         (compared using ==)
  
         Diff:#&lt;User:0x007fe4bbfceed0&gt;.==(#&lt;User:0x007fe4bce5c290&gt;) returned false even though the diff between #&lt;User:0x007fe4bbfceed0&gt; and #&lt;User:0x007fe4bce5c290&gt; is empty. Check the implementation of #&lt;User:0x007fe4bbfceed0&gt;.==.
       # ./spec/controllers/users_controller_spec.rb:9:in `block (3 levels) in &lt;top (required)&gt;'
  </code></pre>
  
  <p>Playing around in the console reveals the following;</p>
  
  <pre><code>irb(main):001:0&gt; a = User.new
  =&gt; #&lt;User id: nil, email: nil, username: nil, password_digest: nil, created_at: nil, updated_at: nil&gt;
  irb(main):002:0&gt; b = User.new
  =&gt; #&lt;User id: nil, email: nil, username: nil, password_digest: nil, created_at: nil, updated_at: nil&gt;
  irb(main):003:0&gt; a == b
  =&gt; false
  </code></pre>
  
  <p>So now I'm curious as to why 2 empty ActiveRecord objects are not equal (after all, <code>Array.new == Array.new</code> returns true), and what I have to do to make my test pass.</p>