webmock 3.9.1 → 3.18.1
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/.github/workflows/CI.yml +38 -0
- data/CHANGELOG.md +180 -6
- data/Gemfile +1 -1
- data/README.md +63 -30
- data/Rakefile +12 -2
- data/lib/webmock/http_lib_adapters/async_http_client_adapter.rb +11 -4
- data/lib/webmock/http_lib_adapters/curb_adapter.rb +2 -2
- data/lib/webmock/http_lib_adapters/em_http_request_adapter.rb +6 -3
- data/lib/webmock/http_lib_adapters/http_rb/client.rb +2 -1
- data/lib/webmock/http_lib_adapters/http_rb/response.rb +17 -3
- data/lib/webmock/http_lib_adapters/http_rb/streamer.rb +4 -2
- data/lib/webmock/http_lib_adapters/http_rb/webmock.rb +6 -2
- data/lib/webmock/http_lib_adapters/httpclient_adapter.rb +23 -6
- data/lib/webmock/http_lib_adapters/manticore_adapter.rb +8 -1
- data/lib/webmock/http_lib_adapters/net_http.rb +29 -115
- data/lib/webmock/request_pattern.rb +30 -8
- data/lib/webmock/request_signature.rb +2 -2
- data/lib/webmock/request_stub.rb +15 -0
- data/lib/webmock/response.rb +19 -13
- data/lib/webmock/stub_registry.rb +24 -9
- data/lib/webmock/test_unit.rb +1 -3
- data/lib/webmock/version.rb +1 -1
- data/lib/webmock/webmock.rb +12 -2
- data/minitest/webmock_spec.rb +1 -1
- data/spec/acceptance/async_http_client/async_http_client_spec.rb +27 -5
- data/spec/acceptance/curb/curb_spec.rb +11 -0
- data/spec/acceptance/em_http_request/em_http_request_spec.rb +57 -1
- data/spec/acceptance/em_http_request/em_http_request_spec_helper.rb +1 -1
- data/spec/acceptance/excon/excon_spec.rb +2 -2
- data/spec/acceptance/manticore/manticore_spec.rb +32 -0
- data/spec/acceptance/net_http/net_http_shared.rb +46 -9
- data/spec/acceptance/net_http/net_http_spec.rb +75 -23
- data/spec/acceptance/net_http/real_net_http_spec.rb +1 -1
- data/spec/acceptance/patron/patron_spec.rb +19 -21
- data/spec/acceptance/patron/patron_spec_helper.rb +2 -2
- data/spec/acceptance/shared/allowing_and_disabling_net_connect.rb +14 -14
- data/spec/acceptance/shared/callbacks.rb +2 -2
- data/spec/acceptance/shared/complex_cross_concern_behaviors.rb +1 -1
- data/spec/acceptance/shared/stubbing_requests.rb +17 -0
- data/spec/unit/request_pattern_spec.rb +82 -46
- data/spec/unit/request_signature_spec.rb +21 -1
- data/spec/unit/request_stub_spec.rb +35 -0
- data/spec/unit/response_spec.rb +51 -19
- data/spec/unit/webmock_spec.rb +54 -0
- data/test/test_webmock.rb +6 -0
- data/webmock.gemspec +6 -5
- metadata +49 -35
- data/.travis.yml +0 -24
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 3a7e964f28dd42787fd854c5fcc87dba4cd61ef214c3dee485d9bd0d71fc1cdd
|
|
4
|
+
data.tar.gz: f6921a9b14ccd71f18b4674aca8d4d24bf377545a4ef8c56862f95cc56b6e8a7
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 80e85d1bb83018bdaab80aed649134757ee8ac591b98e9ccf1b6df10c0d8930db167dd5fd3bb039dd56a955d22c0cc6b1a1227bb88e8f3e56d31d0e1c9d7708e
|
|
7
|
+
data.tar.gz: c67f1f8486d6ee932bd9d01dff2bfcec35d9c3e3ed937e50e1f56d34f664ca11db4c9399c51e82da9316245c1d4727c726b9e307646aef80477764609ecf95ee
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches:
|
|
6
|
+
- master
|
|
7
|
+
pull_request:
|
|
8
|
+
|
|
9
|
+
jobs:
|
|
10
|
+
build:
|
|
11
|
+
runs-on: ubuntu-latest
|
|
12
|
+
strategy:
|
|
13
|
+
fail-fast: false
|
|
14
|
+
matrix:
|
|
15
|
+
ruby:
|
|
16
|
+
- head
|
|
17
|
+
- '3.1'
|
|
18
|
+
- '3.0'
|
|
19
|
+
- '2.7'
|
|
20
|
+
- '2.6'
|
|
21
|
+
- '2.5'
|
|
22
|
+
- jruby
|
|
23
|
+
continue-on-error: ${{ matrix.ruby == 'head' }}
|
|
24
|
+
name: Ruby ${{ matrix.ruby }}
|
|
25
|
+
env:
|
|
26
|
+
JRUBY_OPTS: "--debug"
|
|
27
|
+
steps:
|
|
28
|
+
- uses: actions/checkout@v2
|
|
29
|
+
- name: Install Apt Packages
|
|
30
|
+
run: |
|
|
31
|
+
sudo apt-get install libcurl4-openssl-dev -y
|
|
32
|
+
- uses: ruby/setup-ruby@v1
|
|
33
|
+
continue-on-error: true
|
|
34
|
+
with:
|
|
35
|
+
ruby-version: ${{ matrix.ruby }}
|
|
36
|
+
bundler-cache: true
|
|
37
|
+
- run: |
|
|
38
|
+
bundle exec rake
|
data/CHANGELOG.md
CHANGED
|
@@ -1,8 +1,182 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
# 3.18.1
|
|
4
|
+
|
|
5
|
+
* Reverted simplified connection handing in Net::HTTP adapter due to https://github.com/bblimke/webmock/issues/999
|
|
6
|
+
|
|
7
|
+
# 3.18.0
|
|
8
|
+
|
|
9
|
+
* Net::BufferedIO is not replaced anymore.
|
|
10
|
+
|
|
11
|
+
Thanks to [Ray Zane](https://github.com/rzane)
|
|
12
|
+
|
|
13
|
+
* Simplified connection handing in Net::HTTP adapter.
|
|
14
|
+
|
|
15
|
+
Thanks to [Ray Zane](https://github.com/rzane)
|
|
16
|
+
|
|
17
|
+
# 3.17.1
|
|
18
|
+
|
|
19
|
+
* Fixed Syntax Error
|
|
20
|
+
|
|
21
|
+
Thanks to [Mark Spangler](https://github.com/mspangler)
|
|
22
|
+
|
|
23
|
+
# 3.17.0
|
|
24
|
+
|
|
25
|
+
* Minimum required Ruby version is 2.3
|
|
26
|
+
|
|
27
|
+
Thanks to [Go Sueyoshi](https://github.com/sue445)
|
|
28
|
+
|
|
29
|
+
* When using Net::HTTP, stubbed socket StubSocket#close and StubSocket#closed? behave more like the real sockets.
|
|
30
|
+
|
|
31
|
+
Thanks to [Ray Zane](https://github.com/rzane)
|
|
32
|
+
|
|
33
|
+
* Added `peeraddr`, `ssl_version` and `cipher` methods to stubbed sockets used by Net::HTTP.
|
|
34
|
+
|
|
35
|
+
Thanks to [Ray Zane](https://github.com/rzane)
|
|
36
|
+
|
|
37
|
+
* Added support for matching top-level array in JSON request body.
|
|
38
|
+
|
|
39
|
+
E.g.
|
|
40
|
+
|
|
41
|
+
````
|
|
42
|
+
stub_request(:post, 'www.example.com').with(body: [{a: 1}])
|
|
43
|
+
````
|
|
44
|
+
|
|
45
|
+
Thanks to [Cedric Sohrauer](https://github.com/cedrics)
|
|
46
|
+
|
|
47
|
+
# 3.16.2
|
|
48
|
+
|
|
49
|
+
* Minimum required Ruby version is 2.0.
|
|
50
|
+
|
|
51
|
+
# 3.16.0 (yanked)
|
|
52
|
+
|
|
53
|
+
* Fix leaky file descriptors and reuse socket for persistent connections.
|
|
54
|
+
|
|
55
|
+
Thanks to [Ray Zane](https://github.com/rzane)
|
|
56
|
+
|
|
57
|
+
* Allow specifying for what URIs or hosts, Net::HTTP should connect on start.
|
|
58
|
+
|
|
59
|
+
Thanks to [Ray Zane](https://github.com/rzane)
|
|
60
|
+
|
|
61
|
+
# 3.15.2
|
|
62
|
+
|
|
63
|
+
* Minimum required Ruby version is 2.0.
|
|
64
|
+
|
|
65
|
+
# 3.15.0 (yanked)
|
|
66
|
+
|
|
67
|
+
* fixed async-http adapter on Windows
|
|
68
|
+
|
|
69
|
+
Thanks to [Pavel Rosický](https://github.com/ahorek)
|
|
70
|
+
|
|
71
|
+
* Support for http.rb >= 5.0.2
|
|
72
|
+
|
|
73
|
+
Thanks to [ojab](https://github.com/ojab)
|
|
74
|
+
|
|
75
|
+
* Curb adapter supports headers with `:` character in the header value
|
|
76
|
+
|
|
77
|
+
Thanks to [Giorgio Gambino](https://github.com/mrbuzz)
|
|
78
|
+
|
|
79
|
+
* Support for matching body of JSON or application/x-www-form-urlencoded requests with content type header including charset.
|
|
80
|
+
|
|
81
|
+
Thanks to [Timmitry](https://github.com/Timmitry)
|
|
82
|
+
|
|
83
|
+
* Prevent double-wrapping http.rb features on non-stubbed requests
|
|
84
|
+
|
|
85
|
+
Thanks to [Michael Fairley](https://github.com/michaelfairley)
|
|
86
|
+
|
|
87
|
+
# 3.14.0
|
|
88
|
+
|
|
89
|
+
* Bump Addressable from 2.3.6 to 2.8.0
|
|
90
|
+
|
|
91
|
+
Thanks to [Eduardo Hernandez](https://github.com/EduardoGHdez)
|
|
92
|
+
|
|
93
|
+
# 3.13.0
|
|
94
|
+
|
|
95
|
+
* Support http.rb 5.x
|
|
96
|
+
|
|
97
|
+
Thanks to [Will Storey](https://github.com/horgh)
|
|
98
|
+
|
|
99
|
+
# 3.12.2
|
|
100
|
+
|
|
101
|
+
* Fixed em-http-request adapter to avoid calling middleware twice.
|
|
102
|
+
|
|
103
|
+
Thanks to [Alex Vondrak](https://github.com/ajvondrak)
|
|
104
|
+
|
|
105
|
+
# 3.12.1
|
|
106
|
+
|
|
107
|
+
* Fixed handling of URIs with IPv6 addresses with square brackets when in Net::HTTP adapter.
|
|
108
|
+
|
|
109
|
+
Thanks to [Johanna Hartmann](https://github.com/JohannaHartmann)
|
|
110
|
+
|
|
111
|
+
# 3.12.0
|
|
112
|
+
|
|
113
|
+
* Added support for handling custom JSON and XML content types e.g. 'application/vnd.api+json'
|
|
114
|
+
|
|
115
|
+
# 3.11.3
|
|
116
|
+
|
|
117
|
+
* Fixed async-http adapter to only considered requests as real if they are real.
|
|
118
|
+
|
|
119
|
+
Thanks to Thanks to [Tony Schneider](https://github.com/tonywok) and [Samuel Williams](https://github.com/ioquatix)
|
|
120
|
+
|
|
121
|
+
# 3.11.2
|
|
122
|
+
|
|
123
|
+
* Fix for Manticore streaming mode
|
|
124
|
+
|
|
125
|
+
Thanks to [Oleksiy Kovyrin](https://github.com/kovyrin)
|
|
126
|
+
|
|
127
|
+
# 3.11.1
|
|
128
|
+
|
|
129
|
+
* Compatibility with async-http 0.54+
|
|
130
|
+
|
|
131
|
+
Thanks to [Jun Jiang](https://github.com/jasl)
|
|
132
|
+
|
|
133
|
+
# 3.11.0
|
|
134
|
+
|
|
135
|
+
* Added support for `features` in http.rb adapter.
|
|
136
|
+
|
|
137
|
+
Thanks to [Carl (ce07c3)](https://github.com/ce07c3)
|
|
138
|
+
|
|
139
|
+
# 3.10.0
|
|
140
|
+
|
|
141
|
+
* Added option to global stubs to have lower priority than local stubs.
|
|
142
|
+
|
|
143
|
+
WebMock.globally_stub_request(:after_local_stubs) do
|
|
144
|
+
{ body: "global stub body" }
|
|
145
|
+
end
|
|
146
|
+
|
|
147
|
+
stub_request(:get, "www.example.com").to_return(body: 'non-global stub body')
|
|
148
|
+
|
|
149
|
+
expect(http_request(:get, "http://www.example.com/").body).to eq("non-global stub body")
|
|
150
|
+
|
|
151
|
+
Thanks to [Marek Kasztelnik](https://github.com/mkasztelnik)
|
|
152
|
+
|
|
153
|
+
# 3.9.5
|
|
154
|
+
|
|
155
|
+
* Prevent overwriting `teardown` method in Test::Unit
|
|
156
|
+
|
|
157
|
+
Thanks to [Jesse Bowes](https://github.com/jessebs)
|
|
158
|
+
|
|
159
|
+
# 3.9.4
|
|
160
|
+
|
|
161
|
+
* More intuitive error message when stubbed response body was provided as Hash
|
|
162
|
+
|
|
163
|
+
Thanks to [Ben Koshy](https://github.com/BKSpurgeon)
|
|
164
|
+
|
|
165
|
+
# 3.9.3
|
|
166
|
+
|
|
167
|
+
* Make httpclient_adapter thread-safe
|
|
168
|
+
|
|
169
|
+
Thanks to [Adam Harwood](https://github.com/adam-harwood)
|
|
170
|
+
|
|
171
|
+
# 3.9.2
|
|
172
|
+
|
|
173
|
+
* Made global stubs thread-safe
|
|
174
|
+
|
|
175
|
+
Thanks to [Adam Harwood](https://github.com/adam-harwood)
|
|
176
|
+
|
|
3
177
|
# 3.9.1
|
|
4
178
|
|
|
5
|
-
Fixed support for passing `URI` objects as second argument of `stub_request`
|
|
179
|
+
* Fixed support for passing `URI` objects as second argument of `stub_request`
|
|
6
180
|
|
|
7
181
|
Thanks to [Ryan Kerr](https://github.com/leboshi)
|
|
8
182
|
|
|
@@ -28,11 +202,11 @@
|
|
|
28
202
|
|
|
29
203
|
* Fixed async-http adapter which caused Async::HTTP::Client or Async::HTTP::Internet to hang and never return a response.
|
|
30
204
|
|
|
31
|
-
Thanks to
|
|
205
|
+
Thanks to [Bruno Sutic](https://github.com/bruno-) and [Samuel Williams](https://github.com/ioquatix)
|
|
32
206
|
|
|
33
207
|
* Fixed warning when using async-http adapter
|
|
34
208
|
|
|
35
|
-
Thanks to
|
|
209
|
+
Thanks to [Bruno Sutic](https://github.com/bruno-)
|
|
36
210
|
|
|
37
211
|
* Dropped support for Ruby 2.3 - EOL date: 2019-03-31
|
|
38
212
|
|
|
@@ -40,7 +214,7 @@
|
|
|
40
214
|
|
|
41
215
|
* Handling matching of Addressable::Template patterns that have an ip address without port and patterns that have ip address and don’t have schema and path.
|
|
42
216
|
|
|
43
|
-
Thanks to
|
|
217
|
+
Thanks to [Rafael França](https://github.com/rafaelfranca) and [guppy0356](https://github.com/guppy0356)
|
|
44
218
|
|
|
45
219
|
## 3.8.3
|
|
46
220
|
|
|
@@ -515,9 +689,9 @@
|
|
|
515
689
|
* `WebMock.disable_net_connect` accepts `:allow` option with an object that responds to `#call`, receiving a `URI` object and returning a boolean:
|
|
516
690
|
|
|
517
691
|
|
|
518
|
-
|
|
692
|
+
denylist = ['google.com', 'facebook.com', 'apple.com']
|
|
519
693
|
allowed_sites = lambda{|uri|
|
|
520
|
-
|
|
694
|
+
denylist.none?{|site| uri.host.include?(site) }
|
|
521
695
|
}
|
|
522
696
|
WebMock.disable_net_connect!(:allow => allowed_sites)
|
|
523
697
|
|
data/Gemfile
CHANGED
data/README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
WebMock
|
|
2
2
|
=======
|
|
3
3
|
[](http://badge.fury.io/rb/webmock)
|
|
4
|
-
[](https://github.com/bblimke/webmock/actions)
|
|
5
5
|
[](https://codeclimate.com/github/bblimke/webmock)
|
|
6
6
|
[](https://github.com/markets/awesome-ruby)
|
|
7
7
|
[](http://inch-ci.org/github/bblimke/webmock)
|
|
@@ -24,16 +24,19 @@ Features
|
|
|
24
24
|
Supported HTTP libraries
|
|
25
25
|
------------------------
|
|
26
26
|
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
27
|
+
* [Async::HTTP::Client](https://github.com/socketry/async-http)
|
|
28
|
+
* [Curb](https://github.com/taf2/curb) (currently only Curb::Easy)
|
|
29
|
+
* [EM-HTTP-Request](https://github.com/igrigorik/em-http-request)
|
|
30
|
+
* [Excon](https://github.com/excon/excon)
|
|
31
|
+
* [HTTPClient](https://github.com/nahi/httpclient)
|
|
32
|
+
* [HTTP Gem (also known as http.rb)](https://github.com/httprb/http)
|
|
33
|
+
* [httpx](https://honeyryderchuck.gitlab.io/httpx/wiki/Webmock-Adapter)
|
|
34
|
+
* [Manticore](https://github.com/cheald/manticore)
|
|
35
|
+
* [Net::HTTP](https://ruby-doc.org/stdlib-2.7.0/libdoc/net/http/rdoc/Net/HTTP.html) and other libraries based on Net::HTTP, e.g.:
|
|
36
|
+
* [HTTParty](https://github.com/jnunemaker/httparty)
|
|
37
|
+
* [REST Client](https://github.com/rest-client/rest-client)
|
|
38
|
+
* [Patron](https://github.com/toland/patron)
|
|
39
|
+
* [Typhoeus](https://github.com/typhoeus/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
|
|
@@ -540,9 +550,9 @@ RestClient.get('sample.org', '/bar') # ===> Failure
|
|
|
540
550
|
With an object that responds to `#call`, receiving a `URI` object and returning a boolean:
|
|
541
551
|
|
|
542
552
|
```ruby
|
|
543
|
-
|
|
553
|
+
denylist = ['google.com', 'facebook.com', 'apple.com']
|
|
544
554
|
allowed_sites = lambda{|uri|
|
|
545
|
-
|
|
555
|
+
denylist.none?{|site| uri.host.include?(site) }
|
|
546
556
|
}
|
|
547
557
|
WebMock.disable_net_connect!(allow: allowed_sites)
|
|
548
558
|
|
|
@@ -1137,13 +1147,36 @@ People who submitted patches and new features or suggested improvements. Many th
|
|
|
1137
1147
|
* Lucas Uyezu
|
|
1138
1148
|
* Bruno Sutic
|
|
1139
1149
|
* Ryan Kerr
|
|
1150
|
+
* Adam Harwood
|
|
1151
|
+
* Ben Koshy
|
|
1152
|
+
* Jesse Bowes
|
|
1153
|
+
* Marek Kasztelnik
|
|
1154
|
+
* ce07c3
|
|
1155
|
+
* Jun Jiang
|
|
1156
|
+
* Oleksiy Kovyrin
|
|
1157
|
+
* Matt Larraz
|
|
1158
|
+
* Tony Schneider
|
|
1159
|
+
* Niklas Hösl
|
|
1160
|
+
* Johanna Hartmann
|
|
1161
|
+
* Alex Vondrak
|
|
1162
|
+
* Will Storey
|
|
1163
|
+
* Eduardo Hernandez
|
|
1164
|
+
* ojab
|
|
1165
|
+
* Giorgio Gambino
|
|
1166
|
+
* Timmitry
|
|
1167
|
+
* Michael Fairley
|
|
1168
|
+
* Ray Zane
|
|
1169
|
+
* Go Sueyoshi
|
|
1170
|
+
* Cedric Sohrauer
|
|
1171
|
+
* Akira Matsuda
|
|
1172
|
+
* Mark Spangler
|
|
1140
1173
|
|
|
1141
1174
|
For a full list of contributors you can visit the
|
|
1142
1175
|
[contributors](https://github.com/bblimke/webmock/contributors) page.
|
|
1143
1176
|
|
|
1144
1177
|
## Background
|
|
1145
1178
|
|
|
1146
|
-
Thank you Fakeweb! This library was inspired by [FakeWeb](
|
|
1179
|
+
Thank you Fakeweb! This library was inspired by [FakeWeb](https://github.com/chrisk/fakeweb).
|
|
1147
1180
|
I imported some solutions from that project to WebMock. I also copied some code i.e Net:HTTP adapter.
|
|
1148
1181
|
Fakeweb architecture unfortunately didn't allow me to extend it easily with the features I needed.
|
|
1149
1182
|
I also preferred some things to work differently i.e request stub precedence.
|
data/Rakefile
CHANGED
|
@@ -3,24 +3,34 @@ Bundler::GemHelper.install_tasks
|
|
|
3
3
|
|
|
4
4
|
require "rspec/core/rake_task"
|
|
5
5
|
RSpec::Core::RakeTask.new(:spec) do |t|
|
|
6
|
-
t.rspec_opts = [
|
|
6
|
+
t.rspec_opts = %w[
|
|
7
|
+
--force-color
|
|
8
|
+
--format progress
|
|
9
|
+
--require ./spec/spec_helper.rb
|
|
10
|
+
]
|
|
7
11
|
t.pattern = 'spec/**/*_spec.rb'
|
|
8
12
|
end
|
|
9
13
|
|
|
10
14
|
RSpec::Core::RakeTask.new(:spec_http_without_webmock) do |t|
|
|
11
|
-
t.rspec_opts = [
|
|
15
|
+
t.rspec_opts = %w[
|
|
16
|
+
--force-color
|
|
17
|
+
--format progress
|
|
18
|
+
--require ./spec/acceptance/net_http/real_net_http_spec.rb
|
|
19
|
+
]
|
|
12
20
|
t.pattern = 'spec/acceptance/net_http/real_net_http_spec.rb'
|
|
13
21
|
end
|
|
14
22
|
|
|
15
23
|
require 'rake/testtask'
|
|
16
24
|
Rake::TestTask.new(:test) do |test|
|
|
17
25
|
test.test_files = FileList["test/**/*.rb"].exclude("test/test_helper.rb")
|
|
26
|
+
test.options = "--use-color"
|
|
18
27
|
test.verbose = false
|
|
19
28
|
test.warning = false
|
|
20
29
|
end
|
|
21
30
|
|
|
22
31
|
Rake::TestTask.new(:minitest) do |test|
|
|
23
32
|
test.test_files = FileList["minitest/**/*.rb"].exclude("test/test_helper.rb")
|
|
33
|
+
test.options = "--pride"
|
|
24
34
|
test.verbose = false
|
|
25
35
|
test.warning = false
|
|
26
36
|
end
|
|
@@ -40,8 +40,8 @@ if defined?(Async::HTTP)
|
|
|
40
40
|
)
|
|
41
41
|
webmock_endpoint = WebMockEndpoint.new(scheme, authority, protocol)
|
|
42
42
|
|
|
43
|
-
@network_client = WebMockClient.new(endpoint,
|
|
44
|
-
@webmock_client = WebMockClient.new(webmock_endpoint,
|
|
43
|
+
@network_client = WebMockClient.new(endpoint, **options)
|
|
44
|
+
@webmock_client = WebMockClient.new(webmock_endpoint, **options)
|
|
45
45
|
|
|
46
46
|
@scheme = scheme
|
|
47
47
|
@authority = authority
|
|
@@ -55,6 +55,7 @@ if defined?(Async::HTTP)
|
|
|
55
55
|
WebMock::RequestRegistry.instance.requested_signatures.put(request_signature)
|
|
56
56
|
webmock_response = WebMock::StubRegistry.instance.response_for_request(request_signature)
|
|
57
57
|
net_connect_allowed = WebMock.net_connect_allowed?(request_signature.uri)
|
|
58
|
+
real_request = false
|
|
58
59
|
|
|
59
60
|
if webmock_response
|
|
60
61
|
webmock_response.raise_error_if_any
|
|
@@ -63,6 +64,7 @@ if defined?(Async::HTTP)
|
|
|
63
64
|
response = @webmock_client.call(request)
|
|
64
65
|
elsif net_connect_allowed
|
|
65
66
|
response = @network_client.call(request)
|
|
67
|
+
real_request = true
|
|
66
68
|
else
|
|
67
69
|
raise WebMock::NetConnectNotAllowedError.new(request_signature) unless webmock_response
|
|
68
70
|
end
|
|
@@ -72,7 +74,7 @@ if defined?(Async::HTTP)
|
|
|
72
74
|
WebMock::CallbackRegistry.invoke_callbacks(
|
|
73
75
|
{
|
|
74
76
|
lib: :async_http_client,
|
|
75
|
-
real_request:
|
|
77
|
+
real_request: real_request
|
|
76
78
|
},
|
|
77
79
|
request_signature,
|
|
78
80
|
webmock_response
|
|
@@ -149,7 +151,12 @@ if defined?(Async::HTTP)
|
|
|
149
151
|
private
|
|
150
152
|
|
|
151
153
|
def create_connected_sockets
|
|
152
|
-
|
|
154
|
+
pair = begin
|
|
155
|
+
Async::IO::Socket.pair(Socket::AF_UNIX, Socket::SOCK_STREAM)
|
|
156
|
+
rescue Errno::EAFNOSUPPORT
|
|
157
|
+
Async::IO::Socket.pair(Socket::AF_INET, Socket::SOCK_STREAM)
|
|
158
|
+
end
|
|
159
|
+
pair.tap do |sockets|
|
|
153
160
|
sockets.each do |socket|
|
|
154
161
|
socket.instance_variable_set :@alpn_protocol, nil
|
|
155
162
|
socket.instance_eval do
|
|
@@ -5,7 +5,7 @@ rescue LoadError
|
|
|
5
5
|
end
|
|
6
6
|
|
|
7
7
|
if defined?(Curl)
|
|
8
|
-
WebMock::VersionChecker.new('Curb', Curl::CURB_VERSION, '0.7.16', '0.
|
|
8
|
+
WebMock::VersionChecker.new('Curb', Curl::CURB_VERSION, '0.7.16', '1.0.1', ['0.8.7']).check_version!
|
|
9
9
|
|
|
10
10
|
module WebMock
|
|
11
11
|
module HttpLibAdapters
|
|
@@ -128,7 +128,7 @@ if defined?(Curl)
|
|
|
128
128
|
def headers_as_hash(headers)
|
|
129
129
|
if headers.is_a?(Array)
|
|
130
130
|
headers.inject({}) {|hash, header|
|
|
131
|
-
name, value = header.split(":").map(&:strip)
|
|
131
|
+
name, value = header.split(":", 2).map(&:strip)
|
|
132
132
|
hash[name] = value
|
|
133
133
|
hash
|
|
134
134
|
}
|
|
@@ -99,6 +99,11 @@ if defined?(EventMachine::HttpClient)
|
|
|
99
99
|
end
|
|
100
100
|
end
|
|
101
101
|
|
|
102
|
+
def connection_completed
|
|
103
|
+
@state = :response_header
|
|
104
|
+
send_request(request_signature.headers, request_signature.body)
|
|
105
|
+
end
|
|
106
|
+
|
|
102
107
|
def send_request(head, body)
|
|
103
108
|
WebMock::RequestRegistry.instance.requested_signatures.put(request_signature)
|
|
104
109
|
|
|
@@ -164,7 +169,7 @@ if defined?(EventMachine::HttpClient)
|
|
|
164
169
|
end
|
|
165
170
|
|
|
166
171
|
def build_request_signature
|
|
167
|
-
headers, body =
|
|
172
|
+
headers, body = build_request, @req.body
|
|
168
173
|
|
|
169
174
|
@conn.middleware.select {|m| m.respond_to?(:request) }.each do |m|
|
|
170
175
|
headers, body = m.request(self, headers, body)
|
|
@@ -178,8 +183,6 @@ if defined?(EventMachine::HttpClient)
|
|
|
178
183
|
|
|
179
184
|
body = form_encode_body(body) if body.is_a?(Hash)
|
|
180
185
|
|
|
181
|
-
headers = @req.headers
|
|
182
|
-
|
|
183
186
|
if headers['authorization'] && headers['authorization'].is_a?(Array)
|
|
184
187
|
headers['Authorization'] = WebMock::Util::Headers.basic_auth_header(headers.delete('authorization'))
|
|
185
188
|
end
|
|
@@ -4,7 +4,8 @@ module HTTP
|
|
|
4
4
|
|
|
5
5
|
def perform(request, options)
|
|
6
6
|
return __perform__(request, options) unless webmock_enabled?
|
|
7
|
-
|
|
7
|
+
|
|
8
|
+
WebMockPerform.new(request, options) { __perform__(request, options) }.exec
|
|
8
9
|
end
|
|
9
10
|
|
|
10
11
|
def webmock_enabled?
|
|
@@ -11,7 +11,7 @@ module HTTP
|
|
|
11
11
|
end
|
|
12
12
|
|
|
13
13
|
class << self
|
|
14
|
-
def from_webmock(webmock_response, request_signature = nil)
|
|
14
|
+
def from_webmock(request, webmock_response, request_signature = nil)
|
|
15
15
|
status = Status.new(webmock_response.status.first)
|
|
16
16
|
headers = webmock_response.headers || {}
|
|
17
17
|
uri = normalize_uri(request_signature && request_signature.uri)
|
|
@@ -24,17 +24,31 @@ module HTTP
|
|
|
24
24
|
elsif HTTP::VERSION < "3.0.0"
|
|
25
25
|
Body.new(Streamer.new(webmock_response.body), webmock_response.body.encoding)
|
|
26
26
|
else
|
|
27
|
-
Body.new(
|
|
27
|
+
Body.new(
|
|
28
|
+
Streamer.new(webmock_response.body, encoding: webmock_response.body.encoding),
|
|
29
|
+
encoding: webmock_response.body.encoding
|
|
30
|
+
)
|
|
28
31
|
end
|
|
29
32
|
|
|
30
33
|
return new(status, "1.1", headers, body, uri) if HTTP::VERSION < "1.0.0"
|
|
31
34
|
|
|
35
|
+
# 5.0.0 had a breaking change to require request instead of uri.
|
|
36
|
+
if HTTP::VERSION < '5.0.0'
|
|
37
|
+
return new({
|
|
38
|
+
status: status,
|
|
39
|
+
version: "1.1",
|
|
40
|
+
headers: headers,
|
|
41
|
+
body: body,
|
|
42
|
+
uri: uri
|
|
43
|
+
})
|
|
44
|
+
end
|
|
45
|
+
|
|
32
46
|
new({
|
|
33
47
|
status: status,
|
|
34
48
|
version: "1.1",
|
|
35
49
|
headers: headers,
|
|
36
50
|
body: body,
|
|
37
|
-
|
|
51
|
+
request: request,
|
|
38
52
|
})
|
|
39
53
|
end
|
|
40
54
|
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
module HTTP
|
|
2
2
|
class Response
|
|
3
3
|
class Streamer
|
|
4
|
-
def initialize(str)
|
|
4
|
+
def initialize(str, encoding: Encoding::BINARY)
|
|
5
5
|
@io = StringIO.new str
|
|
6
|
+
@encoding = encoding
|
|
6
7
|
end
|
|
7
8
|
|
|
8
9
|
def readpartial(size = nil, outbuf = nil)
|
|
@@ -14,7 +15,8 @@ module HTTP
|
|
|
14
15
|
end
|
|
15
16
|
end
|
|
16
17
|
|
|
17
|
-
@io.read size, outbuf
|
|
18
|
+
chunk = @io.read size, outbuf
|
|
19
|
+
chunk.force_encoding(@encoding) if chunk
|
|
18
20
|
end
|
|
19
21
|
|
|
20
22
|
def close
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
module HTTP
|
|
2
2
|
class WebMockPerform
|
|
3
|
-
def initialize(request, &perform)
|
|
3
|
+
def initialize(request, options, &perform)
|
|
4
4
|
@request = request
|
|
5
|
+
@options = options
|
|
5
6
|
@perform = perform
|
|
6
7
|
@request_signature = nil
|
|
7
8
|
end
|
|
@@ -38,7 +39,10 @@ module HTTP
|
|
|
38
39
|
webmock_response.raise_error_if_any
|
|
39
40
|
|
|
40
41
|
invoke_callbacks(webmock_response, real_request: false)
|
|
41
|
-
::HTTP::Response.from_webmock webmock_response, request_signature
|
|
42
|
+
response = ::HTTP::Response.from_webmock @request, webmock_response, request_signature
|
|
43
|
+
|
|
44
|
+
@options.features.each { |_name, feature| response = feature.wrap_response(response) }
|
|
45
|
+
response
|
|
42
46
|
end
|
|
43
47
|
|
|
44
48
|
def raise_timeout_error
|