webmock 1.3.4 → 1.3.5
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.
- data/CHANGELOG.md +17 -0
- data/README.md +10 -0
- data/VERSION +1 -1
- data/lib/webmock/config.rb +1 -0
- data/lib/webmock/http_lib_adapters/net_http.rb +1 -8
- data/lib/webmock/webmock.rb +4 -2
- data/spec/net_http_spec.rb +12 -0
- data/spec/webmock_spec.rb +21 -0
- data/webmock.gemspec +2 -2
- metadata +4 -4
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,22 @@
|
|
1
1
|
#Changelog
|
2
2
|
|
3
|
+
## 1.3.5
|
4
|
+
|
5
|
+
* External requests can be disabled while allowing selected hosts. Thanks to Charles Li and Ryan Bigg
|
6
|
+
|
7
|
+
This feature was available before only for localhost with `:allow_localhost => true`
|
8
|
+
|
9
|
+
WebMock.disable_net_connect!(:allow => "www.example.org")
|
10
|
+
|
11
|
+
Net::HTTP.get('www.something.com', '/') # ===> Failure
|
12
|
+
|
13
|
+
Net::HTTP.get('www.example.org', '/') # ===> Allowed.
|
14
|
+
|
15
|
+
* Fixed Net::HTTP adapter so that it preserves the original behavior of Net::HTTP.
|
16
|
+
|
17
|
+
When making a request with a block that calls #read_body on the request,
|
18
|
+
Net::HTTP causes the body to be set to a Net::ReadAdapter, but WebMock was causing the body to be set to a string.
|
19
|
+
|
3
20
|
## 1.3.4
|
4
21
|
|
5
22
|
* Fixed Net::HTTP adapter to handle cases where a block with `read_body` call is passed to `request`.
|
data/README.md
CHANGED
@@ -301,6 +301,14 @@ You can also use WebMock outside a test framework:
|
|
301
301
|
|
302
302
|
Net::HTTP.get('localhost:9887', '/') # ===> Allowed. Perhaps to Selenium?
|
303
303
|
|
304
|
+
### External requests can be disabled while allowing any hostname
|
305
|
+
|
306
|
+
WebMock.disable_net_connect!(:allow => "www.example.org")
|
307
|
+
|
308
|
+
Net::HTTP.get('www.something.com', '/') # ===> Failure
|
309
|
+
|
310
|
+
Net::HTTP.get('www.example.org', '/') # ===> Allowed.
|
311
|
+
|
304
312
|
## Setting Expectations
|
305
313
|
|
306
314
|
### Setting expectations in Test::Unit
|
@@ -525,6 +533,8 @@ People who submitted patches and new features or suggested improvements. Many th
|
|
525
533
|
* Nathaniel Bibler
|
526
534
|
* Martyn Loughran
|
527
535
|
* Muness Alrubaie
|
536
|
+
* Charles Li
|
537
|
+
* Ryan Bigg
|
528
538
|
|
529
539
|
## Background
|
530
540
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.3.
|
1
|
+
1.3.5
|
data/lib/webmock/config.rb
CHANGED
@@ -17,13 +17,6 @@ class StubSocket #:nodoc:
|
|
17
17
|
|
18
18
|
end
|
19
19
|
|
20
|
-
module StubResponse
|
21
|
-
def read_body(*args, &block)
|
22
|
-
yield @body if block_given?
|
23
|
-
@body
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
20
|
module Net #:nodoc: all
|
28
21
|
|
29
22
|
class BufferedIO
|
@@ -105,7 +98,7 @@ module Net #:nodoc: all
|
|
105
98
|
|
106
99
|
response.instance_variable_set(:@read, true)
|
107
100
|
|
108
|
-
response.extend
|
101
|
+
response.extend WebMock::Net::HTTPResponse
|
109
102
|
|
110
103
|
raise Timeout::Error, "execution expired" if webmock_response.should_timeout
|
111
104
|
|
data/lib/webmock/webmock.rb
CHANGED
@@ -37,14 +37,16 @@ module WebMock
|
|
37
37
|
def disable_net_connect!(options = {})
|
38
38
|
Config.instance.allow_net_connect = false
|
39
39
|
Config.instance.allow_localhost = options[:allow_localhost]
|
40
|
+
Config.instance.allow = options[:allow]
|
40
41
|
end
|
41
42
|
|
42
43
|
def net_connect_allowed?(uri = nil)
|
43
44
|
if uri.is_a?(String)
|
44
45
|
uri = WebMock::Util::URI.normalize_uri(uri)
|
45
46
|
end
|
46
|
-
Config.instance.allow_net_connect ||
|
47
|
-
(Config.instance.allow_localhost && uri.is_a?(Addressable::URI) && (uri.host == 'localhost' || uri.host == '127.0.0.1'))
|
47
|
+
Config.instance.allow_net_connect ||
|
48
|
+
(Config.instance.allow_localhost && uri.is_a?(Addressable::URI) && (uri.host == 'localhost' || uri.host == '127.0.0.1')) ||
|
49
|
+
Config.instance.allow && Config.instance.allow.include?(uri.host)
|
48
50
|
end
|
49
51
|
|
50
52
|
def registered_request?(request_signature)
|
data/spec/net_http_spec.rb
CHANGED
@@ -74,6 +74,18 @@ describe "Webmock with Net:HTTP" do
|
|
74
74
|
body.should =~ /Example Web Page/
|
75
75
|
end
|
76
76
|
|
77
|
+
it "should return a Net::ReadAdapter from response.body when a stubbed request is made with a block and #read_body" do
|
78
|
+
WebMock.stub_request(:get, 'http://example.com/').to_return(:body => "the body")
|
79
|
+
response = Net::HTTP.new('example.com', 80).request_get('/') { |r| r.read_body { } }
|
80
|
+
response.body.should be_a(Net::ReadAdapter)
|
81
|
+
end
|
82
|
+
|
83
|
+
it "should return a Net::ReadAdapter from response.body when a real request is made with a block and #read_body" do
|
84
|
+
WebMock.allow_net_connect!
|
85
|
+
response = Net::HTTP.new('example.com', 80).request_get('/') { |r| r.read_body { } }
|
86
|
+
response.body.should be_a(Net::ReadAdapter)
|
87
|
+
end
|
88
|
+
|
77
89
|
describe 'after_request callback support' do
|
78
90
|
let(:expected_body_regex) { /You have reached this web page by typing.*example\.com/ }
|
79
91
|
|
data/spec/webmock_spec.rb
CHANGED
@@ -99,6 +99,27 @@ describe "WebMock", :shared => true do
|
|
99
99
|
}.should raise_error(connection_refused_exception_class)
|
100
100
|
end
|
101
101
|
end
|
102
|
+
|
103
|
+
describe "is not allowed with exception for allowed domains" do
|
104
|
+
before(:each) do
|
105
|
+
WebMock.disable_net_connect!(:allow => ["www.example.org"])
|
106
|
+
end
|
107
|
+
|
108
|
+
it "should return stubbed response if request was stubbed" do
|
109
|
+
stub_http_request(:get, "www.example.com").to_return(:body => "abc")
|
110
|
+
http_request(:get, "http://www.example.com/").body.should == "abc"
|
111
|
+
end
|
112
|
+
|
113
|
+
it "should raise exception if request was not stubbed" do
|
114
|
+
lambda {
|
115
|
+
http_request(:get, "http://www.example.com/")
|
116
|
+
}.should raise_error(WebMock::NetConnectNotAllowedError, client_specific_request_string("Real HTTP connections are disabled. Unregistered request: GET http://www.example.com/"))
|
117
|
+
end
|
118
|
+
|
119
|
+
it "should allow a real request to cms.local" do
|
120
|
+
http_request(:get, "http://www.example.org/").status.should == "200"
|
121
|
+
end
|
122
|
+
end
|
102
123
|
end
|
103
124
|
|
104
125
|
describe "when matching requests" do
|
data/webmock.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{webmock}
|
8
|
-
s.version = "1.3.
|
8
|
+
s.version = "1.3.5"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Bartosz Blimke"]
|
12
|
-
s.date = %q{2010-
|
12
|
+
s.date = %q{2010-09-06}
|
13
13
|
s.description = %q{WebMock allows stubbing HTTP requests and setting expectations on HTTP requests.}
|
14
14
|
s.email = %q{bartosz.blimke@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: webmock
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 17
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 3
|
9
|
-
-
|
10
|
-
version: 1.3.
|
9
|
+
- 5
|
10
|
+
version: 1.3.5
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Bartosz Blimke
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-
|
18
|
+
date: 2010-09-06 00:00:00 +01:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|