Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,14 @@ Net::HTTP.get('www.example.com',
'/thing/5.json?x=1&y=2&z=3&anyParam=4') # ===> Success
```

### Allow query params

```ruby
stub_request(:get, "www.example.com").with(query: :any)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even this usage still feels a little heavy-weight to me.... Is there any reason we can't do stub_request(:get, "www.example.com", query: :any)? Or even just make it the default?


RestClient.get("http://www.example.com/?q=example") # ===> Success
```

### Matching query params using hash

```ruby
Expand Down
2 changes: 2 additions & 0 deletions lib/webmock/request_pattern.rb
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ def initialize(pattern)
def add_query_params(query_params)
@query_params = if query_params.is_a?(Hash)
query_params
elsif query_params == :any
WebMock::Matchers::AnyArgMatcher.new(nil)
elsif query_params.is_a?(WebMock::Matchers::HashIncludingMatcher) \
|| query_params.is_a?(WebMock::Matchers::HashExcludingMatcher)
query_params
Expand Down
7 changes: 7 additions & 0 deletions spec/acceptance/shared/request_expectations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,13 @@
expect(a_request(:get, "www.example.com").with(query: hash_including(a: []))).to have_been_made
}.not_to raise_error
end

it "should satisfy expectation if the request was executed with query params declared as :any" do
expect {
http_request(:get, "http://www.example.com/?x=3&b=1")
expect(a_request(:get, "www.example.com").with(query: :any)).to have_been_made
}.not_to raise_error
end
end

context "when using flat array notation" do
Expand Down