2

This is my rspec code:-

  it "which has max value" do
    get :index, Devise.token_authentication_key => @user.authentication_token, business_id: @business.id, max: '1'
    expect(request.flash[:alert]).to eq(nil)
    expect(response.body).to eq([@location].to_json(LocationFinder::API_PARAMS.merge(:root => false)))
  end

and testing result is-

expected: "[{\"address\":\"1120 Milky Way\",\"business_id\":1,\"city\":\"Cupertino]"

  got: "[{\"address\":\"1120 Milky Way\",\"business_id\":1,\"city\":\"Cupertino,\"distance\":260.33452958767384,]"

Here Distance is an extra field , how can i check particular fields or if it is not possible , how to eliminate "distance" field which is not check by rspec.

1 Answer 1

3

You could check individual fields using something like:

# get the first entry in the JSON array
json_response = JSON.parse(response.body).first

# compare each field
expect(json_response['address']).to eq(@location.address)
expect(json_response['business_id']).to eq(@location.business_id)
expect(json_response['city']).to eq(@location.city)

Of course you may need to adjust the exact methods you call on @location depending on your implementation, but that's the gist of it.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.