Webmock does not respond to a stub request with a request

I am working on a Ruby on Rails stone and I am trying to use webmock because I need to interact (and test) an external API that is not under my control.

So here is the snippet that is in before(:each), because I bit it:

before do
  uri = URI.join(client.class.base_uri, DataComApi::ApiURI.search_contact).to_s
  stub_request(
    :get,
    uri
  ).with(
    query: hash_including({
      'pageSize' => 0,
      'offset'   => 0
    })
  ).to_return(
    body: FactoryGirl.build(
      :data_com_search_contact_response,
      totalHits: 0
    ).to_json
  )
  # DEBUG
  require 'httparty'
  HTTParty.get(
    uri,
    {
      query: {
        offset:   0,
        pageSize: 0
      }
    }
  )
end

And here you can see the console output of the command rspec:

  3) DataComApi::Client#search_contact returns instance of SearchContact
     Failure/Error: HTTParty.get(
     WebMock::NetConnectNotAllowedError:
       Real HTTP connections are disabled. Unregistered request: GET https://www.jigsaw.com/rest/searchContact.json?offset=0&pageSize=0

       You can stub this request with the following snippet:

       stub_request(:get, "https://www.jigsaw.com/rest/searchContact.json?offset=0&pageSize=0").
         to_return(:status => 200, :body => "", :headers => {})

       registered request stubs:

       stub_request(:get, "https://www.jigsaw.com/rest/searchContact.json with query params hash_including({"offset"=>0, "pageSize"=>0})")

       ============================================================
     # ./spec/models/client_spec.rb:65:in `block (3 levels) in <top (r

If I delete the key :queryboth on HTTParty.getand in stub_request, it works, but I need these keys and values ​​to check the API.

I tested even replacing in stub_request, urion /searchContact.json/, but had the same problem.

Here you can find GIST

+3
source share
1 answer

, , : webmock 'query' (a String), Symbol . , .

: https://github.com/bblimke/webmock/issues/366

Edit , , : , , (params )

+4

All Articles