I have a test I can't get to work, so I want to debug my spec by printing the reponse.
I've tried using print response.body
in my spec, but there's no output in either test.log or the console.
I'm probably missing something. What should I try?
Thanks!
Mocking with RSpec is done with the rspec-mocks gem. If you have rspec as a dependency in your Gemfile , you already have rspec-mocks available.
RSpec features doubles that can be used as 'stand-ins' to mock an object that's being used by another object. Doubles are useful when testing the behaviour and interaction between objects when we don't want to call the real objects - something that can take time and often has dependencies we're not concerned with.
You can print the response using:
raise response.body
You can use
$stderr.puts response.body
To print your Response. But I will suggest to just use above code for testing and remove any puts from RSpec Unit test it is considered bad practice to write RSpec code that output something.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With