How do I get an httparty block from the response body?

0

I use the Ruby language, Cucumber framework, and the HttParty gem.

I tried some ways to give expect in response Body to hit something that returns in it. My last attempt to hit user_id = 11111111 was:

expect(@response.body["user_id"]).to eq 11111111

That returns the error:

  

expected: 11111111

     

got: "user_id"

That is, my logic is wrong, I tried n forms where the error message was different.

    
asked by anonymous 08.11.2017 / 14:41

1 answer

0

Come on.

To get the response of a call you can do the following:

def seu_metodo
   response = HTTParty.post(url,
              headers:    headers,
              body:{seu body},

   user_id = response.parsed_response['user_id']
end

If you want to make an assert you need to extract the value and not the field, it might be that swapping .body by .parsed_response will work:)

I would recommend not doing API tests using cucumber and yes Rspec the cucumber you create a complexity of having an updated .feature and a step_definitions too, off if it does not have a class with API's abstractions.

I would go by the way of rspec + httparty the tests are well written and you take away the complexity of maintenance

    
26.03.2018 / 19:11