webmock 3.9.4 → 3.10.0

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: d3a3b9d4cdfb5b9471c673ef6a3cab7e4be5e98d9115a72abf251f0bceed08b9
4
- data.tar.gz: d71b867845cc6c805af1af7e5d7b138ecde29310521735692470aabdc5b32c17
3
+ metadata.gz: 18f78451e2de5c81e96da75d822f7bb1559f4c9f02e80a383758b9c4ef9be1c3
4
+ data.tar.gz: b245cfea73c1924eaeaad716c487f8548b392d120c28ff0f513da71a63d65944
5
5
  SHA512:
6
- metadata.gz: 0bea34ef2c38c8896562c31580f08a3043db6ce2e4d61ef73a6eb42b9a1533ab7441f8e4e16d31b34a5ebace2d00b24ffc93bc7cf4fe700d2e5bd95a3d5064fb
7
- data.tar.gz: 22658ff730ad2c05fe374e148c1c97f13e64bbe9c02a2b4aba21682a0e7ef23dc477b804e6a1e48fbbe4d717d0d212af4db4e57a3a607d6afae315f2625d5f6e
6
+ metadata.gz: 494e56d26e2d83828629de2901e0b1e0234a043261e19bd9080d4326e2812fc699cf7ee3817c8b86b3f99603a1a91918bd1d8474bba10fddefd6cf96565a7869
7
+ data.tar.gz: bb92e415f29748dbb63830bff8231607e599c0082d527513f4c02180dda83930fad830750978be6e59ed206122aeb77f7a48e4603e578fa26aa49f6b143087dd
@@ -1,5 +1,25 @@
1
1
  # Changelog
2
2
 
3
+ # 3.10.0
4
+
5
+ * Added option to global stubs to have lower priority than local stubs.
6
+
7
+ WebMock.globally_stub_request(:after_local_stubs) do
8
+ { body: "global stub body" }
9
+ end
10
+
11
+ stub_request(:get, "www.example.com").to_return(body: 'non-global stub body')
12
+
13
+ expect(http_request(:get, "http://www.example.com/").body).to eq("non-global stub body")
14
+
15
+ Thanks to [Marek Kasztelnik](https://github.com/mkasztelnik)
16
+
17
+ # 3.9.5
18
+
19
+ * Prevent overwriting `teardown` method in Test::Unit
20
+
21
+ Thanks to [Jesse Bowes](https://github.com/jessebs)
22
+
3
23
  # 3.9.4
4
24
 
5
25
  * More intuitive error message when stubbed response body was provided as Hash
data/README.md CHANGED
@@ -1149,6 +1149,8 @@ People who submitted patches and new features or suggested improvements. Many th
1149
1149
  * Ryan Kerr
1150
1150
  * Adam Harwood
1151
1151
  * Ben Koshy
1152
+ * Jesse Bowes
1153
+ * Marek Kasztelnik
1152
1154
 
1153
1155
  For a full list of contributors you can visit the
1154
1156
  [contributors](https://github.com/bblimke/webmock/contributors) page.
@@ -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)
@@ -8,12 +8,10 @@ module Test
8
8
  class TestCase
9
9
  include WebMock::API
10
10
 
11
- alias_method :teardown_without_webmock, :teardown
11
+ teardown
12
12
  def teardown_with_webmock
13
- teardown_without_webmock
14
13
  WebMock.reset!
15
14
  end
16
- alias_method :teardown, :teardown_with_webmock
17
15
 
18
16
  end
19
17
  end
@@ -1,3 +1,3 @@
1
1
  module WebMock
2
- VERSION = '3.9.4' unless defined?(::WebMock::VERSION)
2
+ VERSION = '3.10.0' 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(
@@ -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
@@ -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
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
4
+ version: 3.10.0
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-05 00:00:00.000000000 Z
11
+ date: 2020-11-12 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.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
410
+ changelog_uri: https://github.com/bblimke/webmock/blob/v3.10.0/CHANGELOG.md
411
+ documentation_uri: https://www.rubydoc.info/gems/webmock/3.10.0
412
+ source_code_uri: https://github.com/bblimke/webmock/tree/v3.10.0
413
413
  wiki_uri: https://github.com/bblimke/webmock/wiki
414
414
  post_install_message:
415
415
  rdoc_options: []