All threads / Mocking HTTPParty response

Ask A Question

Notifications

You’re not receiving notifications from this thread.

Mocking HTTPParty response

Ashwin Bhaskar asked in Ruby

I am trying to mock/stub a method that returns a http party response. I am not sure if my construction of HTTPParty Response object is correct.

httparty_req = HTTParty::Request.new Net::HTTP::Get, '/'
 response = HTTParty::Response.new(httparty_req, {}, lambda {''}, {:body => edit_valid_attributes})
allow(MyClass).to receive(:find).with(my_data).and_return(response)

But when I try to print the response, it printins an emplty line. The body contains data. Am I constructing the respnse incorrectly?

puts response.class                        //Prints HTTParty::Response
puts response                                 //Prints empty line
puts response.body                       //prints the body
puts response.parsed_response  //Prints empty line
Join the discussion

Want to stay up-to-date with Ruby on Rails?

Join 33,399+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.

    logo Created with Sketch.

    Ruby on Rails tutorials, guides, and screencasts for web developers learning Ruby, Rails, Javascript, Turbolinks, Stimulus.js, Vue.js, and more. Icons by Icons8

    © 2020 GoRails, LLC. All rights reserved.