What is the easiest way to test if HTTP-request is not made?
Say, I want my application NOT to send an API call to a remote server, if the user doesn't supply a username.
What RSpec test should I write in my Rails app to test that HTTP-request is never made? Can fakeweb help me somehow?
You should probably try WebMock.
It allows you to check the number of times some url was requested.
assert_requested :post, "http://www.example.com", :times => 0
Say we have the following code that makes a conditional request to GitHub's API.
if condition
user = Octokit.user 'dideler'
end
Using RSpec, you can test that the object doesn't receive the message for the method call.
expect(Octokit).to_not receive(:user)
If it passes, that means the request wasn't made.
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