webmock 1.7.5 → 1.7.6
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/.rspec-tm +2 -0
- data/CHANGELOG.md +6 -0
- data/Gemfile +2 -2
- data/README.md +1 -0
- data/Rakefile +3 -3
- data/lib/webmock/http_lib_adapters/httpclient_adapter.rb +11 -4
- data/lib/webmock/version.rb +1 -1
- data/spec/{curb_spec.rb → acceptance/curb/curb_spec.rb} +9 -9
- data/spec/{curb_spec_helper.rb → acceptance/curb/curb_spec_helper.rb} +0 -0
- data/spec/{em_http_request_spec.rb → acceptance/em_http_request/em_http_request_spec.rb} +13 -13
- data/spec/{em_http_request_spec_helper.rb → acceptance/em_http_request/em_http_request_spec_helper.rb} +0 -0
- data/spec/acceptance/httpclient/httpclient_spec.rb +67 -0
- data/spec/{httpclient_spec_helper.rb → acceptance/httpclient/httpclient_spec_helper.rb} +0 -0
- data/spec/{net_http_shared.rb → acceptance/net_http/net_http_shared.rb} +0 -0
- data/spec/{net_http_spec.rb → acceptance/net_http/net_http_spec.rb} +6 -6
- data/spec/{net_http_spec_helper.rb → acceptance/net_http/net_http_spec_helper.rb} +0 -0
- data/spec/{real_net_http_spec.rb → acceptance/net_http/real_net_http_spec.rb} +1 -1
- data/spec/{patron_spec.rb → acceptance/patron/patron_spec.rb} +12 -12
- data/spec/{patron_spec_helper.rb → acceptance/patron/patron_spec_helper.rb} +0 -0
- data/spec/acceptance/shared/allowing_and_disabling_net_connect.rb +142 -0
- data/spec/acceptance/shared/callbacks.rb +130 -0
- data/spec/acceptance/shared/enabling_and_disabling_webmock.rb +96 -0
- data/spec/acceptance/shared/precedence_of_stubs.rb +15 -0
- data/spec/acceptance/shared/request_expectations.rb +620 -0
- data/spec/acceptance/shared/returning_declared_responses.rb +377 -0
- data/spec/acceptance/shared/stubbing_requests.rb +314 -0
- data/spec/{typhoeus_hydra_spec.rb → acceptance/typhoeus/typhoeus_hydra_spec.rb} +5 -5
- data/spec/{typhoeus_hydra_spec_helper.rb → acceptance/typhoeus/typhoeus_hydra_spec_helper.rb} +0 -0
- data/spec/acceptance/webmock_shared.rb +38 -0
- data/spec/spec_helper.rb +4 -2
- data/spec/{example_curl_output.txt → support/example_curl_output.txt} +0 -0
- data/spec/{my_rack_app.rb → support/my_rack_app.rb} +0 -0
- data/spec/{network_connection.rb → support/network_connection.rb} +0 -0
- data/spec/{errors_spec.rb → unit/errors_spec.rb} +1 -1
- data/spec/{http_lib_adapters → unit/http_lib_adapters}/http_lib_adapter_registry_spec.rb +1 -1
- data/spec/{http_lib_adapters → unit/http_lib_adapters}/http_lib_adapter_spec.rb +1 -1
- data/spec/{rack_response_spec.rb → unit/rack_response_spec.rb} +1 -1
- data/spec/{request_execution_verifier_spec.rb → unit/request_execution_verifier_spec.rb} +1 -1
- data/spec/{request_pattern_spec.rb → unit/request_pattern_spec.rb} +1 -1
- data/spec/{request_registry_spec.rb → unit/request_registry_spec.rb} +1 -1
- data/spec/{request_signature_spec.rb → unit/request_signature_spec.rb} +1 -1
- data/spec/{request_stub_spec.rb → unit/request_stub_spec.rb} +1 -1
- data/spec/{response_spec.rb → unit/response_spec.rb} +4 -4
- data/spec/{stub_registry_spec.rb → unit/stub_registry_spec.rb} +1 -1
- data/spec/{stub_request_snippet_spec.rb → unit/stub_request_snippet_spec.rb} +1 -1
- data/spec/{util → unit/util}/hash_counter_spec.rb +1 -1
- data/spec/{util → unit/util}/hash_keys_stringifier_spec.rb +1 -1
- data/spec/{util → unit/util}/headers_spec.rb +1 -1
- data/spec/{util → unit/util}/json_spec.rb +1 -1
- data/spec/{util → unit/util}/uri_spec.rb +1 -1
- data/spec/{webmock_spec.rb → unit/webmock_spec.rb} +1 -1
- data/webmock.gemspec +1 -1
- metadata +111 -116
- data/spec/httpclient_spec.rb +0 -43
- data/spec/vendor/addressable/lib/addressable/uri.rb +0 -8
- data/spec/vendor/addressable/lib/uri.rb +0 -1
- data/spec/vendor/crack/lib/crack.rb +0 -1
- data/spec/vendor/right_http_connection-1.2.4/History.txt +0 -59
- data/spec/vendor/right_http_connection-1.2.4/Manifest.txt +0 -7
- data/spec/vendor/right_http_connection-1.2.4/README.txt +0 -54
- data/spec/vendor/right_http_connection-1.2.4/Rakefile +0 -103
- data/spec/vendor/right_http_connection-1.2.4/lib/net_fix.rb +0 -160
- data/spec/vendor/right_http_connection-1.2.4/lib/right_http_connection.rb +0 -435
- data/spec/vendor/right_http_connection-1.2.4/setup.rb +0 -1585
- data/spec/webmock_shared.rb +0 -1770
data/.rspec-tm
ADDED
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,11 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## 1.7.6
|
4
|
+
|
5
|
+
* Support for the HTTPClient's request_filter feature
|
6
|
+
|
7
|
+
Thanks to [Roman Shterenzon](https://github.com/romanbsd)
|
8
|
+
|
3
9
|
## 1.7.5
|
4
10
|
|
5
11
|
* Added support for Patron 0.4.15. This change is not backward compatible so please upgrade Patron to version >= 0.4.15 if you want to use it with WebMock.
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -648,6 +648,7 @@ People who submitted patches and new features or suggested improvements. Many th
|
|
648
648
|
* Lin Jen-Shin
|
649
649
|
* David Yeu
|
650
650
|
* Andreas Garnæs
|
651
|
+
* Roman Shterenzon
|
651
652
|
|
652
653
|
For a full list of contributors you can visit the
|
653
654
|
[contributors](https://github.com/bblimke/webmock/contributors) page.
|
data/Rakefile
CHANGED
@@ -21,13 +21,13 @@ RSpec::Core::RakeTask.new(:spec) do |t|
|
|
21
21
|
end
|
22
22
|
|
23
23
|
RSpec::Core::RakeTask.new(:spec_http_without_webmock) do |t|
|
24
|
-
t.rspec_opts = ["-c", "-f progress", "-r ./spec/real_net_http_spec.rb"]
|
25
|
-
t.pattern = 'spec/real_net_http_spec.rb'
|
24
|
+
t.rspec_opts = ["-c", "-f progress", "-r ./spec/acceptance/net_http/real_net_http_spec.rb"]
|
25
|
+
t.pattern = 'spec/acceptance/net_http/real_net_http_spec.rb'
|
26
26
|
end
|
27
27
|
|
28
28
|
|
29
29
|
task :em_http_request_1_x_spec do
|
30
|
-
sh "EM_HTTP_REQUEST_1_X=true bundle install && bundle exec rspec spec/em_http_request_spec.rb" if RUBY_VERSION >= "1.9.2"
|
30
|
+
sh "EM_HTTP_REQUEST_1_X=true bundle install && bundle exec rspec spec/acceptance/em_http_request/em_http_request_spec.rb" if RUBY_VERSION >= "1.9.2"
|
31
31
|
end
|
32
32
|
|
33
33
|
require 'rake/testtask'
|
@@ -45,6 +45,9 @@ if defined?(::HTTPClient)
|
|
45
45
|
if WebMock::StubRegistry.instance.registered_request?(request_signature)
|
46
46
|
webmock_response = WebMock::StubRegistry.instance.response_for_request(request_signature)
|
47
47
|
response = build_httpclient_response(webmock_response, stream, &block)
|
48
|
+
@request_filter.each do |filter|
|
49
|
+
filter.filter_response(req, response)
|
50
|
+
end
|
48
51
|
res = conn.push(response)
|
49
52
|
WebMock::CallbackRegistry.invoke_callbacks(
|
50
53
|
{:lib => :httpclient}, request_signature, webmock_response)
|
@@ -130,10 +133,14 @@ if defined?(::HTTPClient)
|
|
130
133
|
auth = www_auth.basic_auth
|
131
134
|
auth.challenge(req.header.request_uri, nil)
|
132
135
|
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
136
|
+
@request_filter.each do |filter|
|
137
|
+
filter.filter_request(req)
|
138
|
+
end
|
139
|
+
|
140
|
+
headers = req.header.all.inject({}) do |hdrs, header|
|
141
|
+
hdrs[header[0]] ||= []
|
142
|
+
hdrs[header[0]] << header[1]
|
143
|
+
hdrs
|
137
144
|
end
|
138
145
|
|
139
146
|
if (auth_cred = auth.get(req)) && auth.scheme == 'Basic'
|
data/lib/webmock/version.rb
CHANGED
@@ -1,17 +1,17 @@
|
|
1
|
-
require
|
2
|
-
require 'webmock_shared'
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'acceptance/webmock_shared'
|
3
3
|
|
4
4
|
unless RUBY_PLATFORM =~ /java/
|
5
|
-
require 'curb_spec_helper'
|
5
|
+
require 'acceptance/curb/curb_spec_helper'
|
6
6
|
|
7
7
|
shared_examples_for "Curb" do
|
8
8
|
include CurbSpecHelper
|
9
9
|
|
10
|
-
|
10
|
+
include_examples "with WebMock"
|
11
11
|
|
12
12
|
describe "when doing PUTs" do
|
13
13
|
it "should stub them" do
|
14
|
-
|
14
|
+
stub_request(:put, "www.example.com").with(:body => "01234")
|
15
15
|
http_request(:put, "http://www.example.com", :body => "01234").
|
16
16
|
status.should == "200"
|
17
17
|
end
|
@@ -273,7 +273,7 @@ unless RUBY_PLATFORM =~ /java/
|
|
273
273
|
include CurbSpecHelper::NamedHttp
|
274
274
|
|
275
275
|
it "should work with blank arguments for post" do
|
276
|
-
|
276
|
+
stub_request(:post, "www.example.com").with(:body => "01234")
|
277
277
|
c = Curl::Easy.new
|
278
278
|
c.url = "http://www.example.com"
|
279
279
|
c.post_body = "01234"
|
@@ -282,13 +282,13 @@ unless RUBY_PLATFORM =~ /java/
|
|
282
282
|
end
|
283
283
|
|
284
284
|
it "should work with several body arguments for post using the class method" do
|
285
|
-
|
285
|
+
stub_request(:post, "www.example.com").with(:user => {:first_name=>'Bartosz', :last_name=>'Blimke'})
|
286
286
|
c = Curl::Easy.http_post "http://www.example.com", 'user[first_name]=Bartosz', 'user[last_name]=Blimke'
|
287
287
|
c.response_code.should == 200
|
288
288
|
end
|
289
289
|
|
290
290
|
it "should work with blank arguments for put" do
|
291
|
-
|
291
|
+
stub_request(:put, "www.example.com").with(:body => "01234")
|
292
292
|
c = Curl::Easy.new
|
293
293
|
c.url = "http://www.example.com"
|
294
294
|
c.put_data = "01234"
|
@@ -299,7 +299,7 @@ unless RUBY_PLATFORM =~ /java/
|
|
299
299
|
it "should work with multiple arguments for post" do
|
300
300
|
data = { :name => "john", :address => "111 example ave" }
|
301
301
|
|
302
|
-
|
302
|
+
stub_request(:post, "www.example.com").with(:body => data)
|
303
303
|
c = Curl::Easy.new
|
304
304
|
c.url = "http://www.example.com"
|
305
305
|
c.http_post Curl::PostField.content('name', data[:name]), Curl::PostField.content('address', data[:address])
|
File without changes
|
@@ -1,21 +1,21 @@
|
|
1
|
-
require
|
2
|
-
require 'webmock_shared'
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'acceptance/webmock_shared'
|
3
3
|
require 'ostruct'
|
4
4
|
|
5
5
|
unless RUBY_PLATFORM =~ /java/
|
6
|
-
require 'em_http_request_spec_helper'
|
6
|
+
require 'acceptance/em_http_request/em_http_request_spec_helper'
|
7
7
|
|
8
|
-
describe "
|
8
|
+
describe "EM::HttpRequest" do
|
9
9
|
include EMHttpRequestSpecHelper
|
10
10
|
|
11
|
-
|
11
|
+
include_examples "with WebMock"
|
12
12
|
|
13
13
|
#functionality only supported for em-http-request 1.x
|
14
14
|
if defined?(EventMachine::HttpConnection)
|
15
15
|
describe "with middleware" do
|
16
16
|
|
17
17
|
it "should work with request middleware" do
|
18
|
-
|
18
|
+
stub_request(:get, "www.example.com").with(:body => 'bar')
|
19
19
|
|
20
20
|
middleware = Class.new do
|
21
21
|
def request(client, head, body)
|
@@ -38,7 +38,7 @@ unless RUBY_PLATFORM =~ /java/
|
|
38
38
|
end
|
39
39
|
|
40
40
|
it "should work with response middleware" do
|
41
|
-
|
41
|
+
stub_request(:get, "www.example.com").to_return(:body => 'foo')
|
42
42
|
|
43
43
|
middleware = Class.new do
|
44
44
|
def response(resp)
|
@@ -102,7 +102,7 @@ unless RUBY_PLATFORM =~ /java/
|
|
102
102
|
end
|
103
103
|
|
104
104
|
it "should work with streaming" do
|
105
|
-
|
105
|
+
stub_request(:get, "www.example.com").to_return(:body => "abc")
|
106
106
|
response = ""
|
107
107
|
EM.run {
|
108
108
|
http = EventMachine::HttpRequest.new('http://www.example.com/').get
|
@@ -112,28 +112,28 @@ unless RUBY_PLATFORM =~ /java/
|
|
112
112
|
end
|
113
113
|
|
114
114
|
it "should work with responses that use chunked transfer encoding" do
|
115
|
-
|
115
|
+
stub_request(:get, "www.example.com").to_return(:body => "abc", :headers => { 'Transfer-Encoding' => 'chunked' })
|
116
116
|
http_request(:get, "http://www.example.com").body.should == "abc"
|
117
117
|
end
|
118
118
|
|
119
119
|
it "should work with optional query params" do
|
120
|
-
|
120
|
+
stub_request(:get, "www.example.com/?x=3&a[]=b&a[]=c").to_return(:body => "abc")
|
121
121
|
http_request(:get, "http://www.example.com/?x=3", :query => {"a" => ["b", "c"]}).body.should == "abc"
|
122
122
|
end
|
123
123
|
|
124
124
|
it "should work with optional query params declared as string" do
|
125
|
-
|
125
|
+
stub_request(:get, "www.example.com/?x=3&a[]=b&a[]=c").to_return(:body => "abc")
|
126
126
|
http_request(:get, "http://www.example.com/?x=3", :query => "a[]=b&a[]=c").body.should == "abc"
|
127
127
|
end
|
128
128
|
|
129
129
|
it "should work when the body is passed as a Hash" do
|
130
|
-
|
130
|
+
stub_request(:post, "www.example.com").with(:body => {:a => "1", :b => "2"}).to_return(:body => "ok")
|
131
131
|
http_request(:post, "http://www.example.com", :body => {:a => "1", :b => "2"}).body.should == "ok"
|
132
132
|
end
|
133
133
|
|
134
134
|
describe "mocking EM::HttpClient API" do
|
135
135
|
before do
|
136
|
-
|
136
|
+
stub_request(:get, "www.example.com/")
|
137
137
|
WebMock::HttpLibAdapters::EmHttpRequestAdapter.enable!
|
138
138
|
end
|
139
139
|
subject do
|
File without changes
|
@@ -0,0 +1,67 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'acceptance/webmock_shared'
|
3
|
+
require 'ostruct'
|
4
|
+
|
5
|
+
require 'acceptance/httpclient/httpclient_spec_helper'
|
6
|
+
|
7
|
+
describe "HTTPClient" do
|
8
|
+
include HTTPClientSpecHelper
|
9
|
+
|
10
|
+
before(:each) do
|
11
|
+
HTTPClientSpecHelper.async_mode = false
|
12
|
+
end
|
13
|
+
|
14
|
+
include_examples "with WebMock"
|
15
|
+
|
16
|
+
it "should yield block on response if block provided" do
|
17
|
+
stub_request(:get, "www.example.com").to_return(:body => "abc")
|
18
|
+
response_body = ""
|
19
|
+
http_request(:get, "http://www.example.com/") do |body|
|
20
|
+
response_body = body
|
21
|
+
end
|
22
|
+
response_body.should == "abc"
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should match requests if headers are the same but in different order" do
|
26
|
+
stub_request(:get, "www.example.com").with(:headers => {"a" => ["b", "c"]} )
|
27
|
+
http_request(
|
28
|
+
:get, "http://www.example.com/",
|
29
|
+
:headers => {"a" => ["c", "b"]}).status.should == "200"
|
30
|
+
end
|
31
|
+
|
32
|
+
describe "when using async requests" do
|
33
|
+
before(:each) do
|
34
|
+
HTTPClientSpecHelper.async_mode = true
|
35
|
+
end
|
36
|
+
|
37
|
+
include_examples "with WebMock"
|
38
|
+
end
|
39
|
+
|
40
|
+
context "Filters" do
|
41
|
+
class Filter
|
42
|
+
def filter_request(request)
|
43
|
+
request.header["Authorization"] = "Bearer 0123456789"
|
44
|
+
end
|
45
|
+
|
46
|
+
def filter_response(request, response)
|
47
|
+
response.header.set('X-Powered-By', 'webmock')
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
before do
|
52
|
+
@client = HTTPClient.new
|
53
|
+
@client.request_filter << Filter.new
|
54
|
+
stub_request(:get, 'www.example.com').with(:headers => {'Authorization' => 'Bearer 0123456789'})
|
55
|
+
end
|
56
|
+
|
57
|
+
it "supports request filters" do
|
58
|
+
@client.request(:get, 'http://www.example.com/').status.should == 200
|
59
|
+
end
|
60
|
+
|
61
|
+
it "supports response filters" do
|
62
|
+
res = @client.request(:get, 'http://www.example.com/')
|
63
|
+
res.header['X-Powered-By'].first.should == 'webmock'
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
File without changes
|
File without changes
|
@@ -1,13 +1,13 @@
|
|
1
|
-
require
|
2
|
-
require 'webmock_shared'
|
1
|
+
require 'spec_helper'
|
3
2
|
require 'ostruct'
|
4
|
-
require '
|
5
|
-
require '
|
3
|
+
require 'acceptance/webmock_shared'
|
4
|
+
require 'acceptance/net_http/net_http_spec_helper'
|
5
|
+
require 'acceptance/net_http/net_http_shared'
|
6
6
|
|
7
7
|
include NetHTTPSpecHelper
|
8
8
|
|
9
|
-
describe "
|
10
|
-
|
9
|
+
describe "Net:HTTP" do
|
10
|
+
include_examples "with WebMock"
|
11
11
|
|
12
12
|
let(:port){ WebMockServer.instance.port }
|
13
13
|
|
File without changes
|
@@ -1,9 +1,9 @@
|
|
1
1
|
require 'rubygems'
|
2
2
|
require 'rspec'
|
3
3
|
require 'net/http'
|
4
|
-
require 'net_http_shared'
|
5
4
|
require 'net/https'
|
6
5
|
require 'stringio'
|
6
|
+
require 'acceptance/net_http/net_http_shared'
|
7
7
|
require 'support/webmock_server'
|
8
8
|
|
9
9
|
describe "Real Net:HTTP without webmock", :without_webmock => true do
|
@@ -1,17 +1,17 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
|
-
require
|
4
|
-
require 'webmock_shared'
|
3
|
+
require 'spec_helper'
|
4
|
+
require 'acceptance/webmock_shared'
|
5
5
|
|
6
6
|
unless RUBY_PLATFORM =~ /java/
|
7
|
-
require 'patron_spec_helper'
|
7
|
+
require 'acceptance/patron/patron_spec_helper'
|
8
8
|
require 'tmpdir'
|
9
9
|
require 'fileutils'
|
10
10
|
|
11
|
-
describe "
|
11
|
+
describe "Patron" do
|
12
12
|
include PatronSpecHelper
|
13
13
|
|
14
|
-
|
14
|
+
include_examples "with WebMock"
|
15
15
|
|
16
16
|
describe "when custom functionality is used" do
|
17
17
|
before(:each) do
|
@@ -33,13 +33,13 @@ unless RUBY_PLATFORM =~ /java/
|
|
33
33
|
|
34
34
|
|
35
35
|
it "should work with get_file" do
|
36
|
-
|
36
|
+
stub_request(:get, "www.example.com").to_return(:body => "abc")
|
37
37
|
@sess.get_file("/", @file_path)
|
38
38
|
File.read(@file_path).should == "abc"
|
39
39
|
end
|
40
40
|
|
41
41
|
it "should raise same error as Patron if file is not readable for get request" do
|
42
|
-
|
42
|
+
stub_request(:get, "www.example.com")
|
43
43
|
File.open("/tmp/read_only_file", "w") do |tmpfile|
|
44
44
|
tmpfile.chmod(0400)
|
45
45
|
end
|
@@ -54,18 +54,18 @@ unless RUBY_PLATFORM =~ /java/
|
|
54
54
|
|
55
55
|
it "should work with put_file" do
|
56
56
|
File.open(@file_path, "w") {|f| f.write "abc"}
|
57
|
-
|
57
|
+
stub_request(:put, "www.example.com").with(:body => "abc")
|
58
58
|
@sess.put_file("/", @file_path)
|
59
59
|
end
|
60
60
|
|
61
61
|
it "should work with post_file" do
|
62
62
|
File.open(@file_path, "w") {|f| f.write "abc"}
|
63
|
-
|
63
|
+
stub_request(:post, "www.example.com").with(:body => "abc")
|
64
64
|
@sess.post_file("/", @file_path)
|
65
65
|
end
|
66
66
|
|
67
67
|
it "should raise same error as Patron if file is not readable for post request" do
|
68
|
-
|
68
|
+
stub_request(:post, "www.example.com").with(:body => "abc")
|
69
69
|
lambda {
|
70
70
|
@sess.post_file("/", "/path/to/non/existing/file")
|
71
71
|
}.should raise_error(ArgumentError, "Unable to open specified file.")
|
@@ -75,7 +75,7 @@ unless RUBY_PLATFORM =~ /java/
|
|
75
75
|
|
76
76
|
describe "handling errors same way as patron" do
|
77
77
|
it "should raise error if put request has neither upload_data nor file_name" do
|
78
|
-
|
78
|
+
stub_request(:post, "www.example.com")
|
79
79
|
lambda {
|
80
80
|
@sess.post("/", nil)
|
81
81
|
}.should raise_error(ArgumentError, "Must provide either data or a filename when doing a PUT or POST")
|
@@ -83,7 +83,7 @@ unless RUBY_PLATFORM =~ /java/
|
|
83
83
|
end
|
84
84
|
|
85
85
|
it "should work with WebDAV copy request" do
|
86
|
-
|
86
|
+
stub_request(:copy, "www.example.com/abc").with(:headers => {'Destination' => "/def"})
|
87
87
|
@sess.copy("/abc", "/def")
|
88
88
|
end
|
89
89
|
|
File without changes
|
@@ -0,0 +1,142 @@
|
|
1
|
+
shared_context "allowing and disabling net connect" do
|
2
|
+
describe "when net connect" do
|
3
|
+
describe "is allowed", :net_connect => true do
|
4
|
+
before(:each) do
|
5
|
+
WebMock.allow_net_connect!
|
6
|
+
end
|
7
|
+
|
8
|
+
it "should make a real web request if request is not stubbed" do
|
9
|
+
http_request(:get, webmock_server_url).status.should == "200"
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should make a real https request if request is not stubbed" do
|
13
|
+
unless http_library == :httpclient
|
14
|
+
http_request(:get, "https://www.paypal.com/uk/cgi-bin/webscr").
|
15
|
+
body.should =~ /.*paypal.*/
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should return stubbed response if request was stubbed" do
|
20
|
+
stub_request(:get, "www.example.com").to_return(:body => "abc")
|
21
|
+
http_request(:get, "http://www.example.com/").body.should == "abc"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe "is not allowed" do
|
26
|
+
before(:each) do
|
27
|
+
WebMock.disable_net_connect!
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should return stubbed response if request was stubbed" do
|
31
|
+
stub_request(:get, "www.example.com").to_return(:body => "abc")
|
32
|
+
http_request(:get, "http://www.example.com/").body.should == "abc"
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should return stubbed response if request with path was stubbed" do
|
36
|
+
stub_request(:get, "www.example.com/hello_world").to_return(:body => "abc")
|
37
|
+
http_request(:get, "http://www.example.com/hello_world").body.should == "abc"
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should raise exception if request was not stubbed" do
|
41
|
+
lambda {
|
42
|
+
http_request(:get, "http://www.example.com/")
|
43
|
+
}.should raise_error(WebMock::NetConnectNotAllowedError, %r(Real HTTP connections are disabled. Unregistered request: GET http://www.example.com/))
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
describe "is not allowed with exception for localhost" do
|
48
|
+
before(:each) do
|
49
|
+
WebMock.disable_net_connect!(:allow_localhost => true)
|
50
|
+
end
|
51
|
+
|
52
|
+
it "should return stubbed response if request was stubbed" do
|
53
|
+
stub_request(:get, "www.example.com").to_return(:body => "abc")
|
54
|
+
http_request(:get, "http://www.example.com/").body.should == "abc"
|
55
|
+
end
|
56
|
+
|
57
|
+
it "should raise exception if request was not stubbed" do
|
58
|
+
lambda {
|
59
|
+
http_request(:get, "http://www.example.com/")
|
60
|
+
}.should raise_error(WebMock::NetConnectNotAllowedError, %r(Real HTTP connections are disabled. Unregistered request: GET http://www.example.com/))
|
61
|
+
end
|
62
|
+
|
63
|
+
it "should make a real request to localhost" do
|
64
|
+
lambda {
|
65
|
+
http_request(:get, "http://localhost:12345/")
|
66
|
+
}.should raise_error(connection_refused_exception_class)
|
67
|
+
end
|
68
|
+
|
69
|
+
it "should make a real request to 127.0.0.1" do
|
70
|
+
lambda {
|
71
|
+
http_request(:get, "http://127.0.0.1:12345/")
|
72
|
+
}.should raise_error(connection_refused_exception_class)
|
73
|
+
end
|
74
|
+
|
75
|
+
it "should make a real request to 0.0.0.0" do
|
76
|
+
lambda {
|
77
|
+
http_request(:get, "http://0.0.0.0:12345/")
|
78
|
+
}.should raise_error(connection_refused_exception_class)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
describe "is not allowed with exception for allowed domains" do
|
83
|
+
let(:host_with_port){ WebMockServer.instance.host_with_port }
|
84
|
+
|
85
|
+
before(:each) do
|
86
|
+
WebMock.disable_net_connect!(:allow => ["www.example.org", host_with_port])
|
87
|
+
end
|
88
|
+
|
89
|
+
context "when the host is not allowed" do
|
90
|
+
it "should return stubbed response if request was stubbed" do
|
91
|
+
stub_request(:get, "www.example.com").to_return(:body => "abc")
|
92
|
+
http_request(:get, "http://www.example.com/").body.should == "abc"
|
93
|
+
end
|
94
|
+
|
95
|
+
it "should raise exception if request was not stubbed" do
|
96
|
+
lambda {
|
97
|
+
http_request(:get, "http://www.example.com/")
|
98
|
+
}.should raise_error(WebMock::NetConnectNotAllowedError, %r(Real HTTP connections are disabled. Unregistered request: GET http://www.example.com/))
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
context "when the host with port is not allowed" do
|
103
|
+
it "should return stubbed response if request was stubbed" do
|
104
|
+
stub_request(:get, "http://localhost:2345").to_return(:body => "abc")
|
105
|
+
http_request(:get, "http://localhost:2345/").body.should == "abc"
|
106
|
+
end
|
107
|
+
|
108
|
+
it "should raise exception if request was not stubbed" do
|
109
|
+
lambda {
|
110
|
+
http_request(:get, "http://localhost:2345/")
|
111
|
+
}.should raise_error(WebMock::NetConnectNotAllowedError, %r(Real HTTP connections are disabled. Unregistered request: GET http://localhost:2345/))
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
context "when the host is allowed" do
|
116
|
+
it "should raise exception if request was not stubbed" do
|
117
|
+
lambda {
|
118
|
+
http_request(:get, "http://www.example.com/")
|
119
|
+
}.should raise_error(WebMock::NetConnectNotAllowedError, %r(Real HTTP connections are disabled. Unregistered request: GET http://www.example.com/))
|
120
|
+
end
|
121
|
+
|
122
|
+
it "should make a real request to allowed host", :net_connect => true do
|
123
|
+
http_request(:get, "http://www.example.org/").status.should == "302"
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
context "when the host with port is allowed" do
|
128
|
+
it "should make a real request to allowed host", :net_connect => true do
|
129
|
+
http_request(:get, "http://#{host_with_port}/").status.should == "200"
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
context "when the host is allowed but not port" do
|
134
|
+
it "should make a real request to allowed host", :net_connect => true do
|
135
|
+
lambda {
|
136
|
+
http_request(:get, "http://localhost:123/")
|
137
|
+
}.should raise_error(WebMock::NetConnectNotAllowedError, %r(Real HTTP connections are disabled. Unregistered request: GET http://localhost:123/))
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|