philiprehberger-http_mock 0.3.1 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/README.md +16 -0
- data/lib/philiprehberger/http_mock/version.rb +1 -1
- data/lib/philiprehberger/http_mock.rb +17 -0
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 972e16a3c97d00fba0369288140c24f523932a5eee58bf0539d8731d743d4f4c
|
|
4
|
+
data.tar.gz: 6d6900eb27ffd533cdbf8094263bd5d83b694bc50d29c30b61970739431b27eb
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 47b5e3a6f310070e4d73b34671a1501ea16a0ebf0a42fcce0b278882567913bf7fba8e0426a984f67d137c5a8cf76a5b3cc0f5efdd1e86bdfc1764c50909b2f8
|
|
7
|
+
data.tar.gz: a80a5e20b6c88c007e90a496c52b6757e31fb92f2c1696553687ca3847cd7395286fa5e9e4bdd7a934c6f6102c045438136c1f5847378f8db23fac7f1031a6ac
|
data/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [0.4.0] - 2026-04-28
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
- `HttpMock.requests_for(method, url)` — filter recorded requests by HTTP method and URL. Returns an array of matching `Request` instances in recording order. Method comparison is case-insensitive.
|
|
14
|
+
|
|
10
15
|
## [0.3.1] - 2026-04-15
|
|
11
16
|
|
|
12
17
|
### Changed
|
data/README.md
CHANGED
|
@@ -101,6 +101,21 @@ Philiprehberger::HttpMock.stub_post("https://api.example.com/users")
|
|
|
101
101
|
|
|
102
102
|
Also available: `stub_put`, `stub_patch`, `stub_delete`.
|
|
103
103
|
|
|
104
|
+
### Filtered Requests
|
|
105
|
+
|
|
106
|
+
Filter recorded requests by method and URL:
|
|
107
|
+
|
|
108
|
+
```ruby
|
|
109
|
+
Philiprehberger::HttpMock.stub_post("https://api.example.com/users").to_return(status: 201)
|
|
110
|
+
|
|
111
|
+
Philiprehberger::HttpMock.request(:post, "https://api.example.com/users", body: '{"name":"Alice"}')
|
|
112
|
+
Philiprehberger::HttpMock.request(:post, "https://api.example.com/users", body: '{"name":"Bob"}')
|
|
113
|
+
|
|
114
|
+
posts = Philiprehberger::HttpMock.requests_for(:post, "https://api.example.com/users")
|
|
115
|
+
posts.length # => 2
|
|
116
|
+
posts.map(&:body) # => ['{"name":"Alice"}', '{"name":"Bob"}']
|
|
117
|
+
```
|
|
118
|
+
|
|
104
119
|
### Last Request
|
|
105
120
|
|
|
106
121
|
```ruby
|
|
@@ -160,6 +175,7 @@ end
|
|
|
160
175
|
| `.stub_delete(url)` | Shorthand for `.stub(:delete, url)` |
|
|
161
176
|
| `.request(method, url, body:, headers:)` | Simulate a request against registered stubs |
|
|
162
177
|
| `.requests` | Get all recorded requests |
|
|
178
|
+
| `.requests_for(method, url)` | Get all recorded requests matching a method and URL (case-insensitive method) |
|
|
163
179
|
| `.last_request` | Get the most recently recorded request |
|
|
164
180
|
| `.verify!` | Raise `UnmatchedStubError` if any stub was never called |
|
|
165
181
|
| `.reset!` | Clear all stubs and recorded requests |
|
|
@@ -64,6 +64,23 @@ module Philiprehberger
|
|
|
64
64
|
registry.requests.last
|
|
65
65
|
end
|
|
66
66
|
|
|
67
|
+
# Get all recorded requests matching a method and URL
|
|
68
|
+
#
|
|
69
|
+
# The method comparison normalizes case (`:GET` matches `:get`). The URL
|
|
70
|
+
# comparison is exact against the recorded `request.url` value, so it
|
|
71
|
+
# mirrors how the stub registry stores incoming requests. Returns an
|
|
72
|
+
# empty Array when no requests match.
|
|
73
|
+
#
|
|
74
|
+
# @param method [Symbol, String] the HTTP method to filter on
|
|
75
|
+
# @param url [String] the URL to filter on
|
|
76
|
+
# @return [Array<Request>] matching requests in recording order
|
|
77
|
+
def requests_for(method, url)
|
|
78
|
+
target_method = method.to_s.downcase.to_sym
|
|
79
|
+
registry.requests.select do |req|
|
|
80
|
+
req.method.to_s.downcase.to_sym == target_method && req.url == url
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
|
|
67
84
|
# Shorthand for stub(:get, url)
|
|
68
85
|
def stub_get(url) = stub(:get, url)
|
|
69
86
|
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: philiprehberger-http_mock
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.4.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Philip Rehberger
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-04-
|
|
11
|
+
date: 2026-04-29 00:00:00.000000000 Z
|
|
12
12
|
dependencies: []
|
|
13
13
|
description: Stub HTTP requests in tests with a fluent API for matching methods, URLs,
|
|
14
14
|
headers, and bodies. Includes request recording and scoped isolation.
|