Skip to content

hash_including not working at all? Doesn't find any query #371

Description

@Fire-Dragon-DoL

I wrote a test after finding out that my stubbed requests were not called correctly, here is a test code:

require 'spec_helper'

describe WebMock, focus: true do
  let!(:dummy_url) { 'http://dummyurl.com' }

  it "receive a request when mocked with query param on a regex" do
    stub_request(
      :get,
      /#{ dummy_url }/
    ).with(
      query: hash_including({
        param1: 5
      })
    ).to_return(
      body: 'body 1'
    )

    expect(
      HTTParty.get(dummy_url, {
        query: {
          param1: 5,
          param2: 'random1'
        }
      }).body
    ).to eq 'body 1'
  end

  it "receive a request when mocked with query param without a regex" do
    stub_request(
      :get,
      dummy_url
    ).with(
      query: hash_including({
        param1: 5
      })
    ).to_return(
      body: 'body 1'
    )

    expect(
      HTTParty.get(dummy_url, {
        query: {
          param1: 5,
          param2: 'random1'
        }
      }).body
    ).to eq 'body 1'
  end

end

Both of them are not passing, they do not receive the request.
Notice that if I use do end block in with, I do manage to receive the request so it's definitely hash_including the issue, expecially because if I remove it, the query matching works fine (if I add param2: 'random1').

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions