tags:

views:

505

answers:

1

I'm trying to check that a new action in my RESTful controller set up an instance variable of the required Object type. Seems pretty typical, but having trouble executing it

Client Controller

def new
  @client = Client.new
end  

Test

describe "GET 'new'" do
  it "should be successful" do
    get 'new'
    response.should be_success
  end

  it "should create a new client" do
    get 'new'
    assigns(:client).should == Client.new
  end
end

Results in...

'ClientsController GET 'new' should create a new client' FAILED
expected: #<Client id: nil, name: nil, created_at: nil, updated_at: nil, company_id: nil>,
     got: #<Client id: nil, name: nil, created_at: nil, updated_at: nil, company_id: nil> (using ==)

Which is probably because it's trying to compare 2 instances of active record, which differ. So, how do I check that the controller set up an instance variable that holds a new instance of the Client model.

A: 

technicalpickles in #rspec helped me out...

assigns(:client).should be_kind_of(Client)
fakingfantastic