webmock 3.30.0 → 3.31.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 +16 -0
- data/README.md +14 -0
- data/lib/webmock/request_pattern.rb +4 -1
- data/lib/webmock/request_signature.rb +7 -3
- data/lib/webmock/request_stub.rb +13 -5
- data/lib/webmock/version.rb +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: fd3966eb9bb71d2c1ef49c389d9f0a90520cd662cd2a2a10d36568eaadbffa33
|
|
4
|
+
data.tar.gz: ec1209ad4ec45fce69665fd4e64a1f59743716a043e42b3e63b8bcddced6911a
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 58a66d8ce0f9f893d8862835d28728e585a8ebd2ff074a64b7a88b09508aa2caeb3181e62cfd7adcef7df67da463aa50c1718b6955aa4bf34f42d5fde35a9575
|
|
7
|
+
data.tar.gz: 3105e385e8f5aa63acf07a874a8d93100f3f8d739aae9d56cfe77e479576afe91541af70aa3a739828c59c170c2adb86335e2ad635b20b1c8941266e28a88202
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
# 3.31.0
|
|
4
|
+
|
|
5
|
+
* Return the contents of a `File` or `Pathname` body given to `to_return_json`, or returned by its body lambda, instead of encoding the object as a JSON string (#1119)
|
|
6
|
+
|
|
7
|
+
The file is read and closed as it is for `to_return`: when the stub is declared, or on each request when it comes from a lambda.
|
|
8
|
+
|
|
9
|
+
Thanks to [Alex](https://github.com/ac1982)
|
|
10
|
+
|
|
11
|
+
* Match HTTP methods given as a string or in upper case, as in `stub_request("get", ...)`, `a_request("GET", ...)` or `assert_requested("post", ...)` (#821)
|
|
12
|
+
|
|
13
|
+
Before, such a method never matched, so the stub never applied and negative expectations like `assert_not_requested("get", ...)` always passed. A test that passed only because of this can now fail.
|
|
14
|
+
|
|
15
|
+
The method of a request is now always a lower case Symbol too. A request made with an upper case method, as Typhoeus does with `method: :POST`, now matches a `:post` stub, and callbacks and `with` blocks see `:post`.
|
|
16
|
+
|
|
17
|
+
Thanks to [Euisan Kim](https://github.com/euisan)
|
|
18
|
+
|
|
3
19
|
# 3.30.0
|
|
4
20
|
|
|
5
21
|
* Allow narrowing an RSpec expectation on a stub with `with`, as in `expect(stub).to have_been_requested.once.with(body: "abc")` (#1128)
|
data/README.md
CHANGED
|
@@ -363,6 +363,20 @@ stub_request(:any, "www.example.com").
|
|
|
363
363
|
Net::HTTP.get('www.example.com', '/') # ===> "{\"foo\": \"bar\"}"
|
|
364
364
|
```
|
|
365
365
|
|
|
366
|
+
A `File` or `Pathname` body is returned as it is, so it should hold JSON that is already encoded:
|
|
367
|
+
|
|
368
|
+
```ruby
|
|
369
|
+
stub_request(:get, "www.example.com").
|
|
370
|
+
to_return_json(body: Pathname.new('spec/fixtures/response.json'))
|
|
371
|
+
```
|
|
372
|
+
|
|
373
|
+
As with `to_return`, the file is read and closed when the stub is declared, so later changes to it don't affect the response. To read the file on every request, return it from a lambda. A lambda that returns a `File` must open a new one each time, since each one is closed after it is read.
|
|
374
|
+
|
|
375
|
+
```ruby
|
|
376
|
+
stub_request(:get, "www.example.com").
|
|
377
|
+
to_return_json(body: -> { Pathname.new('spec/fixtures/response.json') })
|
|
378
|
+
```
|
|
379
|
+
|
|
366
380
|
### Response with custom status message
|
|
367
381
|
|
|
368
382
|
```ruby
|
|
@@ -94,8 +94,11 @@ module WebMock
|
|
|
94
94
|
|
|
95
95
|
|
|
96
96
|
class MethodPattern
|
|
97
|
+
# Request signatures store the method as a lower case Symbol, so a method
|
|
98
|
+
# given as a String or in upper case, like "get" or :GET, matches too.
|
|
99
|
+
# Anything else, such as nil, is kept as given and never matches.
|
|
97
100
|
def initialize(pattern)
|
|
98
|
-
@pattern = pattern
|
|
101
|
+
@pattern = pattern.respond_to?(:to_sym) ? pattern.to_sym.downcase : pattern
|
|
99
102
|
end
|
|
100
103
|
|
|
101
104
|
def matches?(method)
|
|
@@ -4,11 +4,11 @@ module WebMock
|
|
|
4
4
|
|
|
5
5
|
class RequestSignature
|
|
6
6
|
|
|
7
|
-
attr_accessor :
|
|
8
|
-
attr_reader :headers
|
|
7
|
+
attr_accessor :uri, :body
|
|
8
|
+
attr_reader :method, :headers
|
|
9
9
|
|
|
10
10
|
def initialize(method, uri, options = {})
|
|
11
|
-
self.method = method
|
|
11
|
+
self.method = method
|
|
12
12
|
self.uri = uri.is_a?(Addressable::URI) ? uri : WebMock::Util::URI.normalize_uri(uri)
|
|
13
13
|
assign_options(options)
|
|
14
14
|
end
|
|
@@ -23,6 +23,10 @@ module WebMock
|
|
|
23
23
|
string
|
|
24
24
|
end
|
|
25
25
|
|
|
26
|
+
def method=(method)
|
|
27
|
+
@method = method.to_sym.downcase
|
|
28
|
+
end
|
|
29
|
+
|
|
26
30
|
def headers=(headers)
|
|
27
31
|
@headers = WebMock::Util::Headers.normalize_headers(headers)
|
|
28
32
|
end
|
data/lib/webmock/request_stub.rb
CHANGED
|
@@ -39,13 +39,10 @@ module WebMock
|
|
|
39
39
|
else
|
|
40
40
|
body.call
|
|
41
41
|
end
|
|
42
|
-
b
|
|
43
|
-
b
|
|
42
|
+
json_response_body(b)
|
|
44
43
|
}
|
|
45
|
-
elsif !body.is_a?(String)
|
|
46
|
-
body.to_json
|
|
47
44
|
else
|
|
48
|
-
body
|
|
45
|
+
json_response_body(body)
|
|
49
46
|
end
|
|
50
47
|
|
|
51
48
|
resp_h.merge(
|
|
@@ -130,5 +127,16 @@ module WebMock
|
|
|
130
127
|
end
|
|
131
128
|
stub
|
|
132
129
|
end
|
|
130
|
+
|
|
131
|
+
private
|
|
132
|
+
|
|
133
|
+
def json_response_body(body)
|
|
134
|
+
case body
|
|
135
|
+
when String, IO, Pathname
|
|
136
|
+
body
|
|
137
|
+
else
|
|
138
|
+
body.to_json
|
|
139
|
+
end
|
|
140
|
+
end
|
|
133
141
|
end
|
|
134
142
|
end
|
data/lib/webmock/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: webmock
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 3.
|
|
4
|
+
version: 3.31.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Bartosz Blimke
|
|
@@ -360,9 +360,9 @@ licenses:
|
|
|
360
360
|
- MIT
|
|
361
361
|
metadata:
|
|
362
362
|
bug_tracker_uri: https://github.com/bblimke/webmock/issues
|
|
363
|
-
changelog_uri: https://github.com/bblimke/webmock/blob/v3.
|
|
364
|
-
documentation_uri: https://www.rubydoc.info/gems/webmock/3.
|
|
365
|
-
source_code_uri: https://github.com/bblimke/webmock/tree/v3.
|
|
363
|
+
changelog_uri: https://github.com/bblimke/webmock/blob/v3.31.0/CHANGELOG.md
|
|
364
|
+
documentation_uri: https://www.rubydoc.info/gems/webmock/3.31.0
|
|
365
|
+
source_code_uri: https://github.com/bblimke/webmock/tree/v3.31.0
|
|
366
366
|
wiki_uri: https://github.com/bblimke/webmock/wiki
|
|
367
367
|
rdoc_options: []
|
|
368
368
|
require_paths:
|