规格:
require 'spec_helper'
describe UsersController do
describe "GET index" do
it "assigns @users" do
user = User.create(:email => 'bob@test.com', :password=>'12', :password_confirmation=> '12')
get :index
assigns(:users).should eq([user])
end
it "renders the index template" do
get :index
response.should render_template("index")
end
end
end
代码:
class UsersController < ApplicationController
def index
@users=User.all
end
end
错误:
Failures:
1) UsersController GET index assigns @users
Failure/Error: @users.should eq([user])
expected: [#<User id: nil, email: "bob@test.com", encrypted_password: "$2a$04$JRFUhZxmw1jVCVRFx1bkIO9dpiJbVpbBhlXkGq.zbVyj...", reset_password_token: nil, reset_password_sent_at: nil, remember_created_at: nil, sign_in_count: 0, current_sign_in_at: nil, last_sign_in_at: nil, current_sign_in_ip: nil, last_sign_in_ip: nil, created_at: nil, updated_at: nil, admin: nil>]
got: []
(compared using ==)