I tried to put WebMock.disable_net_connect!
in a lot of places but as recommended in my last test I put it in spec_helper.rb
like this:
require 'webmock/rspec'
WebMock.disable_net_connect!(allow_localhost: true)
My spec is the following:
describe Client do
describe '#get_something' do
context 'when post params are valid' do
it 'returns a response' do
request = stub_request(:post, 'https://myurl.com')
.to_return(my_response)
result = client.get_something(params)
expect(WebMock).to have_requested(:post, 'https://myurl.com')
end
end
end
end
Hmm, of course that my client makes the call:
class Client
def get_something(params)
RestClient.post @url, params
end
end
It fails with this message:
Failure/Error: end
The request GET https://myurl.com/ was expected to execute 1 time but it executed 0 times
The following requests were made:
No requests were made.
============================================================
I'm using rails 4.1.8, rspec 3.1.7, rspec-rails 3.1.0 and webmock 1.8.11. Right now, I'm creating a mock of a http_client to get things working, but, any help here will be appreciated! If you need more information just let me know!