Back
rails rspec expected: 81.3 (#<BigDecimal:7ff926a51398,'0.813E2',18(27)>) got: “81.3” (compared using ==)
rspecでテストを書いていたところ、タイトルのエラーが出てきました
どうやら、rbuy のオブジェクトと、データベースの精度の違いによるもののようです
describe 'GET #show' do before do @product = create(:product) get "/products/#{@product.id}", format: :json end it 'returns 200 status' do expect(response).to be_success expect(response.status).to eq(200) end it 'contains body' do json = JSON.parse(response.body) expect(json['data']['id']).to eq(@product.id) expect(json['data']['height'].to_s).to eq(@product.height.to_s) expect(json['data']['width'].to_s).to eq(@product.width.to_s) expect(json['data']['depth'].to_s).to eq(@product.depth.to_s) expect(json['data']['description']).to eq(@product.description) end end
参考にした記事