webmock 3.6.2 → 3.14.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/CI.yml +37 -0
  3. data/CHANGELOG.md +214 -0
  4. data/Gemfile +1 -1
  5. data/README.md +85 -32
  6. data/Rakefile +12 -2
  7. data/lib/webmock/http_lib_adapters/async_http_client_adapter.rb +216 -0
  8. data/lib/webmock/http_lib_adapters/curb_adapter.rb +4 -0
  9. data/lib/webmock/http_lib_adapters/em_http_request_adapter.rb +7 -4
  10. data/lib/webmock/http_lib_adapters/excon_adapter.rb +3 -0
  11. data/lib/webmock/http_lib_adapters/http_rb/client.rb +4 -1
  12. data/lib/webmock/http_lib_adapters/http_rb/response.rb +24 -3
  13. data/lib/webmock/http_lib_adapters/http_rb/streamer.rb +2 -2
  14. data/lib/webmock/http_lib_adapters/http_rb/webmock.rb +1 -1
  15. data/lib/webmock/http_lib_adapters/httpclient_adapter.rb +23 -6
  16. data/lib/webmock/http_lib_adapters/manticore_adapter.rb +24 -9
  17. data/lib/webmock/http_lib_adapters/net_http.rb +43 -19
  18. data/lib/webmock/request_pattern.rb +82 -47
  19. data/lib/webmock/response.rb +11 -5
  20. data/lib/webmock/rspec.rb +2 -1
  21. data/lib/webmock/stub_registry.rb +26 -11
  22. data/lib/webmock/test_unit.rb +1 -3
  23. data/lib/webmock/util/uri.rb +5 -4
  24. data/lib/webmock/version.rb +1 -1
  25. data/lib/webmock/webmock.rb +5 -3
  26. data/lib/webmock.rb +1 -0
  27. data/spec/acceptance/async_http_client/async_http_client_spec.rb +375 -0
  28. data/spec/acceptance/async_http_client/async_http_client_spec_helper.rb +73 -0
  29. data/spec/acceptance/curb/curb_spec.rb +12 -5
  30. data/spec/acceptance/em_http_request/em_http_request_spec.rb +56 -0
  31. data/spec/acceptance/em_http_request/em_http_request_spec_helper.rb +1 -1
  32. data/spec/acceptance/excon/excon_spec_helper.rb +2 -0
  33. data/spec/acceptance/http_rb/http_rb_spec.rb +11 -0
  34. data/spec/acceptance/manticore/manticore_spec.rb +51 -0
  35. data/spec/acceptance/net_http/net_http_spec.rb +38 -0
  36. data/spec/acceptance/patron/patron_spec_helper.rb +2 -2
  37. data/spec/acceptance/shared/callbacks.rb +2 -1
  38. data/spec/acceptance/shared/returning_declared_responses.rb +36 -15
  39. data/spec/acceptance/shared/stubbing_requests.rb +35 -0
  40. data/spec/unit/request_pattern_spec.rb +183 -48
  41. data/spec/unit/response_spec.rb +22 -18
  42. data/spec/unit/util/uri_spec.rb +10 -0
  43. data/spec/unit/webmock_spec.rb +52 -11
  44. data/test/test_webmock.rb +6 -0
  45. data/webmock.gemspec +11 -1
  46. metadata +48 -10
  47. data/.travis.yml +0 -19
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9d54455d6752d60f630b108721f21ad51f4d2e648cf1fe492f72cce5d0e3bd66
4
- data.tar.gz: 937d29ecd33fe244fe5f9749140d94c4ea68134b8afdcdd44a4ec41d5562df10
3
+ metadata.gz: a8f150fbeccca419468dfebe632e3b5d365cb8c2df9a5e2a31e65591298786fb
4
+ data.tar.gz: d92950bc5ae3510e599c40545f3e7a0ebaafa54a698f79a3c82243e240d35948
5
5
  SHA512:
6
- metadata.gz: 46ffed006b40f5d04d66ca5c3997f5874801e55d50a6580c1f3686a1c06a2fd4f69b4ab23c07f4828bdf01ace8749a0a7874a92db04780e621333a731bf89baf
7
- data.tar.gz: 3d265897b59b5adcf8cf1954c5656160eb8bfeeb583d3abdcf9883b61b88b1b09ed050da8f45f582a190a86beb8d1bb809d55b39d89ac9ab4ed1681bc05ebeaa
6
+ metadata.gz: f58d569f7c633d758cee725e5dafb39edacb74e0017ba9c29de0cad8fe16d1f7740cc30847a9f129f6571232d2ca8172d7fb76a1eb3383e31ee8371472f141f9
7
+ data.tar.gz: 52191c4e12ac3bf79b575f36d58823ea37ab17f83c7a62602889f361eafadabfa4b0b8ffc1f466eee6de53ea77578fc0149a60e14abdd8a7459b651afbeb85d0
@@ -0,0 +1,37 @@
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.0'
18
+ - '2.7'
19
+ - '2.6'
20
+ - '2.5'
21
+ - jruby
22
+ continue-on-error: ${{ matrix.ruby == 'head' }}
23
+ name: Ruby ${{ matrix.ruby }}
24
+ env:
25
+ JRUBY_OPTS: "--debug"
26
+ steps:
27
+ - uses: actions/checkout@v2
28
+ - name: Install Apt Packages
29
+ run: |
30
+ sudo apt-get install libcurl4-openssl-dev -y
31
+ - uses: ruby/setup-ruby@v1
32
+ continue-on-error: true
33
+ with:
34
+ ruby-version: ${{ matrix.ruby }}
35
+ bundler-cache: true
36
+ - run: |
37
+ bundle exec rake
data/CHANGELOG.md CHANGED
@@ -1,5 +1,219 @@
1
1
  # Changelog
2
2
 
3
+ # 3.14.0
4
+
5
+ * Bump Addressable from 2.3.6 to 2.8.0
6
+
7
+ Thanks to [Eduardo Hernandez](https://github.com/EduardoGHdez)
8
+
9
+ # 3.13.0
10
+
11
+ * Support http.rb 5.x
12
+
13
+ Thanks to [Will Storey](https://github.com/horgh)
14
+
15
+ # 3.12.2
16
+
17
+ * Fixed em-http-request adapter to avoid calling middleware twice.
18
+
19
+ Thanks to [Alex Vondrak](https://github.com/ajvondrak)
20
+
21
+ # 3.12.1
22
+
23
+ * Fixed handling of URIs with IPv6 addresses with square brackets when in Net::HTTP adapter.
24
+
25
+ Thanks to [Johanna Hartmann](https://github.com/JohannaHartmann)
26
+
27
+ # 3.12.0
28
+
29
+ * Added support for handling custom JSON and XML content types e.g. 'application/vnd.api+json'
30
+
31
+ # 3.11.3
32
+
33
+ * Fixed async-http adapter to only considered requests as real if they are real.
34
+
35
+ Thanks to Thanks to [Tony Schneider](https://github.com/tonywok) and [Samuel Williams](https://github.com/ioquatix)
36
+
37
+ # 3.11.2
38
+
39
+ * Fix for Manticore streaming mode
40
+
41
+ Thanks to [Oleksiy Kovyrin](https://github.com/kovyrin)
42
+
43
+ # 3.11.1
44
+
45
+ * Compatibility with async-http 0.54+
46
+
47
+ Thanks to [Jun Jiang](https://github.com/jasl)
48
+
49
+ # 3.11.0
50
+
51
+ * Added support for `features` in http.rb adapter.
52
+
53
+ Thanks to [Carl (ce07c3)](https://github.com/ce07c3)
54
+
55
+ # 3.10.0
56
+
57
+ * Added option to global stubs to have lower priority than local stubs.
58
+
59
+ WebMock.globally_stub_request(:after_local_stubs) do
60
+ { body: "global stub body" }
61
+ end
62
+
63
+ stub_request(:get, "www.example.com").to_return(body: 'non-global stub body')
64
+
65
+ expect(http_request(:get, "http://www.example.com/").body).to eq("non-global stub body")
66
+
67
+ Thanks to [Marek Kasztelnik](https://github.com/mkasztelnik)
68
+
69
+ # 3.9.5
70
+
71
+ * Prevent overwriting `teardown` method in Test::Unit
72
+
73
+ Thanks to [Jesse Bowes](https://github.com/jessebs)
74
+
75
+ # 3.9.4
76
+
77
+ * More intuitive error message when stubbed response body was provided as Hash
78
+
79
+ Thanks to [Ben Koshy](https://github.com/BKSpurgeon)
80
+
81
+ # 3.9.3
82
+
83
+ * Make httpclient_adapter thread-safe
84
+
85
+ Thanks to [Adam Harwood](https://github.com/adam-harwood)
86
+
87
+ # 3.9.2
88
+
89
+ * Made global stubs thread-safe
90
+
91
+ Thanks to [Adam Harwood](https://github.com/adam-harwood)
92
+
93
+ # 3.9.1
94
+
95
+ * Fixed support for passing `URI` objects as second argument of `stub_request`
96
+
97
+ Thanks to [Ryan Kerr](https://github.com/leboshi)
98
+
99
+ ## 3.9.0
100
+
101
+ * Allow using a "callable" (like a proc) as URI pattern
102
+
103
+ stub_request(:any, ->(uri) { true })
104
+
105
+ Thanks to [John Hawthorn](https://github.com/jhawthorn)
106
+
107
+ * Added stubbed IO on stubbed socket in Net::HTTP adapter.
108
+
109
+ Thanks to [Thilo Rusche](https://github.com/trusche)
110
+
111
+ * When 'webmock/rspec' is required, reset WebMock after all after(:each/example) hooks
112
+
113
+ Thanks to [Andrew Stuntz](https://github.com/drews256)
114
+
115
+ * Fixed `net_connect_allowed?` when invoked with no arguments, when there were any allowed URIs passed to `disable_net_connect?`.
116
+
117
+ Thanks to [Lucas Uyezu](https://github.com/lucasuyezu)
118
+
119
+ * Fixed async-http adapter which caused Async::HTTP::Client or Async::HTTP::Internet to hang and never return a response.
120
+
121
+ Thanks to [Bruno Sutic](https://github.com/bruno-) and [Samuel Williams](https://github.com/ioquatix)
122
+
123
+ * Fixed warning when using async-http adapter
124
+
125
+ Thanks to [Bruno Sutic](https://github.com/bruno-)
126
+
127
+ * Dropped support for Ruby 2.3 - EOL date: 2019-03-31
128
+
129
+ * Dropped support for Ruby 2.4 - EOL date: 2020-03-31
130
+
131
+ * 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.
132
+
133
+ Thanks to [Rafael França](https://github.com/rafaelfranca) and [guppy0356](https://github.com/guppy0356)
134
+
135
+ ## 3.8.3
136
+
137
+ * Fixed problem introduced in version 3.4.2, which caused matching against Addressable::Template representing host part of the URI to raise an error.
138
+
139
+ Thanks to [Vesa Laakso](https://github.com/valscion)
140
+
141
+ ## 3.8.2
142
+
143
+ * Support correct encoding parameter for HTTP.rb 2.x and earlier
144
+
145
+ Thanks to [Alex Coomans](https://github.com/drcapulet)
146
+
147
+ ## 3.8.1
148
+
149
+ * Added support for mocking non-ASCII bodies when making requests with HTTP.rb
150
+
151
+ Thanks to [Patrik Ragnarsson](https://github.com/dentarg)
152
+
153
+ ## 3.8.0
154
+
155
+ * Fixed options handling when initialising Async::HTTP::Client
156
+
157
+ Thanks to [Samuel Williams](https://github.com/ioquatix)
158
+
159
+ * Ruby 2.7 support.
160
+
161
+ Thanks to [Ryan Davis](https://github.com/zenspider) and [Brandur](https://github.com/brandur)
162
+
163
+ ## 3.7.6
164
+
165
+ * Suppressed keyword argument warnings in Ruby 2.7 in async-http adapter.
166
+
167
+ Thanks to [Koichi ITO](https://github.com/koic)
168
+
169
+ ## 3.7.5
170
+
171
+ * Suppress Excon warning generated by extra key
172
+
173
+ Thanks to [Marco Costa](https://github.com/marcotc)
174
+
175
+ ## 3.7.4
176
+
177
+ * Resetting memoized response fields in Curb adapter.
178
+
179
+ Thanks to [Andrei Sidorov](https://github.com/heretge)
180
+
181
+ ## 3.7.3
182
+
183
+ * Fix for http.rb. Allow passing an output buffer to HTTP::Response::Body#readpartial
184
+
185
+ Thanks to [George Claghorn](https://github.com/georgeclaghorn)
186
+
187
+ * Fixed Manticore adapter to invoke Manticore failure handler on stubbed timeout
188
+
189
+ Thanks to [Alex Junger](https://github.com/alexJunger)
190
+
191
+ * Added project metadata to the gemspec
192
+
193
+ Thanks to [Orien Madgwick](https://github.com/orien)
194
+
195
+ ## 3.7.2
196
+
197
+ * Fixed handling of non UTF-8 encoded urls
198
+
199
+ Thanks to [Rafael França](https://github.com/rafaelfranca)
200
+
201
+ * Fixed "shadowing outer local variable" warning
202
+
203
+ Thanks to [y-yagi](https://github.com/y-yagi)
204
+
205
+ ## 3.7.1
206
+
207
+ * Fixed Async::HTTP::Client adapter code to not cause Ruby warning
208
+
209
+ Thanks to [y-yagi](https://github.com/y-yagi)
210
+
211
+ ## 3.7.0
212
+
213
+ * Support for Async::HTTP::Client
214
+
215
+ Thanks to [Andriy Yanko](https://github.com/ayanko)
216
+
3
217
  ## 3.6.2
4
218
 
5
219
  * Fixed Patron adapter to handle HTTP/2 status line.
data/Gemfile CHANGED
@@ -1,4 +1,4 @@
1
- source 'http://rubygems.org/'
1
+ source 'https://rubygems.org/'
2
2
 
3
3
  gemspec
4
4
 
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  WebMock
2
2
  =======
3
3
  [![Gem Version](https://badge.fury.io/rb/webmock.svg)](http://badge.fury.io/rb/webmock)
4
- [![Build Status](https://secure.travis-ci.org/bblimke/webmock.svg?branch=master)](http://travis-ci.org/bblimke/webmock)
4
+ [![Build Status](https://github.com/bblimke/webmock/workflows/CI/badge.svg?branch=master)](https://github.com/bblimke/webmock/actions)
5
5
  [![Code Climate](https://codeclimate.com/github/bblimke/webmock/badges/gpa.svg)](https://codeclimate.com/github/bblimke/webmock)
6
6
  [![Mentioned in Awesome Ruby](https://awesome.re/mentioned-badge.svg)](https://github.com/markets/awesome-ruby)
7
7
  [![Inline docs](http://inch-ci.org/github/bblimke/webmock.svg?branch=master)](http://inch-ci.org/github/bblimke/webmock)
@@ -24,30 +24,42 @@ Features
24
24
  Supported HTTP libraries
25
25
  ------------------------
26
26
 
27
- * Net::HTTP and libraries based on Net::HTTP (i.e RightHttpConnection, REST Client, HTTParty)
28
- * HTTPClient
29
- * Patron
30
- * EM-HTTP-Request
31
- * Curb (currently only Curb::Easy)
32
- * Typhoeus (currently only Typhoeus::Hydra)
33
- * Excon
34
- * HTTP Gem
35
- * Manticore
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)
36
40
 
37
41
  Supported Ruby Interpreters
38
42
  ---------------------------
39
43
 
40
- * MRI 2.2
41
- * MRI 2.3
42
- * MRI 2.4
43
44
  * MRI 2.5
44
45
  * MRI 2.6
46
+ * MRI 2.7
45
47
  * JRuby
46
48
  * Rubinius
47
49
 
48
50
  ## Installation
49
51
 
52
+ ```bash
50
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
+ ```
51
63
 
52
64
  ### or to install the latest development version from github master
53
65
 
@@ -59,36 +71,36 @@ Supported Ruby Interpreters
59
71
 
60
72
  WebMock 2.x has changed somewhat since version 1.x. Changes are listed in [CHANGELOG.md](CHANGELOG.md)
61
73
 
62
- ### Test::Unit
74
+ ### Cucumber
63
75
 
64
- Add the following code to `test/test_helper.rb`
76
+ Create a file `features/support/webmock.rb` with the following contents:
65
77
 
66
78
  ```ruby
67
- require 'webmock/test_unit'
79
+ require 'webmock/cucumber'
68
80
  ```
69
81
 
70
- ### RSpec
82
+ ### MiniTest
71
83
 
72
- Add the following code to `spec/spec_helper`:
84
+ Add the following code to `test/test_helper`:
73
85
 
74
86
  ```ruby
75
- require 'webmock/rspec'
87
+ require 'webmock/minitest'
76
88
  ```
77
89
 
78
- ### MiniTest
90
+ ### RSpec
79
91
 
80
- Add the following code to `test/test_helper`:
92
+ Add the following code to `spec/spec_helper`:
81
93
 
82
94
  ```ruby
83
- require 'webmock/minitest'
95
+ require 'webmock/rspec'
84
96
  ```
85
97
 
86
- ### Cucumber
98
+ ### Test::Unit
87
99
 
88
- Create a file `features/support/webmock.rb` with the following contents:
100
+ Add the following code to `test/test_helper.rb`
89
101
 
90
102
  ```ruby
91
- require 'webmock/cucumber'
103
+ require 'webmock/test_unit'
92
104
  ```
93
105
 
94
106
  ### Outside a test framework
@@ -102,13 +114,10 @@ include WebMock::API
102
114
  WebMock.enable!
103
115
  ```
104
116
 
105
- ## Examples
106
-
107
-
117
+ # Examples
108
118
 
109
119
  ## Stubbing
110
120
 
111
-
112
121
  ### Stubbed request based on uri only and with the default response
113
122
 
114
123
  ```ruby
@@ -241,6 +250,12 @@ stub_request(:any, /example/)
241
250
  Net::HTTP.get('www.example.com', '/') # ===> Success
242
251
  ```
243
252
 
253
+ ### Matching uris using lambda
254
+
255
+ ```ruby
256
+ stub_request(:any, ->(uri) { true })
257
+ ```
258
+
244
259
  ### Matching uris using RFC 6570 - Basic Example
245
260
 
246
261
  ```ruby
@@ -298,6 +313,12 @@ stub_request(:any, "www.example.com").
298
313
  Net::HTTP.get("www.example.com", '/') # ===> "abc"
299
314
  ```
300
315
 
316
+ Set appropriate Content-Type for HTTParty's `parsed_response`.
317
+
318
+ ```ruby
319
+ stub_request(:any, "www.example.com").to_return body: '{}', headers: {content_type: 'application/json'}
320
+ ```
321
+
301
322
  ### Response with body specified as IO object
302
323
 
303
324
  ```ruby
@@ -1105,9 +1126,41 @@ People who submitted patches and new features or suggested improvements. Many th
1105
1126
  * Csaba Apagyi
1106
1127
  * Frederick Cheung
1107
1128
  * Fábio D. Batista
1108
-
1109
-
1110
-
1129
+ * Andriy Yanko
1130
+ * y-yagi
1131
+ * Rafael França
1132
+ * George Claghorn
1133
+ * Alex Junger
1134
+ * Orien Madgwick
1135
+ * Andrei Sidorov
1136
+ * Marco Costa
1137
+ * Ryan Davis
1138
+ * Brandur
1139
+ * Samuel Williams
1140
+ * Patrik Ragnarsson
1141
+ * Alex Coomans
1142
+ * Vesa Laakso
1143
+ * John Hawthorn
1144
+ * guppy0356
1145
+ * Thilo Rusche
1146
+ * Andrew Stuntz
1147
+ * Lucas Uyezu
1148
+ * Bruno Sutic
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
1111
1164
 
1112
1165
  For a full list of contributors you can visit the
1113
1166
  [contributors](https://github.com/bblimke/webmock/contributors) page.
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 = ["-c", "-f progress", "-r ./spec/spec_helper.rb"]
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 = ["-c", "-f progress", "-r ./spec/acceptance/net_http/real_net_http_spec.rb"]
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