I am new to testing and I have a UserController that I want to test. I start with a new action and still have the following:
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
My UserController so far looks like
class UsersController < ApplicationController def new @user = User.new end end
I expected my first test to work, but when I run it, I get the following:
Failures: 1) UsersController GET 'new' assigns a new User to @user Failure/Error: assigns(:user).should eq(user) expected:
A game in the console shows the following:
irb(main):001:0> a = User.new =>
So now I'm curious why the 2 empty ActiveRecord objects are not equal (after all, Array.new == Array.new
returns true) and what I need to do to pass the test.
source share