webmock 3.9.3 → 3.9.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/README.md +34 -23
- data/lib/webmock/response.rb +11 -5
- data/lib/webmock/version.rb +1 -1
- data/spec/unit/response_spec.rb +22 -18
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d3a3b9d4cdfb5b9471c673ef6a3cab7e4be5e98d9115a72abf251f0bceed08b9
|
4
|
+
data.tar.gz: d71b867845cc6c805af1af7e5d7b138ecde29310521735692470aabdc5b32c17
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0bea34ef2c38c8896562c31580f08a3043db6ce2e4d61ef73a6eb42b9a1533ab7441f8e4e16d31b34a5ebace2d00b24ffc93bc7cf4fe700d2e5bd95a3d5064fb
|
7
|
+
data.tar.gz: 22658ff730ad2c05fe374e148c1c97f13e64bbe9c02a2b4aba21682a0e7ef23dc477b804e6a1e48fbbe4d717d0d212af4db4e57a3a607d6afae315f2625d5f6e
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -24,16 +24,19 @@ Features
|
|
24
24
|
Supported HTTP libraries
|
25
25
|
------------------------
|
26
26
|
|
27
|
-
*
|
28
|
-
* HTTPClient
|
29
|
-
* Patron
|
30
|
-
* EM-HTTP-Request
|
27
|
+
* Async::HTTP::Client
|
31
28
|
* Curb (currently only Curb::Easy)
|
32
|
-
*
|
29
|
+
* EM-HTTP-Request
|
33
30
|
* Excon
|
34
|
-
*
|
31
|
+
* HTTPClient
|
32
|
+
* [HTTP Gem (also known as http.rb)](https://github.com/httprb/http)
|
35
33
|
* Manticore
|
36
|
-
*
|
34
|
+
* Net::HTTP and other libraries based on Net::HTTP, e.g.:
|
35
|
+
* HTTParty
|
36
|
+
* REST Client
|
37
|
+
* RightHttpConnection
|
38
|
+
* Patron
|
39
|
+
* Typhoeus (currently only Typhoeus::Hydra)
|
37
40
|
|
38
41
|
Supported Ruby Interpreters
|
39
42
|
---------------------------
|
@@ -46,7 +49,17 @@ Supported Ruby Interpreters
|
|
46
49
|
|
47
50
|
## Installation
|
48
51
|
|
52
|
+
```bash
|
49
53
|
gem install webmock
|
54
|
+
```
|
55
|
+
or alternatively:
|
56
|
+
|
57
|
+
```ruby
|
58
|
+
# add to your Gemfile
|
59
|
+
group :test do
|
60
|
+
gem "webmock"
|
61
|
+
end
|
62
|
+
```
|
50
63
|
|
51
64
|
### or to install the latest development version from github master
|
52
65
|
|
@@ -58,36 +71,36 @@ Supported Ruby Interpreters
|
|
58
71
|
|
59
72
|
WebMock 2.x has changed somewhat since version 1.x. Changes are listed in [CHANGELOG.md](CHANGELOG.md)
|
60
73
|
|
61
|
-
###
|
74
|
+
### Cucumber
|
62
75
|
|
63
|
-
|
76
|
+
Create a file `features/support/webmock.rb` with the following contents:
|
64
77
|
|
65
78
|
```ruby
|
66
|
-
require 'webmock/
|
79
|
+
require 'webmock/cucumber'
|
67
80
|
```
|
68
81
|
|
69
|
-
###
|
82
|
+
### MiniTest
|
70
83
|
|
71
|
-
Add the following code to `
|
84
|
+
Add the following code to `test/test_helper`:
|
72
85
|
|
73
86
|
```ruby
|
74
|
-
require 'webmock/
|
87
|
+
require 'webmock/minitest'
|
75
88
|
```
|
76
89
|
|
77
|
-
###
|
90
|
+
### RSpec
|
78
91
|
|
79
|
-
Add the following code to `
|
92
|
+
Add the following code to `spec/spec_helper`:
|
80
93
|
|
81
94
|
```ruby
|
82
|
-
require 'webmock/
|
95
|
+
require 'webmock/rspec'
|
83
96
|
```
|
84
97
|
|
85
|
-
###
|
98
|
+
### Test::Unit
|
86
99
|
|
87
|
-
|
100
|
+
Add the following code to `test/test_helper.rb`
|
88
101
|
|
89
102
|
```ruby
|
90
|
-
require 'webmock/
|
103
|
+
require 'webmock/test_unit'
|
91
104
|
```
|
92
105
|
|
93
106
|
### Outside a test framework
|
@@ -101,13 +114,10 @@ include WebMock::API
|
|
101
114
|
WebMock.enable!
|
102
115
|
```
|
103
116
|
|
104
|
-
|
105
|
-
|
106
|
-
|
117
|
+
# Examples
|
107
118
|
|
108
119
|
## Stubbing
|
109
120
|
|
110
|
-
|
111
121
|
### Stubbed request based on uri only and with the default response
|
112
122
|
|
113
123
|
```ruby
|
@@ -1138,6 +1148,7 @@ People who submitted patches and new features or suggested improvements. Many th
|
|
1138
1148
|
* Bruno Sutic
|
1139
1149
|
* Ryan Kerr
|
1140
1150
|
* Adam Harwood
|
1151
|
+
* Ben Koshy
|
1141
1152
|
|
1142
1153
|
For a full list of contributors you can visit the
|
1143
1154
|
[contributors](https://github.com/bblimke/webmock/contributors) page.
|
data/lib/webmock/response.rb
CHANGED
@@ -91,10 +91,10 @@ module WebMock
|
|
91
91
|
|
92
92
|
def ==(other)
|
93
93
|
self.body == other.body &&
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
94
|
+
self.headers === other.headers &&
|
95
|
+
self.status == other.status &&
|
96
|
+
self.exception == other.exception &&
|
97
|
+
self.should_timeout == other.should_timeout
|
98
98
|
end
|
99
99
|
|
100
100
|
private
|
@@ -111,7 +111,13 @@ module WebMock
|
|
111
111
|
valid_types = [Proc, IO, Pathname, String, Array]
|
112
112
|
return if @body.nil?
|
113
113
|
return if valid_types.any? { |c| @body.is_a?(c) }
|
114
|
-
|
114
|
+
|
115
|
+
if @body.class.is_a?(Hash)
|
116
|
+
raise InvalidBody, "must be one of: #{valid_types}, but you've used a #{@body.class}' instead." \
|
117
|
+
"\n What shall we encode it to? try calling .to_json .to_xml instead on the hash instead, or otherwise convert it to a string."
|
118
|
+
else
|
119
|
+
raise InvalidBody, "must be one of: #{valid_types}. '#{@body.class}' given"
|
120
|
+
end
|
115
121
|
end
|
116
122
|
|
117
123
|
def read_raw_response(raw_response)
|
data/lib/webmock/version.rb
CHANGED
data/spec/unit/response_spec.rb
CHANGED
@@ -130,11 +130,15 @@ describe WebMock::Response do
|
|
130
130
|
# Users of webmock commonly make the mistake of stubbing the response
|
131
131
|
# body to return a hash, to prevent this:
|
132
132
|
#
|
133
|
-
it "should error if
|
133
|
+
it "should error if given a non-allowed type: a hash" do
|
134
134
|
expect { WebMock::Response.new(body: Hash.new) }.to \
|
135
135
|
raise_error(WebMock::Response::InvalidBody)
|
136
136
|
end
|
137
137
|
|
138
|
+
it "should error if given a non-allowed type: something that is not a hash" do
|
139
|
+
expect { WebMock::Response.new(body: 123) }.to \
|
140
|
+
raise_error(WebMock::Response::InvalidBody)
|
141
|
+
end
|
138
142
|
end
|
139
143
|
|
140
144
|
describe "from raw response" do
|
@@ -152,12 +156,12 @@ describe WebMock::Response do
|
|
152
156
|
|
153
157
|
it "should read headers" do
|
154
158
|
expect(@response.headers).to eq({
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
159
|
+
"Date"=>"Sat, 23 Jan 2010 01:01:05 GMT",
|
160
|
+
"Content-Type"=>"text/html; charset=UTF-8",
|
161
|
+
"Content-Length"=>"419",
|
162
|
+
"Connection"=>"Keep-Alive",
|
163
|
+
"Accept"=>"image/jpeg, image/png"
|
164
|
+
})
|
161
165
|
end
|
162
166
|
|
163
167
|
it "should read body" do
|
@@ -182,12 +186,12 @@ describe WebMock::Response do
|
|
182
186
|
|
183
187
|
it "should read headers" do
|
184
188
|
expect(@response.headers).to eq({
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
189
|
+
"Date"=>"Sat, 23 Jan 2010 01:01:05 GMT",
|
190
|
+
"Content-Type"=>"text/html; charset=UTF-8",
|
191
|
+
"Content-Length"=>"419",
|
192
|
+
"Connection"=>"Keep-Alive",
|
193
|
+
"Accept"=>"image/jpeg, image/png"
|
194
|
+
})
|
191
195
|
end
|
192
196
|
|
193
197
|
it "should read body" do
|
@@ -234,11 +238,11 @@ describe WebMock::Response do
|
|
234
238
|
it "should evaluate new response with evaluated options" do
|
235
239
|
request_signature = WebMock::RequestSignature.new(:post, "www.example.com", body: "abc", headers: {'A' => 'a'})
|
236
240
|
response = WebMock::DynamicResponse.new(lambda {|request|
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
241
|
+
{
|
242
|
+
body: request.body,
|
243
|
+
headers: request.headers,
|
244
|
+
status: 302
|
245
|
+
}
|
242
246
|
})
|
243
247
|
evaluated_response = response.evaluate(request_signature)
|
244
248
|
expect(evaluated_response.body).to eq("abc")
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: webmock
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.9.
|
4
|
+
version: 3.9.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bartosz Blimke
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-11-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: addressable
|
@@ -407,9 +407,9 @@ licenses:
|
|
407
407
|
- MIT
|
408
408
|
metadata:
|
409
409
|
bug_tracker_uri: https://github.com/bblimke/webmock/issues
|
410
|
-
changelog_uri: https://github.com/bblimke/webmock/blob/v3.9.
|
411
|
-
documentation_uri: https://www.rubydoc.info/gems/webmock/3.9.
|
412
|
-
source_code_uri: https://github.com/bblimke/webmock/tree/v3.9.
|
410
|
+
changelog_uri: https://github.com/bblimke/webmock/blob/v3.9.4/CHANGELOG.md
|
411
|
+
documentation_uri: https://www.rubydoc.info/gems/webmock/3.9.4
|
412
|
+
source_code_uri: https://github.com/bblimke/webmock/tree/v3.9.4
|
413
413
|
wiki_uri: https://github.com/bblimke/webmock/wiki
|
414
414
|
post_install_message:
|
415
415
|
rdoc_options: []
|