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
Reply
Join the discussion

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

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

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

    Screencast tutorials to help you learn Ruby on Rails, Javascript, Hotwire, Turbo, Stimulus.js, PostgreSQL, MySQL, Ubuntu, and more. Icons by Icons8

    © 2023 GoRails, LLC. All rights reserved.