webmock 3.9.5 → 3.11.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e86a9ca126d1410e47a219ea054f8591fe421e303deb27366b0705c88d37484f
4
- data.tar.gz: 8e35153a6620d376d86cf37c3ab85060f38265cc9c110ce6f5adbc3120af0fdf
3
+ metadata.gz: 57ec99bb8b1ce01a51c062c634c17abe5cda03777fbb43d4aec3dd12175c44bf
4
+ data.tar.gz: 55c9f75174da8a3c63ac600d8199cef85350a6b525e39c44e8c514383a5d3432
5
5
  SHA512:
6
- metadata.gz: 3af5f5d03fe560dbbdf8cb974ed913568bfb8964372c44d705ae6b8956a66f9095723e9a6c8845b7fb9ce6894047cb5662c6d01f5ae832e62a17cd6bf681e6c9
7
- data.tar.gz: bae8f2a18cf86174308dc4ab14305aca3586853e67a9b27a4fbdefbb5abee31c54ec734ff42f22a1fa974e233d69516eea96a669a511cbb342bda2e2f062e3fa
6
+ metadata.gz: 9d7ed44a6d69e2a6fef4cf5636e6ee1a525485bccc3951735f8d3470901c9f05b9d61da09dc6b2ac39a558aa8f42d2d40c8b29a9048d21853af080f8f8a6912b
7
+ data.tar.gz: 2e0a3617e7eac5a0cbe7a63def37747f5e3948a284b40aa996cb519463d73c3cfdec206963f5eff351259f9af7c2a11fd6eacab49e6fff930327c1fb42d6f30f
@@ -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,43 @@
1
1
  # Changelog
2
2
 
3
+ # 3.11.3
4
+
5
+ * Fixed async-http adapter to only considered requests as real if they are real.
6
+
7
+ Thanks to Thanks to [Tony Schneider](https://github.com/tonywok) and [Samuel Williams](https://github.com/ioquatix)
8
+
9
+ # 3.11.2
10
+
11
+ * Fix for Manticore streaming mode
12
+
13
+ Thanks to [Oleksiy Kovyrin](https://github.com/kovyrin)
14
+
15
+ # 3.11.1
16
+
17
+ * Compatibility with async-http 0.54+
18
+
19
+ Thanks to [Jun Jiang](https://github.com/jasl)
20
+
21
+ # 3.11.0
22
+
23
+ * Added support for `features` in http.rb adapter.
24
+
25
+ Thanks to [Carl (ce07c3)](https://github.com/ce07c3)
26
+
27
+ # 3.10.0
28
+
29
+ * Added option to global stubs to have lower priority than local stubs.
30
+
31
+ WebMock.globally_stub_request(:after_local_stubs) do
32
+ { body: "global stub body" }
33
+ end
34
+
35
+ stub_request(:get, "www.example.com").to_return(body: 'non-global stub body')
36
+
37
+ expect(http_request(:get, "http://www.example.com/").body).to eq("non-global stub body")
38
+
39
+ Thanks to [Marek Kasztelnik](https://github.com/mkasztelnik)
40
+
3
41
  # 3.9.5
4
42
 
5
43
  * Prevent overwriting `teardown` method in Test::Unit
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
@@ -1150,6 +1150,12 @@ People who submitted patches and new features or suggested improvements. Many th
1150
1150
  * Adam Harwood
1151
1151
  * Ben Koshy
1152
1152
  * Jesse Bowes
1153
+ * Marek Kasztelnik
1154
+ * ce07c3
1155
+ * Jun Jiang
1156
+ * Oleksiy Kovyrin
1157
+ * Matt Larraz
1158
+ * Tony Schneider
1153
1159
 
1154
1160
  For a full list of contributors you can visit the
1155
1161
  [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
@@ -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, protocol, scheme, authority, **options)
44
- @webmock_client = WebMockClient.new(webmock_endpoint, protocol, scheme, authority, **options)
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: net_connect_allowed
77
+ real_request: real_request
76
78
  },
77
79
  request_signature,
78
80
  webmock_response
@@ -4,7 +4,10 @@ module HTTP
4
4
 
5
5
  def perform(request, options)
6
6
  return __perform__(request, options) unless webmock_enabled?
7
- WebMockPerform.new(request) { __perform__(request, options) }.exec
7
+
8
+ response = WebMockPerform.new(request) { __perform__(request, options) }.exec
9
+ options.features.each { |_name, feature| response = feature.wrap_response(response) }
10
+ response
8
11
  end
9
12
 
10
13
  def webmock_enabled?
@@ -127,8 +127,15 @@ if defined?(Manticore)
127
127
  def generate_webmock_response(manticore_response)
128
128
  webmock_response = WebMock::Response.new
129
129
  webmock_response.status = [manticore_response.code, manticore_response.message]
130
- webmock_response.body = manticore_response.body
131
130
  webmock_response.headers = manticore_response.headers
131
+
132
+ # The attempt to read the body could fail if manticore is used in a streaming mode
133
+ webmock_response.body = begin
134
+ manticore_response.body
135
+ rescue ::Manticore::StreamClosedException
136
+ nil
137
+ end
138
+
132
139
  webmock_response
133
140
  end
134
141
  end
@@ -10,14 +10,18 @@ module WebMock
10
10
  end
11
11
 
12
12
  def global_stubs
13
- @global_stubs ||= []
13
+ @global_stubs ||= Hash.new { |h, k| h[k] = [] }
14
14
  end
15
15
 
16
16
  def reset!
17
17
  self.request_stubs = []
18
18
  end
19
19
 
20
- def register_global_stub(&block)
20
+ def register_global_stub(order = :before_local_stubs, &block)
21
+ unless %i[before_local_stubs after_local_stubs].include?(order)
22
+ raise ArgumentError.new("Wrong order. Use :before_local_stubs or :after_local_stubs")
23
+ end
24
+
21
25
  # This hash contains the responses returned by the block,
22
26
  # keyed by the exact request (using the object_id).
23
27
  # That way, there's no race condition in case #to_return
@@ -38,7 +42,7 @@ module WebMock
38
42
  response_lock.synchronize { responses.delete(request.object_id) }
39
43
  })
40
44
 
41
- global_stubs.push stub
45
+ global_stubs[order].push stub
42
46
  end
43
47
 
44
48
  def register_request_stub(stub)
@@ -64,9 +68,10 @@ module WebMock
64
68
  private
65
69
 
66
70
  def request_stub_for(request_signature)
67
- (global_stubs + request_stubs).detect { |registered_request_stub|
68
- registered_request_stub.request_pattern.matches?(request_signature)
69
- }
71
+ (global_stubs[:before_local_stubs] + request_stubs + global_stubs[:after_local_stubs])
72
+ .detect { |registered_request_stub|
73
+ registered_request_stub.request_pattern.matches?(request_signature)
74
+ }
70
75
  end
71
76
 
72
77
  def evaluate_response_for_request(response, request_signature)
@@ -1,3 +1,3 @@
1
1
  module WebMock
2
- VERSION = '3.9.5' unless defined?(::WebMock::VERSION)
2
+ VERSION = '3.11.3' unless defined?(::WebMock::VERSION)
3
3
  end
@@ -140,8 +140,8 @@ module WebMock
140
140
  puts WebMock::RequestExecutionVerifier.executed_requests_message
141
141
  end
142
142
 
143
- def self.globally_stub_request(&block)
144
- WebMock::StubRegistry.instance.register_global_stub(&block)
143
+ def self.globally_stub_request(order = :before_local_stubs, &block)
144
+ WebMock::StubRegistry.instance.register_global_stub(order, &block)
145
145
  end
146
146
 
147
147
  %w(
@@ -135,6 +135,28 @@ unless RUBY_PLATFORM =~ /java/
135
135
  expect { make_request(:get, 'http://www.example.com') }.to raise_error Async::TimeoutError
136
136
  end
137
137
 
138
+ it 'does not invoke "after real request" callbacks for stubbed requests' do
139
+ WebMock.allow_net_connect!
140
+ stub_request(:get, 'http://www.example.com').to_return(body: 'abc')
141
+
142
+ callback_invoked = false
143
+ WebMock.after_request(real_requests_only: true) { |_| callback_invoked = true }
144
+
145
+ make_request(:get, 'http://www.example.com')
146
+ expect(callback_invoked).to eq(false)
147
+ end
148
+
149
+ it 'does invoke "after request" callbacks for stubbed requests' do
150
+ WebMock.allow_net_connect!
151
+ stub_request(:get, 'http://www.example.com').to_return(body: 'abc')
152
+
153
+ callback_invoked = false
154
+ WebMock.after_request(real_requests_only: false) { |_| callback_invoked = true }
155
+
156
+ make_request(:get, 'http://www.example.com')
157
+ expect(callback_invoked).to eq(true)
158
+ end
159
+
138
160
  context 'scheme and protocol' do
139
161
  let(:default_response_headers) { {} }
140
162
 
@@ -70,6 +70,38 @@ if RUBY_PLATFORM =~ /java/
70
70
  expect(failure_handler).to have_received(:call)
71
71
  end
72
72
  end
73
+
74
+ context 'when used in a streaming mode' do
75
+ let(:webmock_server_url) {"http://#{WebMockServer.instance.host_with_port}/"}
76
+ let(:result_chunks) { [] }
77
+
78
+ def manticore_streaming_get
79
+ Manticore.get(webmock_server_url).tap do |req|
80
+ req.on_success do |response|
81
+ response.body do |chunk|
82
+ result_chunks << chunk
83
+ end
84
+ end
85
+ end
86
+ end
87
+
88
+ context 'when connections are allowed' do
89
+ it 'works' do
90
+ WebMock.allow_net_connect!
91
+ expect { manticore_streaming_get.call }.to_not raise_error
92
+ expect(result_chunks).to_not be_empty
93
+ end
94
+ end
95
+
96
+ context 'when stubbed' do
97
+ it 'works' do
98
+ stub_body = 'hello!'
99
+ stub_request(:get, webmock_server_url).to_return(body: stub_body)
100
+ expect { manticore_streaming_get.call }.to_not raise_error
101
+ expect(result_chunks).to eq [stub_body]
102
+ end
103
+ end
104
+ end
73
105
  end
74
106
  end
75
107
  end
@@ -593,6 +593,23 @@ shared_examples_for "stubbing requests" do |*adapter_info|
593
593
  end
594
594
  end
595
595
  end
596
+
597
+ context "when global stub should be invoked last" do
598
+ before do
599
+ WebMock.globally_stub_request(:after_local_stubs) do
600
+ { body: "global stub body" }
601
+ end
602
+ end
603
+
604
+ it "uses global stub when non-global stub is not defined" do
605
+ expect(http_request(:get, "http://www.example.com/").body).to eq("global stub body")
606
+ end
607
+
608
+ it "uses non-global stub first" do
609
+ stub_request(:get, "www.example.com").to_return(body: 'non-global stub body')
610
+ expect(http_request(:get, "http://www.example.com/").body).to eq("non-global stub body")
611
+ end
612
+ end
596
613
  end
597
614
 
598
615
  describe "when stubbing request with a block evaluated on request" do
data/webmock.gemspec CHANGED
@@ -45,6 +45,7 @@ Gem::Specification.new do |s|
45
45
  s.add_development_dependency 'minitest', '>= 5.0.0'
46
46
  s.add_development_dependency 'test-unit', '>= 3.0.0'
47
47
  s.add_development_dependency 'rdoc', '> 3.5.0'
48
+ s.add_development_dependency 'webrick'
48
49
 
49
50
  s.files = `git ls-files`.split("\n")
50
51
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
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.5
4
+ version: 3.11.3
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-09 00:00:00.000000000 Z
11
+ date: 2021-02-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: addressable
@@ -254,6 +254,20 @@ dependencies:
254
254
  - - ">"
255
255
  - !ruby/object:Gem::Version
256
256
  version: 3.5.0
257
+ - !ruby/object:Gem::Dependency
258
+ name: webrick
259
+ requirement: !ruby/object:Gem::Requirement
260
+ requirements:
261
+ - - ">="
262
+ - !ruby/object:Gem::Version
263
+ version: '0'
264
+ type: :development
265
+ prerelease: false
266
+ version_requirements: !ruby/object:Gem::Requirement
267
+ requirements:
268
+ - - ">="
269
+ - !ruby/object:Gem::Version
270
+ version: '0'
257
271
  description: WebMock allows stubbing HTTP requests and setting expectations on HTTP
258
272
  requests.
259
273
  email:
@@ -263,6 +277,7 @@ extensions: []
263
277
  extra_rdoc_files: []
264
278
  files:
265
279
  - ".gemtest"
280
+ - ".github/workflows/CI.yml"
266
281
  - ".gitignore"
267
282
  - ".rspec-tm"
268
283
  - ".travis.yml"
@@ -407,9 +422,9 @@ licenses:
407
422
  - MIT
408
423
  metadata:
409
424
  bug_tracker_uri: https://github.com/bblimke/webmock/issues
410
- changelog_uri: https://github.com/bblimke/webmock/blob/v3.9.5/CHANGELOG.md
411
- documentation_uri: https://www.rubydoc.info/gems/webmock/3.9.5
412
- source_code_uri: https://github.com/bblimke/webmock/tree/v3.9.5
425
+ changelog_uri: https://github.com/bblimke/webmock/blob/v3.11.3/CHANGELOG.md
426
+ documentation_uri: https://www.rubydoc.info/gems/webmock/3.11.3
427
+ source_code_uri: https://github.com/bblimke/webmock/tree/v3.11.3
413
428
  wiki_uri: https://github.com/bblimke/webmock/wiki
414
429
  post_install_message:
415
430
  rdoc_options: []