webmock 3.4.2 → 3.5.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
- SHA1:
3
- metadata.gz: 91d9ae63bf5035f1d5ca0279cd0a8f4ec3ea80e9
4
- data.tar.gz: b59813f02e62e3f5fa9b86e396d6da32f61f1a35
2
+ SHA256:
3
+ metadata.gz: 2fcd3ec57f1f8be3dbf2685777853444680221a9c0230e6c068d3581bfb831a4
4
+ data.tar.gz: c14190f8962b927f5d1c5493db24a226c6cc56d54aff9d34589e7fa3adbf44b5
5
5
  SHA512:
6
- metadata.gz: 576e5b246b09980d0a371a3b83468ef8d715917b29d1f6bc07fbb0c7398346c7effbcd3a9b8a6dcf9634f9531d49f8b85fe9f196f5afcaddbddc1cc6be5cb5c7
7
- data.tar.gz: 19eb107133e2f8a12bf9859fd0cf444afe78d8d6da3057d93928344e2d67c8c99ccd2554d749dcae94f4cad3ebea915ba54b8f5296c42d7a8809023f10e242dc
6
+ metadata.gz: 7ed35459642359c3dc62cae4016b636110432e2bef6b6047acc5bb11d7ffa6dd180cb8938ad6e6dc522a4cb3429150ad7533e442df5fe8ab2fc3b9638126da7c
7
+ data.tar.gz: 2e7ebfc8da28d95acf8477b7166dba7e19657ba5d8fd7c4f44ae19985d216c639250c6c7ff47e2b65b007f58791f0116509a15f98b8babd75fd0acb66d00ca1d
@@ -2,14 +2,14 @@ before_install:
2
2
  - gem update --system
3
3
  - gem update bundler
4
4
  rvm:
5
- - 2.2.8
6
- - 2.3.5
7
- - 2.4.2
8
- - 2.5.0
5
+ - 2.3.8
6
+ - 2.4.5
7
+ - 2.5.3
8
+ - 2.6.0
9
9
  - rbx-2
10
10
  - ruby-head
11
- - jruby-9.0.5.0
12
- - jruby-9.1.13.0
11
+ - jruby-9.1.17.0
12
+ - jruby-9.2.5.0
13
13
  - jruby-head
14
14
  matrix:
15
15
  allow_failures:
@@ -1,5 +1,25 @@
1
1
  # Changelog
2
2
 
3
+ ## 3.5.0
4
+
5
+ * Ruby 2.6.0 support
6
+
7
+ Thanks to [Arkadiy Tetelman](https://github.com/arkadiyt)
8
+
9
+ * Added `WebMock.reset_executed_requests!` method.
10
+
11
+ stub_get = stub_request(:get, "www.example.com")
12
+ Net::HTTP.get('www.example.com', '/')
13
+ WebMock::RequestRegistry.instance.times_executed(stub_get.request_pattern) # => 1
14
+ reset_executed_requests!
15
+ WebMock::RequestRegistry.instance.times_executed(stub_get.request_pattern) # => 0
16
+
17
+ Thanks to [Olia Kremmyda](https://github.com/oliakremmyda)
18
+
19
+ * Performance improvements
20
+
21
+ Thanks to [Pavel Rosický](https://github.com/ahorek)
22
+
3
23
  ## 3.4.2
4
24
 
5
25
  * Fixed `rbuf_fill` in Net::HTTP adapter to be thread-safe
data/README.md CHANGED
@@ -705,6 +705,28 @@ Net::HTTP.get('www.example.com', '/') # ===> Failure
705
705
  assert_not_requested :get, "www.example.com" # ===> Success
706
706
  ```
707
707
 
708
+ ## Clearing request counters
709
+
710
+ If you want to reset **only** the counters of the executed requests use `WebMock.reset_executed_requests!`
711
+
712
+ ```ruby
713
+ stub = stub_request(:get, "www.example.com")
714
+ stub2 = stub_request(:get, "www.example2.com")
715
+
716
+ Net::HTTP.get('www.example.com', '/')
717
+ Net::HTTP.get('www.example.com', '/')
718
+
719
+ Net::HTTP.get('www.example2.com', '/')
720
+
721
+ expect(stub).to have_been_requested.times(2)
722
+ expect(stub2).to have_been_requested.times(1)
723
+
724
+ WebMock.reset_executed_requests!
725
+
726
+ expect(stub).not_to have_been_requested
727
+ expect(stub2).not_to have_been_requested
728
+ ```
729
+
708
730
  ## Disabling and enabling WebMock or only some http client adapters
709
731
 
710
732
  ```ruby
@@ -1058,6 +1080,9 @@ People who submitted patches and new features or suggested improvements. Many th
1058
1080
  * Lukas Pokorny
1059
1081
  * Arkadiy Tetelman
1060
1082
  * Kazato Sugimoto
1083
+ * Olle Jonsson
1084
+ * Pavel Rosický
1085
+ * Geremia Taglialatela
1061
1086
 
1062
1087
  For a full list of contributors you can visit the
1063
1088
  [contributors](https://github.com/bblimke/webmock/contributors) page.
@@ -4,55 +4,55 @@ require 'addressable/uri'
4
4
  require 'addressable/template'
5
5
  require 'crack/xml'
6
6
 
7
- require 'webmock/deprecation'
8
- require 'webmock/version'
9
-
10
- require 'webmock/errors'
11
-
12
- require 'webmock/util/query_mapper'
13
- require 'webmock/util/uri'
14
- require 'webmock/util/headers'
15
- require 'webmock/util/hash_counter'
16
- require 'webmock/util/hash_keys_stringifier'
17
- require 'webmock/util/values_stringifier'
18
- require 'webmock/util/json'
19
- require 'webmock/util/version_checker'
20
- require 'webmock/util/hash_validator'
21
-
22
- require 'webmock/matchers/hash_argument_matcher'
23
- require 'webmock/matchers/hash_excluding_matcher'
24
- require 'webmock/matchers/hash_including_matcher'
25
- require 'webmock/matchers/any_arg_matcher'
26
-
27
- require 'webmock/request_pattern'
28
- require 'webmock/request_signature'
29
- require 'webmock/responses_sequence'
30
- require 'webmock/request_stub'
31
- require 'webmock/response'
32
- require 'webmock/rack_response'
33
-
34
- require 'webmock/stub_request_snippet'
35
- require 'webmock/request_signature_snippet'
36
- require 'webmock/request_body_diff'
37
-
38
- require 'webmock/assertion_failure'
39
- require 'webmock/request_execution_verifier'
40
- require 'webmock/config'
41
- require 'webmock/callback_registry'
42
- require 'webmock/request_registry'
43
- require 'webmock/stub_registry'
44
- require 'webmock/api'
45
-
46
- require 'webmock/http_lib_adapters/http_lib_adapter_registry'
47
- require 'webmock/http_lib_adapters/http_lib_adapter'
48
- require 'webmock/http_lib_adapters/net_http'
49
- require 'webmock/http_lib_adapters/http_rb_adapter'
50
- require 'webmock/http_lib_adapters/httpclient_adapter'
51
- require 'webmock/http_lib_adapters/patron_adapter'
52
- require 'webmock/http_lib_adapters/curb_adapter'
53
- require 'webmock/http_lib_adapters/em_http_request_adapter'
54
- require 'webmock/http_lib_adapters/typhoeus_hydra_adapter'
55
- require 'webmock/http_lib_adapters/excon_adapter'
56
- require 'webmock/http_lib_adapters/manticore_adapter'
57
-
58
- require 'webmock/webmock'
7
+ require_relative 'webmock/deprecation'
8
+ require_relative 'webmock/version'
9
+
10
+ require_relative 'webmock/errors'
11
+
12
+ require_relative 'webmock/util/query_mapper'
13
+ require_relative 'webmock/util/uri'
14
+ require_relative 'webmock/util/headers'
15
+ require_relative 'webmock/util/hash_counter'
16
+ require_relative 'webmock/util/hash_keys_stringifier'
17
+ require_relative 'webmock/util/values_stringifier'
18
+ require_relative 'webmock/util/json'
19
+ require_relative 'webmock/util/version_checker'
20
+ require_relative 'webmock/util/hash_validator'
21
+
22
+ require_relative 'webmock/matchers/hash_argument_matcher'
23
+ require_relative 'webmock/matchers/hash_excluding_matcher'
24
+ require_relative 'webmock/matchers/hash_including_matcher'
25
+ require_relative 'webmock/matchers/any_arg_matcher'
26
+
27
+ require_relative 'webmock/request_pattern'
28
+ require_relative 'webmock/request_signature'
29
+ require_relative 'webmock/responses_sequence'
30
+ require_relative 'webmock/request_stub'
31
+ require_relative 'webmock/response'
32
+ require_relative 'webmock/rack_response'
33
+
34
+ require_relative 'webmock/stub_request_snippet'
35
+ require_relative 'webmock/request_signature_snippet'
36
+ require_relative 'webmock/request_body_diff'
37
+
38
+ require_relative 'webmock/assertion_failure'
39
+ require_relative 'webmock/request_execution_verifier'
40
+ require_relative 'webmock/config'
41
+ require_relative 'webmock/callback_registry'
42
+ require_relative 'webmock/request_registry'
43
+ require_relative 'webmock/stub_registry'
44
+ require_relative 'webmock/api'
45
+
46
+ require_relative 'webmock/http_lib_adapters/http_lib_adapter_registry'
47
+ require_relative 'webmock/http_lib_adapters/http_lib_adapter'
48
+ require_relative 'webmock/http_lib_adapters/net_http'
49
+ require_relative 'webmock/http_lib_adapters/http_rb_adapter'
50
+ require_relative 'webmock/http_lib_adapters/httpclient_adapter'
51
+ require_relative 'webmock/http_lib_adapters/patron_adapter'
52
+ require_relative 'webmock/http_lib_adapters/curb_adapter'
53
+ require_relative 'webmock/http_lib_adapters/em_http_request_adapter'
54
+ require_relative 'webmock/http_lib_adapters/typhoeus_hydra_adapter'
55
+ require_relative 'webmock/http_lib_adapters/excon_adapter'
56
+ require_relative 'webmock/http_lib_adapters/manticore_adapter'
57
+
58
+ require_relative 'webmock/webmock'
@@ -66,6 +66,10 @@ module WebMock
66
66
  WebMock::StubRegistry.instance.remove_request_stub(stub)
67
67
  end
68
68
 
69
+ def reset_executed_requests!
70
+ WebMock::RequestRegistry.instance.reset!
71
+ end
72
+
69
73
  private
70
74
 
71
75
  def convert_uri_method_and_options_to_request_and_options(method, uri, options, &block)
@@ -256,8 +256,9 @@ end
256
256
  module Net #:nodoc: all
257
257
 
258
258
  class WebMockNetBufferedIO < BufferedIO
259
- def initialize(io, read_timeout: 60, continue_timeout: nil, debug_output: nil)
259
+ def initialize(io, read_timeout: 60, write_timeout: 60, continue_timeout: nil, debug_output: nil)
260
260
  @read_timeout = read_timeout
261
+ @write_timeout = write_timeout
261
262
  @rbuf = ''.dup
262
263
  @debug_output = debug_output
263
264
 
@@ -25,7 +25,7 @@ module WebMock
25
25
  responses = {}
26
26
 
27
27
  stub = ::WebMock::RequestStub.new(:any, /.*/).with { |request|
28
- responses[request.object_id] = block.call(request)
28
+ responses[request.object_id] = yield(request)
29
29
  }.to_return(lambda { |request| responses.delete(request.object_id) })
30
30
 
31
31
  global_stubs.push stub
@@ -30,8 +30,8 @@ module WebMock
30
30
  end
31
31
 
32
32
  def each(&block)
33
- @order.to_a.sort {|a, b| a[1] <=> b[1]}.each do |a|
34
- block.call(a[0], hash[a[0]])
33
+ @order.to_a.sort_by { |a| a[1] }.each do |a|
34
+ yield(a[0], hash[a[0]])
35
35
  end
36
36
  end
37
37
  end
@@ -81,7 +81,7 @@ module WebMock::Util
81
81
  value = if value.nil?
82
82
  nil
83
83
  else
84
- ::Addressable::URI.unencode_component(value.gsub(/\+/, ' '))
84
+ ::Addressable::URI.unencode_component(value.tr('+', ' '))
85
85
  end
86
86
  key = Addressable::URI.unencode_component(key)
87
87
  key = key.dup.force_encoding(Encoding::ASCII_8BIT) if key.respond_to?(:force_encoding)
@@ -1,3 +1,3 @@
1
1
  module WebMock
2
- VERSION = '3.4.2' unless defined?(::WebMock::VERSION)
2
+ VERSION = '3.5.0' unless defined?(::WebMock::VERSION)
3
3
  end
@@ -20,7 +20,8 @@ describe "Excon" do
20
20
  it "should support excon response_block for real requests", net_connect: true do
21
21
  a = []
22
22
  WebMock.allow_net_connect!
23
- r = Excon.new('http://httpstat.us/200').get(response_block: lambda {|e, remaining, total| a << e}, chunk_size: 1)
23
+ r = Excon.new('http://httpstat.us/200', headers: { "Accept" => "*" }).
24
+ get(response_block: lambda {|e, remaining, total| a << e}, chunk_size: 1)
24
25
  expect(a).to eq(["2", "0", "0", " ", "O", "K"])
25
26
  expect(r.body).to eq("")
26
27
  end
@@ -40,7 +41,8 @@ describe "Excon" do
40
41
  WebMock.after_request { |_, res|
41
42
  response = res
42
43
  }
43
- r = Excon.new('http://httpstat.us/200').get(response_block: lambda {|e, remaining, total| a << e}, chunk_size: 1)
44
+ r = Excon.new('http://httpstat.us/200', headers: { "Accept" => "*" }).
45
+ get(response_block: lambda {|e, remaining, total| a << e}, chunk_size: 1)
44
46
  expect(response.body).to eq("200 OK")
45
47
  expect(a).to eq(["2", "0", "0", " ", "O", "K"])
46
48
  expect(r.body).to eq("")
@@ -102,7 +102,7 @@ shared_context "callbacks" do |*adapter_info|
102
102
  WebMock.after_request(except: [:other_lib]) do |_, response|
103
103
  @response = response
104
104
  end
105
- http_request(:get, "http://httpstat.us/201")
105
+ http_request(:get, "http://httpstat.us/201", headers: { "Accept" => "*" })
106
106
  end
107
107
 
108
108
  it "should pass real response to callback with status and message" do
@@ -153,4 +153,23 @@ describe WebMock::API do
153
153
  end
154
154
  end
155
155
  end
156
+
157
+ describe '#reset_executed_requests!' do
158
+ subject { WebMock::API.reset_executed_requests! }
159
+
160
+ let(:request_signature) { WebMock::RequestSignature.new(:get, "www.example.com") }
161
+ let(:request_pattern) { WebMock::RequestPattern.new(:get, "www.example.com") }
162
+
163
+ before do
164
+ WebMock::RequestRegistry.instance.requested_signatures.put(request_signature)
165
+ end
166
+
167
+ it 'resets request registry counter' do
168
+ expect{
169
+ subject
170
+ }.to change{
171
+ WebMock::RequestRegistry.instance.times_executed(request_pattern)
172
+ }.from(1).to(0)
173
+ end
174
+ end
156
175
  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.4.2
4
+ version: 3.5.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: 2018-06-03 00:00:00.000000000 Z
11
+ date: 2018-12-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: addressable
@@ -399,7 +399,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
399
399
  version: '0'
400
400
  requirements: []
401
401
  rubyforge_project: webmock
402
- rubygems_version: 2.6.11
402
+ rubygems_version: 2.7.6
403
403
  signing_key:
404
404
  specification_version: 4
405
405
  summary: Library for stubbing HTTP requests in Ruby.