webmock 3.5.1 → 3.11.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.
Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +15 -12
  3. data/CHANGELOG.md +211 -0
  4. data/README.md +92 -26
  5. data/Rakefile +0 -2
  6. data/lib/webmock.rb +1 -0
  7. data/lib/webmock/http_lib_adapters/async_http_client_adapter.rb +214 -0
  8. data/lib/webmock/http_lib_adapters/curb_adapter.rb +10 -1
  9. data/lib/webmock/http_lib_adapters/em_http_request_adapter.rb +1 -1
  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 +11 -1
  13. data/lib/webmock/http_lib_adapters/http_rb/streamer.rb +2 -2
  14. data/lib/webmock/http_lib_adapters/httpclient_adapter.rb +23 -6
  15. data/lib/webmock/http_lib_adapters/manticore_adapter.rb +25 -14
  16. data/lib/webmock/http_lib_adapters/net_http.rb +35 -17
  17. data/lib/webmock/http_lib_adapters/patron_adapter.rb +1 -1
  18. data/lib/webmock/request_body_diff.rb +1 -1
  19. data/lib/webmock/request_pattern.rb +76 -48
  20. data/lib/webmock/response.rb +11 -5
  21. data/lib/webmock/rspec.rb +2 -1
  22. data/lib/webmock/stub_registry.rb +26 -11
  23. data/lib/webmock/test_unit.rb +1 -3
  24. data/lib/webmock/util/query_mapper.rb +4 -2
  25. data/lib/webmock/util/uri.rb +8 -8
  26. data/lib/webmock/version.rb +1 -1
  27. data/lib/webmock/webmock.rb +10 -3
  28. data/spec/acceptance/async_http_client/async_http_client_spec.rb +353 -0
  29. data/spec/acceptance/async_http_client/async_http_client_spec_helper.rb +73 -0
  30. data/spec/acceptance/curb/curb_spec.rb +23 -5
  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 +19 -0
  35. data/spec/acceptance/net_http/net_http_spec.rb +12 -0
  36. data/spec/acceptance/shared/callbacks.rb +2 -1
  37. data/spec/acceptance/shared/request_expectations.rb +7 -0
  38. data/spec/acceptance/shared/returning_declared_responses.rb +36 -15
  39. data/spec/acceptance/shared/stubbing_requests.rb +40 -0
  40. data/spec/support/webmock_server.rb +1 -0
  41. data/spec/unit/request_pattern_spec.rb +119 -3
  42. data/spec/unit/response_spec.rb +22 -18
  43. data/spec/unit/util/query_mapper_spec.rb +7 -0
  44. data/spec/unit/util/uri_spec.rb +74 -2
  45. data/spec/unit/webmock_spec.rb +54 -5
  46. data/test/test_webmock.rb +6 -0
  47. data/webmock.gemspec +9 -2
  48. metadata +39 -10
@@ -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 not given one of the allowed types" do
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
- "Date"=>"Sat, 23 Jan 2010 01:01:05 GMT",
156
- "Content-Type"=>"text/html; charset=UTF-8",
157
- "Content-Length"=>"419",
158
- "Connection"=>"Keep-Alive",
159
- "Accept"=>"image/jpeg, image/png"
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
- "Date"=>"Sat, 23 Jan 2010 01:01:05 GMT",
186
- "Content-Type"=>"text/html; charset=UTF-8",
187
- "Content-Length"=>"419",
188
- "Connection"=>"Keep-Alive",
189
- "Accept"=>"image/jpeg, image/png"
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
- body: request.body,
239
- headers: request.headers,
240
- status: 302
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")
@@ -147,4 +147,11 @@ describe WebMock::Util::QueryMapper do
147
147
  expect(subject.values_to_query values).to eq query
148
148
  expect(subject.query_to_values query).to eq values
149
149
  end
150
+
151
+ it 'converts an empty array to ?' do
152
+ query = "one%5B%5D"
153
+ values = {"one" => []}
154
+ expect(subject.values_to_query values).to eq query
155
+ expect(subject.query_to_values query).to eq values
156
+ end
150
157
  end
@@ -1,6 +1,5 @@
1
1
  require 'spec_helper'
2
2
 
3
-
4
3
  URIS_WITHOUT_PATH_OR_PARAMS =
5
4
  [
6
5
  "www.example.com",
@@ -65,7 +64,6 @@ URIS_WITH_DIFFERENT_PORT =
65
64
  "http://www.example.com:88/"
66
65
  ].sort
67
66
 
68
-
69
67
  URIS_FOR_HTTPS =
70
68
  [
71
69
  "https://www.example.com",
@@ -74,6 +72,49 @@ URIS_FOR_HTTPS =
74
72
  "https://www.example.com:443/"
75
73
  ].sort
76
74
 
75
+ URIS_FOR_LOCALHOST =
76
+ [
77
+ "localhost",
78
+ "localhost/",
79
+ "localhost:80",
80
+ "localhost:80/",
81
+ "http://localhost",
82
+ "http://localhost/",
83
+ "http://localhost:80",
84
+ "http://localhost:80/"
85
+ ].sort
86
+
87
+ URIS_WITH_SCHEME =
88
+ [
89
+ "http://www.example.com",
90
+ "http://www.example.com/",
91
+ "http://www.example.com:80",
92
+ "http://www.example.com:80/"
93
+ ].sort
94
+
95
+ URIS_WITH_COLON_IN_PATH =
96
+ [
97
+ [
98
+ "https://example.com/a/b:80",
99
+ "https://example.com:443/a/b:80",
100
+ ].sort,
101
+ [
102
+ "https://example.com:443/a/b:443",
103
+ "https://example.com/a/b:443",
104
+ ].sort,
105
+ [
106
+ "http://example.com/a/b:443",
107
+ "example.com/a/b:443",
108
+ "http://example.com:80/a/b:443",
109
+ "example.com:80/a/b:443",
110
+ ].sort,
111
+ [
112
+ "http://example.com/a/b:80",
113
+ "example.com/a/b:80",
114
+ "http://example.com:80/a/b:80",
115
+ "example.com:80/a/b:80",
116
+ ].sort
117
+ ]
77
118
 
78
119
  describe WebMock::Util::URI do
79
120
 
@@ -115,6 +156,37 @@ describe WebMock::Util::URI do
115
156
  end
116
157
  end
117
158
 
159
+ it "should find all variations of the same uri for all variations of host names uris without a period" do
160
+ URIS_FOR_LOCALHOST.each do |uri|
161
+ expect(WebMock::Util::URI.variations_of_uri_as_strings(uri).sort).to eq(URIS_FOR_LOCALHOST)
162
+ end
163
+ end
164
+
165
+ it "should find all variations of the same uri with scheme for all variations when only_with_scheme is true" do
166
+ URIS_WITHOUT_PATH_OR_PARAMS.each do |uri|
167
+ variations_of_uri_with_scheme = WebMock::Util::URI.variations_of_uri_as_strings(uri, only_with_scheme: true)
168
+ expect(variations_of_uri_with_scheme.sort).to eq(URIS_WITH_SCHEME)
169
+ end
170
+ end
171
+
172
+ it "should not replace :80 or :443 in path" do
173
+ URIS_WITH_COLON_IN_PATH.each do |uris|
174
+ uris.each do |uri|
175
+ expect(WebMock::Util::URI.variations_of_uri_as_strings(uri).sort).to eq(uris)
176
+ end
177
+ end
178
+ end
179
+
180
+ it "should find all variations of uris with https, basic auth, a non-standard port and a path" do
181
+ uri = "https://~%8A:pass@www.example.com:9000/foo"
182
+ variations = [
183
+ "https://~%8A:pass@www.example.com:9000/foo",
184
+ "https://~\x8A:pass@www.example.com:9000/foo".force_encoding(Encoding::ASCII_8BIT)
185
+ ]
186
+
187
+ expect(WebMock::Util::URI.variations_of_uri_as_strings(uri)).to eq(variations)
188
+ end
189
+
118
190
  end
119
191
 
120
192
  describe "normalized uri equality" do
@@ -1,11 +1,60 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe "WebMock version" do
4
- it "should report version" do
5
- expect(WebMock.version).to eq(WebMock::VERSION)
3
+ describe "WebMock" do
4
+
5
+ describe ".version" do
6
+ it "should report version" do
7
+ expect(WebMock.version).to eq(WebMock::VERSION)
8
+ end
9
+
10
+ it "should not require safe_yaml" do
11
+ expect(defined?SafeYAML).to eq(nil)
12
+ end
13
+
14
+ it "should alias enable_net_connect! to allow_net_connect!" do
15
+ expect(WebMock.method(:enable_net_connect!)).to eq(WebMock.method(:allow_net_connect!))
16
+ end
17
+
18
+ it "should alias disallow_net_connect! to disable_net_connect!" do
19
+ expect(WebMock.method(:disallow_net_connect!)).to eq(WebMock.method(:disable_net_connect!))
20
+ end
6
21
  end
7
22
 
8
- it "should not require safe_yaml" do
9
- expect(defined?SafeYAML).to eq(nil)
23
+ describe ".net_connect_allowed?" do
24
+ context 'enabled globally' do
25
+ before do
26
+ WebMock.enable_net_connect!
27
+ end
28
+
29
+ context 'without arguments' do
30
+ it 'returns WebMock::Config.instance.allow_net_connect' do
31
+ expect(WebMock.net_connect_allowed?).to eql(true)
32
+ end
33
+ end
34
+ end
35
+
36
+ context 'disabled with allowed remote string' do
37
+ before do
38
+ WebMock.disable_net_connect!(allow: "http://192.168.64.2:20031")
39
+ end
40
+
41
+ context 'without arguments' do
42
+ it 'returns WebMock::Config.instance.allow_net_connect' do
43
+ expect(WebMock.net_connect_allowed?).to eql(false)
44
+ end
45
+ end
46
+ end
47
+
48
+ context 'disabled globally' do
49
+ before do
50
+ WebMock.disable_net_connect!
51
+ end
52
+
53
+ context 'without arguments' do
54
+ it 'returns WebMock::Config.instance.allow_net_connect' do
55
+ expect(WebMock.net_connect_allowed?).to eql(false)
56
+ end
57
+ end
58
+ end
10
59
  end
11
60
  end
@@ -3,4 +3,10 @@ require File.expand_path(File.dirname(__FILE__) + '/shared_test')
3
3
 
4
4
  class TestWebMock < Test::Unit::TestCase
5
5
  include SharedTest
6
+
7
+ def teardown
8
+ # Ensure global Test::Unit teardown was called
9
+ assert_empty WebMock::RequestRegistry.instance.requested_signatures.hash
10
+ assert_empty WebMock::StubRegistry.instance.request_stubs
11
+ end
6
12
  end
@@ -13,13 +13,19 @@ Gem::Specification.new do |s|
13
13
  s.description = %q{WebMock allows stubbing HTTP requests and setting expectations on HTTP requests.}
14
14
  s.license = "MIT"
15
15
 
16
- s.rubyforge_project = 'webmock'
16
+ s.metadata = {
17
+ 'bug_tracker_uri' => 'https://github.com/bblimke/webmock/issues',
18
+ 'changelog_uri' => "https://github.com/bblimke/webmock/blob/v#{s.version}/CHANGELOG.md",
19
+ 'documentation_uri' => "https://www.rubydoc.info/gems/webmock/#{s.version}",
20
+ 'source_code_uri' => "https://github.com/bblimke/webmock/tree/v#{s.version}",
21
+ 'wiki_uri' => 'https://github.com/bblimke/webmock/wiki'
22
+ }
17
23
 
18
24
  s.required_ruby_version = '>= 2.0'
19
25
 
20
26
  s.add_dependency 'addressable', '>= 2.3.6'
21
27
  s.add_dependency 'crack', '>= 0.3.2'
22
- s.add_dependency 'hashdiff'
28
+ s.add_dependency 'hashdiff', ['>= 0.4.0', '< 2.0.0']
23
29
 
24
30
  unless RUBY_PLATFORM =~ /java/
25
31
  s.add_development_dependency 'patron', '>= 0.4.18'
@@ -35,6 +41,7 @@ Gem::Specification.new do |s|
35
41
  s.add_development_dependency 'em-http-request', '>= 1.0.2'
36
42
  s.add_development_dependency 'em-synchrony', '>= 1.0.0'
37
43
  s.add_development_dependency 'excon', '>= 0.27.5'
44
+ s.add_development_dependency 'async-http', '>= 0.48.0'
38
45
  s.add_development_dependency 'minitest', '>= 5.0.0'
39
46
  s.add_development_dependency 'test-unit', '>= 3.0.0'
40
47
  s.add_development_dependency 'rdoc', '> 3.5.0'
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.5.1
4
+ version: 3.11.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bartosz Blimke
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-12-27 00:00:00.000000000 Z
11
+ date: 2020-12-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: addressable
@@ -44,14 +44,20 @@ dependencies:
44
44
  requirements:
45
45
  - - ">="
46
46
  - !ruby/object:Gem::Version
47
- version: '0'
47
+ version: 0.4.0
48
+ - - "<"
49
+ - !ruby/object:Gem::Version
50
+ version: 2.0.0
48
51
  type: :runtime
49
52
  prerelease: false
50
53
  version_requirements: !ruby/object:Gem::Requirement
51
54
  requirements:
52
55
  - - ">="
53
56
  - !ruby/object:Gem::Version
54
- version: '0'
57
+ version: 0.4.0
58
+ - - "<"
59
+ - !ruby/object:Gem::Version
60
+ version: 2.0.0
55
61
  - !ruby/object:Gem::Dependency
56
62
  name: patron
57
63
  requirement: !ruby/object:Gem::Requirement
@@ -192,6 +198,20 @@ dependencies:
192
198
  - - ">="
193
199
  - !ruby/object:Gem::Version
194
200
  version: 0.27.5
201
+ - !ruby/object:Gem::Dependency
202
+ name: async-http
203
+ requirement: !ruby/object:Gem::Requirement
204
+ requirements:
205
+ - - ">="
206
+ - !ruby/object:Gem::Version
207
+ version: 0.48.0
208
+ type: :development
209
+ prerelease: false
210
+ version_requirements: !ruby/object:Gem::Requirement
211
+ requirements:
212
+ - - ">="
213
+ - !ruby/object:Gem::Version
214
+ version: 0.48.0
195
215
  - !ruby/object:Gem::Dependency
196
216
  name: minitest
197
217
  requirement: !ruby/object:Gem::Requirement
@@ -259,6 +279,7 @@ files:
259
279
  - lib/webmock/cucumber.rb
260
280
  - lib/webmock/deprecation.rb
261
281
  - lib/webmock/errors.rb
282
+ - lib/webmock/http_lib_adapters/async_http_client_adapter.rb
262
283
  - lib/webmock/http_lib_adapters/curb_adapter.rb
263
284
  - lib/webmock/http_lib_adapters/em_http_request_adapter.rb
264
285
  - lib/webmock/http_lib_adapters/excon_adapter.rb
@@ -312,6 +333,8 @@ files:
312
333
  - minitest/test_helper.rb
313
334
  - minitest/test_webmock.rb
314
335
  - minitest/webmock_spec.rb
336
+ - spec/acceptance/async_http_client/async_http_client_spec.rb
337
+ - spec/acceptance/async_http_client/async_http_client_spec_helper.rb
315
338
  - spec/acceptance/curb/curb_spec.rb
316
339
  - spec/acceptance/curb/curb_spec_helper.rb
317
340
  - spec/acceptance/em_http_request/em_http_request_spec.rb
@@ -382,8 +405,13 @@ files:
382
405
  homepage: http://github.com/bblimke/webmock
383
406
  licenses:
384
407
  - MIT
385
- metadata: {}
386
- post_install_message:
408
+ metadata:
409
+ bug_tracker_uri: https://github.com/bblimke/webmock/issues
410
+ changelog_uri: https://github.com/bblimke/webmock/blob/v3.11.0/CHANGELOG.md
411
+ documentation_uri: https://www.rubydoc.info/gems/webmock/3.11.0
412
+ source_code_uri: https://github.com/bblimke/webmock/tree/v3.11.0
413
+ wiki_uri: https://github.com/bblimke/webmock/wiki
414
+ post_install_message:
387
415
  rdoc_options: []
388
416
  require_paths:
389
417
  - lib
@@ -398,12 +426,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
398
426
  - !ruby/object:Gem::Version
399
427
  version: '0'
400
428
  requirements: []
401
- rubyforge_project: webmock
402
- rubygems_version: 2.7.6
403
- signing_key:
429
+ rubygems_version: 3.1.2
430
+ signing_key:
404
431
  specification_version: 4
405
432
  summary: Library for stubbing HTTP requests in Ruby.
406
433
  test_files:
434
+ - spec/acceptance/async_http_client/async_http_client_spec.rb
435
+ - spec/acceptance/async_http_client/async_http_client_spec_helper.rb
407
436
  - spec/acceptance/curb/curb_spec.rb
408
437
  - spec/acceptance/curb/curb_spec_helper.rb
409
438
  - spec/acceptance/em_http_request/em_http_request_spec.rb