webmock 3.9.5 → 3.10.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e86a9ca126d1410e47a219ea054f8591fe421e303deb27366b0705c88d37484f
4
- data.tar.gz: 8e35153a6620d376d86cf37c3ab85060f38265cc9c110ce6f5adbc3120af0fdf
3
+ metadata.gz: 18f78451e2de5c81e96da75d822f7bb1559f4c9f02e80a383758b9c4ef9be1c3
4
+ data.tar.gz: b245cfea73c1924eaeaad716c487f8548b392d120c28ff0f513da71a63d65944
5
5
  SHA512:
6
- metadata.gz: 3af5f5d03fe560dbbdf8cb974ed913568bfb8964372c44d705ae6b8956a66f9095723e9a6c8845b7fb9ce6894047cb5662c6d01f5ae832e62a17cd6bf681e6c9
7
- data.tar.gz: bae8f2a18cf86174308dc4ab14305aca3586853e67a9b27a4fbdefbb5abee31c54ec734ff42f22a1fa974e233d69516eea96a669a511cbb342bda2e2f062e3fa
6
+ metadata.gz: 494e56d26e2d83828629de2901e0b1e0234a043261e19bd9080d4326e2812fc699cf7ee3817c8b86b3f99603a1a91918bd1d8474bba10fddefd6cf96565a7869
7
+ data.tar.gz: bb92e415f29748dbb63830bff8231607e599c0082d527513f4c02180dda83930fad830750978be6e59ed206122aeb77f7a48e4603e578fa26aa49f6b143087dd
@@ -1,5 +1,19 @@
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
+
3
17
  # 3.9.5
4
18
 
5
19
  * Prevent overwriting `teardown` method in Test::Unit
data/README.md CHANGED
@@ -1150,6 +1150,7 @@ 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
1153
1154
 
1154
1155
  For a full list of contributors you can visit the
1155
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)
@@ -1,3 +1,3 @@
1
1
  module WebMock
2
- VERSION = '3.9.5' 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
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.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-09 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.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
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: []