I am testing my controller with RSPEC in ruby on rails. Here is the (relevant parts of the) controller action i am testing,
Controller Code:
before do
@company=FactoryGirl.create(:company)
@customer=FactoryGirl.create(:customer, company_id: @company.id)
@job=FactoryGirl.create(:job, customer_id: @customer.id, company_id: @company.id)
end
class JobsController < ApplicationController
def new
if params[:customer_id]
@job = current_member.company.jobs.new(
customer_id: params[:customer_id],
lead_id: params[:lead_id]
)
else
...
end
...
end
RSPEC Code:
it "has valid job with customer_id param" do
get :new, {:customer_id=>@customer.id, :lead_id=>@job.lead_id}
expect(assigns(:job)).to eq @member.company.jobs.new(customer_id:@customer.id, lead_id:@job.lead_id)
end
Here is the error I am getting:
Failures:
1) Failure/Error: expect(assigns(:job)).to eq @member.company.jobs.new(customer_id:@customer.id, lead_id:@job.lead_id)
expected: #<Job id: nil, name: nil, status: "pending", company_id: 43, account_id_old: nil, job_type_id: nil, address_id: nil, trade_id: nil, lead_id: nil, started_date: nil, end_date: nil, created_at: nil, updated_at: nil, order_number: nil, creator_id: nil, account_id: nil, customer_id: 22, contact_id: nil>
got: #<Job id: nil, name: nil, status: "pending", company_id: 43, account_id_old: nil, job_type_id: nil, address_id: nil, trade_id: nil, lead_id: nil, started_date: nil, end_date: nil, created_at: nil, updated_at: nil, order_number: nil, creator_id: nil, account_id: nil, customer_id: 22, contact_id: nil>
(compared using ==)
I dont get it, both the 'expected' and the 'got' sections appear to be the same thing! Ideas/Help please?
Aucun commentaire:
Enregistrer un commentaire