ruby - rails rspec expected is not json -
my spec doesn't seem behaving properly, or rather code isn't.
here's test:
describe 'get #show' before(:each) @os = factorygirl.create :deployer_os :os end 'returns operating systems' os_response = json_response expect(os_response).to eql @os end { should respond_with 200 } end
factory:
factorygirl.define factory :deployer_os, :class => 'deployeros' platform 'darwin' version '10.10' description 'yosemite' end end
result:
failure/error: expect(os_response).to eql @os expected: #<deployeros id: 120, platform: "darwin", version: "10.10", description: "yosemite", created_at: "2015-10-15 07:03:44", updated_at: "2015-10-15 07:03:44"> got: {:deployer=>[{:id=>120, :platform=>"darwin", :version=>"10.10", :description=>"yosemite", :created_at=>"2015-10-15t07:03:44.642z", :updated_at=>"2015-10-15t07:03:44.642z"}]} (compared using eql?) diff: ...
i'm not sure how resolve this? i'm getting result want don't think i'm writing test correctly.
update
modifying test works i'm wondering if best way accomplish this?
describe 'get #show' before(:each) @os = json.parse((factorygirl.create :deployer_os).to_json, symbolize_names: true) :os end 'returns operating systems' os_response = json_response expect(os_response).to eql @os end { should respond_with 200 } end
you have json in response compare object, why? try next:
@os.to_json
but @os - it's singe object , in response have array. decision must consider want go request.
Comments
Post a Comment