webmock 3.8.3 → 3.9.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: 0c101b3661b9aeb49e30e85da73705637944747d62eef4d463a9c30866431b10
4
- data.tar.gz: 3c2a7ae9e28143b97b83c5a93cc14950748dc68969790d80f0d62a28600d7a5a
3
+ metadata.gz: 603d6344674ad0d4b41e3b9fb2523d0d629f781873e0b5ac6dc72331ce30139a
4
+ data.tar.gz: 034c21429d7b11336d59485f198abb0b61f3dce89ec59c2298bb81d1f8cd987e
5
5
  SHA512:
6
- metadata.gz: 60174ed92a21c2f304d29e4d00edb7447eae871b37ddc2bb6b0a4704bf42492c9632913cee2c040644e6decc95242f39bf32728fe0df3b34d936cc9f78a42f2f
7
- data.tar.gz: e7c4dc5363ec3f8028852b1d2173b214742bc03ca2ee25599a6d38d8c3a291f517890168dc74a69cd4f90f3f840e94fdd857941ab853a833ae5d77bc8282e464
6
+ metadata.gz: e4a36fc1d613f0187c361d4d1fed3a3c2f082496839b1af649a752916fa9e1285a8261aec34fe25a236a35d930782a5b6cd62de919481e99198390b65407577d
7
+ data.tar.gz: c3b93eaaa8f3a513e54d90f179ced6b48f08805232060ebd2cf41407bdd2f000d5cd8a01e584237bb634ad0ca5a00607d000ec7c257b51ebdbe96790937cc7ae
@@ -1,19 +1,24 @@
1
1
  before_install:
2
2
  - gem update --system -N
3
3
  rvm:
4
- - 2.3.8
5
- - 2.4.6
6
4
  - 2.5.5
7
5
  - 2.6.3
8
6
  - 2.7.0
9
7
  - rbx-2
10
8
  - ruby-head
11
- - jruby-9.1.17.0
12
- - jruby-9.2.7.0
13
- - jruby-head
14
- jdk: openjdk8
15
9
  matrix:
10
+ include:
11
+ - rvm: jruby-9.1.17.0
12
+ jdk: openjdk8
13
+ - rvm: jruby-9.2.11.1
14
+ jdk: openjdk11
15
+ - rvm: jruby-head
16
+ jdk: openjdk11
16
17
  allow_failures:
17
18
  - rvm: jruby-head
18
19
  - rvm: ruby-head
19
20
  - rvm: rbx-2
21
+ env:
22
+ global:
23
+ JRUBY_OPTS: "--debug"
24
+
@@ -1,5 +1,41 @@
1
1
  # Changelog
2
2
 
3
+ ## 3.9.0
4
+
5
+ * Allow using a "callable" (like a proc) as URI pattern
6
+
7
+ stub_request(:any, ->(uri) { true })
8
+
9
+ Thanks to [John Hawthorn](https://github.com/jhawthorn)
10
+
11
+ * Added stubbed IO on stubbed socket in Net::HTTP adapter.
12
+
13
+ Thanks to [Thilo Rusche](https://github.com/trusche)
14
+
15
+ * When 'webmock/rspec' is required, reset WebMock after all after(:each/example) hooks
16
+
17
+ Thanks to [Andrew Stuntz](https://github.com/drews256)
18
+
19
+ * Fixed `net_connect_allowed?` when invoked with no arguments, when there were any allowed URIs passed to `disable_net_connect?`.
20
+
21
+ Thanks to [Lucas Uyezu](https://github.com/lucasuyezu)
22
+
23
+ * Fixed async-http adapter which caused Async::HTTP::Client or Async::HTTP::Internet to hang and never return a response.
24
+
25
+ Thanks to (Bruno Sutic)[https://github.com/bruno-] and [Samuel Williams](https://github.com/ioquatix)
26
+
27
+ * Fixed warning when using async-http adapter
28
+
29
+ Thanks to (Bruno Sutic)[https://github.com/bruno-]
30
+
31
+ * Dropped support for Ruby 2.3 - EOL date: 2019-03-31
32
+
33
+ * Dropped support for Ruby 2.4 - EOL date: 2020-03-31
34
+
35
+ * Handling matching of Addressable::Template patterns that have an ip address without port and patterns that have ip address and don’t have schema and path.
36
+
37
+ Thanks to (Rafael França)[https://github.com/rafaelfranca] and (guppy0356)[https://github.com/guppy0356]
38
+
3
39
  ## 3.8.3
4
40
 
5
41
  * Fixed problem introduced in version 3.4.2, which caused matching against Addressable::Template representing host part of the URI to raise an error.
data/README.md CHANGED
@@ -38,9 +38,6 @@ Supported HTTP libraries
38
38
  Supported Ruby Interpreters
39
39
  ---------------------------
40
40
 
41
- * MRI 2.2
42
- * MRI 2.3
43
- * MRI 2.4
44
41
  * MRI 2.5
45
42
  * MRI 2.6
46
43
  * MRI 2.7
@@ -243,6 +240,12 @@ stub_request(:any, /example/)
243
240
  Net::HTTP.get('www.example.com', '/') # ===> Success
244
241
  ```
245
242
 
243
+ ### Matching uris using lambda
244
+
245
+ ```ruby
246
+ stub_request(:any, ->(uri) { true })
247
+ ```
248
+
246
249
  ### Matching uris using RFC 6570 - Basic Example
247
250
 
248
251
  ```ruby
@@ -300,6 +303,12 @@ stub_request(:any, "www.example.com").
300
303
  Net::HTTP.get("www.example.com", '/') # ===> "abc"
301
304
  ```
302
305
 
306
+ Set appropriate Content-Type for HTTParty's `parsed_response`.
307
+
308
+ ```ruby
309
+ stub_request(:any, "www.example.com").to_return body: '{}', headers: {content_type: 'application/json'}
310
+ ```
311
+
303
312
  ### Response with body specified as IO object
304
313
 
305
314
  ```ruby
@@ -1121,6 +1130,12 @@ People who submitted patches and new features or suggested improvements. Many th
1121
1130
  * Patrik Ragnarsson
1122
1131
  * Alex Coomans
1123
1132
  * Vesa Laakso
1133
+ * John Hawthorn
1134
+ * guppy0356
1135
+ * Thilo Rusche
1136
+ * Andrew Stuntz
1137
+ * Lucas Uyezu
1138
+ * Bruno Sutic
1124
1139
 
1125
1140
  For a full list of contributors you can visit the
1126
1141
  [contributors](https://github.com/bblimke/webmock/contributors) page.
@@ -136,7 +136,7 @@ if defined?(Async::HTTP)
136
136
 
137
137
  def connect
138
138
  server_socket, client_socket = create_connected_sockets
139
- Async do
139
+ Async(transient: true) do
140
140
  accept_socket(server_socket)
141
141
  end
142
142
  client_socket
@@ -151,7 +151,7 @@ if defined?(Async::HTTP)
151
151
  def create_connected_sockets
152
152
  Async::IO::Socket.pair(Socket::AF_UNIX, Socket::SOCK_STREAM).tap do |sockets|
153
153
  sockets.each do |socket|
154
- socket.instance_variable_set :@alpn_protocol, @alpn_protocol
154
+ socket.instance_variable_set :@alpn_protocol, nil
155
155
  socket.instance_eval do
156
156
  def alpn_protocol
157
157
  nil # means HTTP11 will be used for HTTPS
@@ -252,6 +252,13 @@ class StubSocket #:nodoc:
252
252
  def readuntil(*args)
253
253
  end
254
254
 
255
+ def io
256
+ @io ||= StubIO.new
257
+ end
258
+
259
+ class StubIO
260
+ def setsockopt(*args); end
261
+ end
255
262
  end
256
263
 
257
264
  module Net #:nodoc: all
@@ -80,6 +80,8 @@ module WebMock
80
80
  URIRegexpPattern.new(uri)
81
81
  elsif uri.is_a?(Addressable::Template)
82
82
  URIAddressablePattern.new(uri)
83
+ elsif uri.respond_to?(:call)
84
+ URICallablePattern.new(uri)
83
85
  else
84
86
  URIStringPattern.new(uri)
85
87
  end
@@ -108,10 +110,10 @@ module WebMock
108
110
 
109
111
  def initialize(pattern)
110
112
  @pattern = case pattern
111
- when Addressable::URI, Addressable::Template
112
- pattern
113
+ when String
114
+ WebMock::Util::URI.normalize_uri(pattern)
113
115
  else
114
- WebMock::Util::URI.normalize_uri(pattern)
116
+ pattern
115
117
  end
116
118
  @query_params = nil
117
119
  end
@@ -131,38 +133,44 @@ module WebMock
131
133
  end
132
134
  end
133
135
 
136
+ def matches?(uri)
137
+ pattern_matches?(uri) && query_params_matches?(uri)
138
+ end
139
+
134
140
  def to_s
135
- str = @pattern.inspect
141
+ str = pattern_inspect
136
142
  str += " with query params #{@query_params.inspect}" if @query_params
137
143
  str
138
144
  end
139
- end
140
145
 
141
- class URIRegexpPattern < URIPattern
142
- def matches?(uri)
143
- WebMock::Util::URI.variations_of_uri_as_strings(uri).any? { |u| u.match(@pattern) } &&
144
- (@query_params.nil? || @query_params == WebMock::Util::QueryMapper.query_to_values(uri.query, notation: Config.instance.query_values_notation))
146
+ private
147
+
148
+ def pattern_inspect
149
+ @pattern.inspect
145
150
  end
146
151
 
147
- def to_s
148
- str = @pattern.inspect
149
- str += " with query params #{@query_params.inspect}" if @query_params
150
- str
152
+ def query_params_matches?(uri)
153
+ @query_params.nil? || @query_params == WebMock::Util::QueryMapper.query_to_values(uri.query, notation: Config.instance.query_values_notation)
151
154
  end
152
155
  end
153
156
 
154
- class URIAddressablePattern < URIPattern
155
- def matches?(uri)
156
- if @query_params.nil?
157
- # Let Addressable check the whole URI
158
- matches_with_variations?(uri)
159
- else
160
- # WebMock checks the query, Addressable checks everything else
161
- matches_with_variations?(uri.omit(:query)) &&
162
- @query_params == WebMock::Util::QueryMapper.query_to_values(uri.query)
163
- end
157
+ class URICallablePattern < URIPattern
158
+ private
159
+
160
+ def pattern_matches?(uri)
161
+ @pattern.call(uri)
164
162
  end
163
+ end
165
164
 
165
+ class URIRegexpPattern < URIPattern
166
+ private
167
+
168
+ def pattern_matches?(uri)
169
+ WebMock::Util::URI.variations_of_uri_as_strings(uri).any? { |u| u.match(@pattern) }
170
+ end
171
+ end
172
+
173
+ class URIAddressablePattern < URIPattern
166
174
  def add_query_params(query_params)
167
175
  @@add_query_params_warned ||= false
168
176
  if not @@add_query_params_warned
@@ -172,13 +180,21 @@ module WebMock
172
180
  super(query_params)
173
181
  end
174
182
 
175
- def to_s
176
- str = @pattern.pattern.inspect
177
- str += " with variables #{@pattern.variables.inspect}" if @pattern.variables
178
- str
183
+ private
184
+
185
+ def pattern_matches?(uri)
186
+ if @query_params.nil?
187
+ # Let Addressable check the whole URI
188
+ matches_with_variations?(uri)
189
+ else
190
+ # WebMock checks the query, Addressable checks everything else
191
+ matches_with_variations?(uri.omit(:query))
192
+ end
179
193
  end
180
194
 
181
- private
195
+ def pattern_inspect
196
+ @pattern.pattern.inspect
197
+ end
182
198
 
183
199
  def matches_with_variations?(uri)
184
200
  template =
@@ -187,16 +203,34 @@ module WebMock
187
203
  rescue Addressable::URI::InvalidURIError
188
204
  Addressable::Template.new(@pattern.pattern)
189
205
  end
190
- WebMock::Util::URI.variations_of_uri_as_strings(uri).any? { |u| template.match(u) }
206
+ WebMock::Util::URI.variations_of_uri_as_strings(uri).any? { |u|
207
+ template_matches_uri?(template, u)
208
+ }
209
+ end
210
+
211
+ def template_matches_uri?(template, uri)
212
+ template.match(uri)
213
+ rescue Addressable::URI::InvalidURIError
214
+ false
191
215
  end
192
216
  end
193
217
 
194
218
  class URIStringPattern < URIPattern
195
- def matches?(uri)
219
+ def add_query_params(query_params)
220
+ super
221
+ if @query_params.is_a?(Hash) || @query_params.is_a?(String)
222
+ query_hash = (WebMock::Util::QueryMapper.query_to_values(@pattern.query, notation: Config.instance.query_values_notation) || {}).merge(@query_params)
223
+ @pattern.query = WebMock::Util::QueryMapper.values_to_query(query_hash, notation: WebMock::Config.instance.query_values_notation)
224
+ @query_params = nil
225
+ end
226
+ end
227
+
228
+ private
229
+
230
+ def pattern_matches?(uri)
196
231
  if @pattern.is_a?(Addressable::URI)
197
232
  if @query_params
198
- uri.omit(:query) === @pattern &&
199
- (@query_params.nil? || @query_params == WebMock::Util::QueryMapper.query_to_values(uri.query, notation: Config.instance.query_values_notation))
233
+ uri.omit(:query) === @pattern
200
234
  else
201
235
  uri === @pattern
202
236
  end
@@ -205,19 +239,8 @@ module WebMock
205
239
  end
206
240
  end
207
241
 
208
- def add_query_params(query_params)
209
- super
210
- if @query_params.is_a?(Hash) || @query_params.is_a?(String)
211
- query_hash = (WebMock::Util::QueryMapper.query_to_values(@pattern.query, notation: Config.instance.query_values_notation) || {}).merge(@query_params)
212
- @pattern.query = WebMock::Util::QueryMapper.values_to_query(query_hash, notation: WebMock::Config.instance.query_values_notation)
213
- @query_params = nil
214
- end
215
- end
216
-
217
- def to_s
218
- str = WebMock::Util::URI.strip_default_port_from_uri_string(@pattern.to_s)
219
- str += " with query params #{@query_params.inspect}" if @query_params
220
- str
242
+ def pattern_inspect
243
+ WebMock::Util::URI.strip_default_port_from_uri_string(@pattern.to_s)
221
244
  end
222
245
  end
223
246
 
@@ -33,7 +33,8 @@ RSPEC_CONFIGURER.configure { |config|
33
33
  WebMock.disable!
34
34
  end
35
35
 
36
- config.after(:each) do
36
+ config.around(:each) do |example|
37
+ example.run
37
38
  WebMock.reset!
38
39
  end
39
40
  }
@@ -24,7 +24,7 @@ module WebMock
24
24
  # doesn't run immediately after stub.with.
25
25
  responses = {}
26
26
 
27
- stub = ::WebMock::RequestStub.new(:any, /.*/).with { |request|
27
+ stub = ::WebMock::RequestStub.new(:any, ->(uri) { true }).with { |request|
28
28
  responses[request.object_id] = yield(request)
29
29
  }.to_return(lambda { |request| responses.delete(request.object_id) })
30
30
 
@@ -1,3 +1,3 @@
1
1
  module WebMock
2
- VERSION = '3.8.3' unless defined?(::WebMock::VERSION)
2
+ VERSION = '3.9.0' unless defined?(::WebMock::VERSION)
3
3
  end
@@ -59,11 +59,13 @@ module WebMock
59
59
  end
60
60
 
61
61
  def self.net_connect_allowed?(uri = nil)
62
+ return !!Config.instance.allow_net_connect if uri.nil?
63
+
62
64
  if uri.is_a?(String)
63
65
  uri = WebMock::Util::URI.normalize_uri(uri)
64
66
  end
65
67
 
66
- Config.instance.allow_net_connect ||
68
+ !!Config.instance.allow_net_connect ||
67
69
  ( Config.instance.allow_localhost && WebMock::Util::URI.is_uri_localhost?(uri) ||
68
70
  Config.instance.allow && net_connect_explicit_allowed?(Config.instance.allow, uri) )
69
71
  end
@@ -136,6 +136,8 @@ unless RUBY_PLATFORM =~ /java/
136
136
  end
137
137
 
138
138
  context 'scheme and protocol' do
139
+ let(:default_response_headers) { {} }
140
+
139
141
  before do
140
142
  stub_request(
141
143
  :get, "#{scheme}://www.example.com"
@@ -152,7 +154,7 @@ unless RUBY_PLATFORM =~ /java/
152
154
  specify do
153
155
  expect(subject).to eq(
154
156
  status: 200,
155
- headers: {},
157
+ headers: default_response_headers,
156
158
  body: 'BODY'
157
159
  )
158
160
  end
@@ -169,6 +171,7 @@ unless RUBY_PLATFORM =~ /java/
169
171
 
170
172
  context 'HTTP10 protocol' do
171
173
  let(:protocol) { Async::HTTP::Protocol::HTTP10 }
174
+ let(:default_response_headers) { {"connection"=>["keep-alive"]} }
172
175
 
173
176
  include_examples :common
174
177
  end
@@ -197,6 +200,7 @@ unless RUBY_PLATFORM =~ /java/
197
200
 
198
201
  context 'HTTP10 protocol' do
199
202
  let(:protocol) { Async::HTTP::Protocol::HTTP10 }
203
+ let(:default_response_headers) { {"connection"=>["keep-alive"]} }
200
204
 
201
205
  include_examples :common
202
206
  end
@@ -201,6 +201,18 @@ describe "Net:HTTP" do
201
201
  expect(Net::HTTP.get_response(Addressable::URI.parse('http://www.example.com/hello?a=1')).body).to eq("abc")
202
202
  end
203
203
 
204
+ it "should support method calls on stubbed socket" do
205
+ WebMock.allow_net_connect!
206
+ stub_request(:get, 'www.google.com')#.with(headers: {"My-Header" => 99})
207
+ req = Net::HTTP::Get.new('/')
208
+ Net::HTTP.start('www.google.com') do |http|
209
+ http.request(req, '')
210
+ socket = http.instance_variable_get(:@socket)
211
+ expect(socket).to be_a(StubSocket)
212
+ expect { socket.io.setsockopt(Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1) }.to_not raise_error
213
+ end
214
+ end
215
+
204
216
  describe "connecting on Net::HTTP.start" do
205
217
  before(:each) do
206
218
  @http = Net::HTTP.new('www.google.com', 443)
@@ -640,4 +640,22 @@ shared_examples_for "stubbing requests" do |*adapter_info|
640
640
  }.to raise_error(WebMock::NetConnectNotAllowedError, %r(Real HTTP connections are disabled. Unregistered request: GET http://www.example.com/))
641
641
  end
642
642
  end
643
+
644
+ describe "in Rspec around(:each) hook" do
645
+ # order goes
646
+ # around(:each)
647
+ # before(:each)
648
+ # after(:each)
649
+ # anything after example.run in around(:each)
650
+ around(:each) do |example|
651
+ example.run
652
+ expect {
653
+ http_request(:get, "http://www.example.com/")
654
+ }.to_not raise_error # WebMock::NetConnectNotAllowedError
655
+ end
656
+
657
+ it "should still allow me to make a mocked request" do
658
+ stub_request(:get, "www.example.com")
659
+ end
660
+ end
643
661
  end
@@ -111,6 +111,16 @@ describe WebMock::RequestPattern do
111
111
  to match(WebMock::RequestSignature.new(:get, "www.example.com"))
112
112
  end
113
113
 
114
+ it "should match if uri proc pattern returning true" do
115
+ expect(WebMock::RequestPattern.new(:get, ->(uri) { true })).
116
+ to match(WebMock::RequestSignature.new(:get, "www.example.com"))
117
+ end
118
+
119
+ it "should not match if uri proc pattern returns false" do
120
+ expect(WebMock::RequestPattern.new(:get, ->(uri) { false })).
121
+ not_to match(WebMock::RequestSignature.new(:get, "www.example.com"))
122
+ end
123
+
114
124
  it "should match if uri Addressable::Template pattern matches unescaped form of request uri" do
115
125
  expect(WebMock::RequestPattern.new(:get, Addressable::Template.new("www.example.com/{any_path}"))).
116
126
  to match(WebMock::RequestSignature.new(:get, "www.example.com/my%20path"))
@@ -132,6 +142,12 @@ describe WebMock::RequestPattern do
132
142
  expect(WebMock::RequestPattern.new(:get, uri)).to match(signature)
133
143
  end
134
144
 
145
+ it "should match if Addressable::Template pattern that has ip address host without port matches request uri" do
146
+ signature = WebMock::RequestSignature.new(:get, "127.0.0.1/1234")
147
+ uri = Addressable::Template.new("127.0.0.1/{id}")
148
+ expect(WebMock::RequestPattern.new(:get, uri)).to match(signature)
149
+ end
150
+
135
151
  it "should match if Addressable::Template pattern host matches request uri" do
136
152
  signature = WebMock::RequestSignature.new(:get, "www.example.com")
137
153
  uri = Addressable::Template.new("{subdomain}.example.com")
@@ -144,6 +160,12 @@ describe WebMock::RequestPattern do
144
160
  expect(WebMock::RequestPattern.new(:get, uri)).not_to match(signature)
145
161
  end
146
162
 
163
+ it "should match if uri Addressable::Template pattern matches request uri without a schema and a path " do
164
+ signature = WebMock::RequestSignature.new(:get, "127.0.0.1:3000")
165
+ uri = Addressable::Template.new("127.0.0.1:3000")
166
+ expect(WebMock::RequestPattern.new(:get, uri)).to match(signature)
167
+ end
168
+
147
169
  it "should match for uris with same parameters as pattern" do
148
170
  expect(WebMock::RequestPattern.new(:get, "www.example.com?a=1&b=2")).
149
171
  to match(WebMock::RequestSignature.new(:get, "www.example.com?a=1&b=2"))
@@ -241,6 +263,42 @@ describe WebMock::RequestPattern do
241
263
  end
242
264
  end
243
265
 
266
+ describe "when uri is described as a proc" do
267
+ it "should match request query params" do
268
+ expect(WebMock::RequestPattern.new(:get, ->(uri) { true }, query: {"a" => ["b", "c"]})).
269
+ to match(WebMock::RequestSignature.new(:get, "www.example.com?a[]=b&a[]=c"))
270
+ end
271
+
272
+ it "should match request query params if params don't match" do
273
+ expect(WebMock::RequestPattern.new(:get, ->(uri) { true }, query: {"x" => ["b", "c"]})).
274
+ not_to match(WebMock::RequestSignature.new(:get, "www.example.com?a[]=b&a[]=c"))
275
+ end
276
+
277
+ it "should match when query params are declared as HashIncluding matcher matching params" do
278
+ expect(WebMock::RequestPattern.new(:get, ->(uri) { true },
279
+ query: WebMock::Matchers::HashIncludingMatcher.new({"a" => ["b", "c"]}))).
280
+ to match(WebMock::RequestSignature.new(:get, "www.example.com?a[]=b&a[]=c&b=1"))
281
+ end
282
+
283
+ it "should not match when query params are declared as HashIncluding matcher not matching params" do
284
+ expect(WebMock::RequestPattern.new(:get, ->(uri) { true },
285
+ query: WebMock::Matchers::HashIncludingMatcher.new({"x" => ["b", "c"]}))).
286
+ not_to match(WebMock::RequestSignature.new(:get, "www.example.com?a[]=b&a[]=c&b=1"))
287
+ end
288
+
289
+ it "should match when query params are declared as RSpec HashIncluding matcher matching params" do
290
+ expect(WebMock::RequestPattern.new(:get, ->(uri) { true },
291
+ query: RSpec::Mocks::ArgumentMatchers::HashIncludingMatcher.new({"a" => ["b", "c"]}))).
292
+ to match(WebMock::RequestSignature.new(:get, "www.example.com?a[]=b&a[]=c&b=1"))
293
+ end
294
+
295
+ it "should not match when query params are declared as RSpec HashIncluding matcher not matching params" do
296
+ expect(WebMock::RequestPattern.new(:get, ->(uri) { true },
297
+ query: RSpec::Mocks::ArgumentMatchers::HashIncludingMatcher.new({"a" => ["b", "d"]}))).
298
+ not_to match(WebMock::RequestSignature.new(:get, "www.example.com?a[]=b&a[]=c&b=1"))
299
+ end
300
+ end
301
+
244
302
  describe "when uri is described as Addressable::Template" do
245
303
  it "should raise error if query params are specified" do
246
304
  expect(WebMock::RequestPattern.new(:get, Addressable::Template.new("www.example.com"), query: {"a" => ["b", "c"]})).
@@ -1,19 +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)
6
- end
3
+ describe "WebMock" do
7
4
 
8
- it "should not require safe_yaml" do
9
- expect(defined?SafeYAML).to eq(nil)
10
- end
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
11
13
 
12
- it "should alias enable_net_connect! to allow_net_connect!" do
13
- expect(WebMock.method(:enable_net_connect!)).to eq(WebMock.method(:allow_net_connect!))
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
14
21
  end
15
22
 
16
- it "should alias disallow_net_connect! to disable_net_connect!" do
17
- expect(WebMock.method(:disallow_net_connect!)).to eq(WebMock.method(:disable_net_connect!))
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
18
59
  end
19
60
  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.8.3
4
+ version: 3.9.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-03-11 00:00:00.000000000 Z
11
+ date: 2020-09-13 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.8.3/CHANGELOG.md
411
- documentation_uri: https://www.rubydoc.info/gems/webmock/3.8.3
412
- source_code_uri: https://github.com/bblimke/webmock/tree/v3.8.3
410
+ changelog_uri: https://github.com/bblimke/webmock/blob/v3.9.0/CHANGELOG.md
411
+ documentation_uri: https://www.rubydoc.info/gems/webmock/3.9.0
412
+ source_code_uri: https://github.com/bblimke/webmock/tree/v3.9.0
413
413
  wiki_uri: https://github.com/bblimke/webmock/wiki
414
414
  post_install_message:
415
415
  rdoc_options: []