httpi 0.9.3 → 0.9.4
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/.travis.yml +7 -0
- data/CHANGELOG.md +14 -1
- data/Gemfile +5 -3
- data/README.md +130 -100
- data/Rakefile +10 -40
- data/httpi.gemspec +11 -13
- data/lib/httpi.rb +5 -0
- data/lib/httpi/adapter.rb +17 -13
- data/lib/httpi/auth/ssl.rb +4 -4
- data/lib/httpi/request.rb +1 -1
- data/lib/httpi/version.rb +1 -1
- data/spec/httpi/adapter/curb_spec.rb +167 -164
- data/spec/httpi/adapter/httpclient_spec.rb +16 -16
- data/spec/httpi/adapter_spec.rb +29 -15
- data/spec/httpi/auth/config_spec.rb +16 -16
- data/spec/httpi/auth/ssl_spec.rb +19 -19
- data/spec/httpi/httpi_spec.rb +44 -53
- data/spec/httpi/request_spec.rb +15 -15
- data/spec/httpi/response_spec.rb +17 -17
- metadata +34 -50
@@ -10,14 +10,14 @@ describe HTTPI::Adapter::HTTPClient do
|
|
10
10
|
let(:ssl_config) { HTTPClient::SSLConfig.any_instance }
|
11
11
|
|
12
12
|
describe "#get" do
|
13
|
-
it "
|
13
|
+
it "returns a valid HTTPI::Response" do
|
14
14
|
httpclient.expects(:get).with(basic_request.url, nil, basic_request.headers).returns(http_message)
|
15
15
|
adapter.get(basic_request).should match_response(:body => Fixture.xml)
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
19
|
describe "#post" do
|
20
|
-
it "
|
20
|
+
it "returns a valid HTTPI::Response" do
|
21
21
|
request = HTTPI::Request.new :url => "http://example.com", :body => Fixture.xml
|
22
22
|
httpclient.expects(:post).with(request.url, request.body, request.headers).returns(http_message)
|
23
23
|
|
@@ -26,14 +26,14 @@ describe HTTPI::Adapter::HTTPClient do
|
|
26
26
|
end
|
27
27
|
|
28
28
|
describe "#head" do
|
29
|
-
it "
|
29
|
+
it "returns a valid HTTPI::Response" do
|
30
30
|
httpclient.expects(:head).with(basic_request.url, nil, basic_request.headers).returns(http_message)
|
31
31
|
adapter.head(basic_request).should match_response(:body => Fixture.xml)
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
35
35
|
describe "#put" do
|
36
|
-
it "
|
36
|
+
it "returns a valid HTTPI::Response" do
|
37
37
|
request = HTTPI::Request.new :url => "http://example.com", :body => Fixture.xml
|
38
38
|
httpclient.expects(:put).with(request.url, request.body, request.headers).returns(http_message)
|
39
39
|
|
@@ -42,7 +42,7 @@ describe HTTPI::Adapter::HTTPClient do
|
|
42
42
|
end
|
43
43
|
|
44
44
|
describe "#delete" do
|
45
|
-
it "
|
45
|
+
it "returns a valid HTTPI::Response" do
|
46
46
|
httpclient.expects(:delete).with(basic_request.url, basic_request.headers).returns(http_message(""))
|
47
47
|
adapter.delete(basic_request).should match_response(:body => "")
|
48
48
|
end
|
@@ -52,16 +52,16 @@ describe HTTPI::Adapter::HTTPClient do
|
|
52
52
|
before { httpclient.stubs(:get).returns(http_message) }
|
53
53
|
|
54
54
|
describe "proxy" do
|
55
|
-
it "should
|
55
|
+
it "have should specs"
|
56
56
|
end
|
57
57
|
|
58
58
|
describe "connect_timeout" do
|
59
|
-
it "
|
59
|
+
it "is not set unless specified" do
|
60
60
|
httpclient.expects(:connect_timeout=).never
|
61
61
|
adapter.get(basic_request)
|
62
62
|
end
|
63
63
|
|
64
|
-
it "
|
64
|
+
it "is set if specified" do
|
65
65
|
request = basic_request { |request| request.open_timeout = 30 }
|
66
66
|
|
67
67
|
httpclient.expects(:connect_timeout=).with(30)
|
@@ -70,12 +70,12 @@ describe HTTPI::Adapter::HTTPClient do
|
|
70
70
|
end
|
71
71
|
|
72
72
|
describe "receive_timeout" do
|
73
|
-
it "
|
73
|
+
it "is not set unless specified" do
|
74
74
|
httpclient.expects(:receive_timeout=).never
|
75
75
|
adapter.get(basic_request)
|
76
76
|
end
|
77
77
|
|
78
|
-
it "
|
78
|
+
it "is set if specified" do
|
79
79
|
request = basic_request { |request| request.read_timeout = 30 }
|
80
80
|
|
81
81
|
httpclient.expects(:receive_timeout=).with(30)
|
@@ -84,14 +84,14 @@ describe HTTPI::Adapter::HTTPClient do
|
|
84
84
|
end
|
85
85
|
|
86
86
|
describe "set_auth" do
|
87
|
-
it "
|
87
|
+
it "is set for HTTP basic auth" do
|
88
88
|
request = basic_request { |request| request.auth.basic "username", "password" }
|
89
89
|
|
90
90
|
httpclient.expects(:set_auth).with(request.url, *request.auth.credentials)
|
91
91
|
adapter.get(request)
|
92
92
|
end
|
93
93
|
|
94
|
-
it "
|
94
|
+
it "is set for HTTP digest auth" do
|
95
95
|
request = basic_request { |request| request.auth.digest "username", "password" }
|
96
96
|
|
97
97
|
httpclient.expects(:set_auth).with(request.url, *request.auth.credentials)
|
@@ -115,7 +115,7 @@ describe HTTPI::Adapter::HTTPClient do
|
|
115
115
|
adapter.get(ssl_auth_request)
|
116
116
|
end
|
117
117
|
|
118
|
-
it "
|
118
|
+
it "sets the client_ca if specified" do
|
119
119
|
ssl_auth_request.auth.ssl.ca_cert_file = "spec/fixtures/client_cert.pem"
|
120
120
|
ssl_config.expects(:client_ca=).with(ssl_auth_request.auth.ssl.ca_cert)
|
121
121
|
|
@@ -136,15 +136,15 @@ describe HTTPI::Adapter::HTTPClient do
|
|
136
136
|
adapter.get(ssl_auth_request)
|
137
137
|
end
|
138
138
|
|
139
|
-
it "
|
139
|
+
it "does not set client_cert and client_key "do
|
140
140
|
ssl_config.expects(:client_cert=).never
|
141
141
|
ssl_config.expects(:client_key=).never
|
142
142
|
|
143
143
|
adapter.get(ssl_auth_request)
|
144
144
|
end
|
145
145
|
|
146
|
-
it "
|
147
|
-
|
146
|
+
it "does not raise an exception" do
|
147
|
+
expect { adapter.get(ssl_auth_request) }.to_not raise_error
|
148
148
|
end
|
149
149
|
end
|
150
150
|
end
|
data/spec/httpi/adapter_spec.rb
CHANGED
@@ -1,40 +1,54 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
require "httpi/adapter"
|
3
3
|
|
4
|
-
|
5
4
|
describe HTTPI::Adapter do
|
6
5
|
let(:adapter) { HTTPI::Adapter }
|
7
6
|
|
8
7
|
describe ".use" do
|
9
|
-
|
10
|
-
adapter.use
|
8
|
+
around do |example|
|
9
|
+
adapter.use = nil
|
10
|
+
example.run
|
11
|
+
adapter.use = nil
|
12
|
+
end
|
11
13
|
|
12
|
-
|
13
|
-
adapter.use.
|
14
|
+
it "sets the adapter to use" do
|
15
|
+
adapter.use.should_not == :net_http
|
14
16
|
|
15
|
-
adapter.use =
|
17
|
+
adapter.use = :net_http
|
18
|
+
adapter.use.should == :net_http
|
16
19
|
end
|
17
20
|
|
18
|
-
it "
|
21
|
+
it "defaults to use the HTTPClient adapter" do
|
19
22
|
adapter.use.should == :httpclient
|
20
23
|
end
|
21
24
|
|
22
|
-
it "
|
23
|
-
|
25
|
+
it "loads the adapter's client library" do
|
26
|
+
adapter.expects(:require).with("httpclient")
|
27
|
+
adapter.use = :httpclient
|
28
|
+
end
|
29
|
+
|
30
|
+
it "raises an ArgumentError in case of an invalid adapter" do
|
31
|
+
expect { adapter.use = :unknown }.to raise_error(ArgumentError)
|
24
32
|
end
|
25
33
|
end
|
26
34
|
|
27
35
|
describe ".load" do
|
28
|
-
|
29
|
-
adapter
|
36
|
+
context "called with a valid adapter" do
|
37
|
+
it "returns the adapter's name and class" do
|
38
|
+
adapter.load(:curb).should == [:curb, HTTPI::Adapter::Curb]
|
39
|
+
end
|
30
40
|
end
|
31
41
|
|
32
|
-
|
33
|
-
adapter
|
42
|
+
context "called with nil" do
|
43
|
+
it "returns the default adapter's name and class" do
|
44
|
+
adapter.load(nil).should == [:httpclient, HTTPI::Adapter::HTTPClient]
|
45
|
+
end
|
34
46
|
end
|
35
47
|
|
36
|
-
|
37
|
-
|
48
|
+
context "called with an invalid adapter" do
|
49
|
+
it "raises an ArgumentError" do
|
50
|
+
expect { adapter.use = :unknown }.to raise_error(ArgumentError)
|
51
|
+
end
|
38
52
|
end
|
39
53
|
end
|
40
54
|
|
@@ -9,7 +9,7 @@ describe HTTPI::Auth::Config do
|
|
9
9
|
auth.basic "username", "password"
|
10
10
|
auth.basic.should == ["username", "password"]
|
11
11
|
end
|
12
|
-
|
12
|
+
|
13
13
|
it "also accepts an Array of credentials" do
|
14
14
|
auth.basic ["username", "password"]
|
15
15
|
auth.basic.should == ["username", "password"]
|
@@ -22,11 +22,11 @@ describe HTTPI::Auth::Config do
|
|
22
22
|
end
|
23
23
|
|
24
24
|
describe "#basic?" do
|
25
|
-
it "
|
25
|
+
it "defaults to return false" do
|
26
26
|
auth.should_not be_basic
|
27
27
|
end
|
28
28
|
|
29
|
-
it "
|
29
|
+
it "returns true for HTTP basic auth" do
|
30
30
|
auth.basic "username", "password"
|
31
31
|
auth.should be_basic
|
32
32
|
end
|
@@ -37,7 +37,7 @@ describe HTTPI::Auth::Config do
|
|
37
37
|
auth.digest "username", "password"
|
38
38
|
auth.digest.should == ["username", "password"]
|
39
39
|
end
|
40
|
-
|
40
|
+
|
41
41
|
it "also accepts an Array of credentials" do
|
42
42
|
auth.digest ["username", "password"]
|
43
43
|
auth.digest.should == ["username", "password"]
|
@@ -50,65 +50,65 @@ describe HTTPI::Auth::Config do
|
|
50
50
|
end
|
51
51
|
|
52
52
|
describe "#digest?" do
|
53
|
-
it "
|
53
|
+
it "defaults to return false" do
|
54
54
|
auth.should_not be_digest
|
55
55
|
end
|
56
56
|
|
57
|
-
it "
|
57
|
+
it "returns true for HTTP digest auth" do
|
58
58
|
auth.digest "username", "password"
|
59
59
|
auth.should be_digest
|
60
60
|
end
|
61
61
|
end
|
62
62
|
|
63
63
|
describe "#http?" do
|
64
|
-
it "
|
64
|
+
it "defaults to return false" do
|
65
65
|
auth.should_not be_http
|
66
66
|
end
|
67
67
|
|
68
|
-
it "
|
68
|
+
it "returns true for HTTP basic auth" do
|
69
69
|
auth.basic "username", "password"
|
70
70
|
auth.should be_http
|
71
71
|
end
|
72
72
|
|
73
|
-
it "
|
73
|
+
it "returns true for HTTP digest auth" do
|
74
74
|
auth.digest "username", "password"
|
75
75
|
auth.should be_http
|
76
76
|
end
|
77
77
|
end
|
78
78
|
|
79
79
|
describe "#ssl" do
|
80
|
-
it "
|
80
|
+
it "returns the HTTPI::Auth::SSL object" do
|
81
81
|
auth.ssl.should be_a(HTTPI::Auth::SSL)
|
82
82
|
end
|
83
83
|
end
|
84
84
|
|
85
85
|
describe "#ssl?" do
|
86
|
-
it "
|
86
|
+
it "defaults to return false" do
|
87
87
|
auth.should_not be_ssl
|
88
88
|
end
|
89
89
|
|
90
|
-
it "
|
90
|
+
it "returns true for SSL client auth" do
|
91
91
|
auth.ssl.cert_key_file = "spec/fixtures/client_key.pem"
|
92
92
|
auth.ssl.cert_file = "spec/fixtures/client_cert.pem"
|
93
|
-
|
93
|
+
|
94
94
|
auth.should be_ssl
|
95
95
|
end
|
96
96
|
end
|
97
97
|
|
98
98
|
describe "#type" do
|
99
|
-
it "
|
99
|
+
it "returns the authentication type" do
|
100
100
|
auth.basic "username", "password"
|
101
101
|
auth.type.should == :basic
|
102
102
|
end
|
103
103
|
end
|
104
104
|
|
105
105
|
describe "#credentials" do
|
106
|
-
it "
|
106
|
+
it "returns the credentials for HTTP basic auth" do
|
107
107
|
auth.basic "username", "basic"
|
108
108
|
auth.credentials.should == ["username", "basic"]
|
109
109
|
end
|
110
110
|
|
111
|
-
it "
|
111
|
+
it "returns the credentials for HTTP digest auth" do
|
112
112
|
auth.digest "username", "digest"
|
113
113
|
auth.credentials.should == ["username", "digest"]
|
114
114
|
end
|
data/spec/httpi/auth/ssl_spec.rb
CHANGED
@@ -4,36 +4,36 @@ require "httpi/auth/ssl"
|
|
4
4
|
describe HTTPI::Auth::SSL do
|
5
5
|
|
6
6
|
describe "VERIFY_MODES" do
|
7
|
-
it "
|
7
|
+
it "contains the supported SSL verify modes" do
|
8
8
|
HTTPI::Auth::SSL::VERIFY_MODES.should == [:none, :peer, :fail_if_no_peer_cert, :client_once]
|
9
9
|
end
|
10
10
|
end
|
11
11
|
|
12
12
|
describe "#present?" do
|
13
|
-
it "
|
13
|
+
it "defaults to return false" do
|
14
14
|
ssl = HTTPI::Auth::SSL.new
|
15
15
|
ssl.should_not be_present
|
16
16
|
end
|
17
17
|
|
18
|
-
it "
|
18
|
+
it "returns false if only a client key was specified" do
|
19
19
|
ssl = HTTPI::Auth::SSL.new
|
20
20
|
ssl.cert_key_file = "spec/fixtures/client_key.pem"
|
21
21
|
|
22
22
|
ssl.should_not be_present
|
23
23
|
end
|
24
24
|
|
25
|
-
it "
|
25
|
+
it "returns false if only a client key was specified" do
|
26
26
|
ssl = HTTPI::Auth::SSL.new
|
27
27
|
ssl.cert_file = "spec/fixtures/client_cert.pem"
|
28
28
|
|
29
29
|
ssl.should_not be_present
|
30
30
|
end
|
31
31
|
|
32
|
-
it "
|
32
|
+
it "returns true if both client key and cert are present" do
|
33
33
|
ssl.should be_present
|
34
34
|
end
|
35
35
|
|
36
|
-
it "
|
36
|
+
it "returns true of the verify_mode is :none" do
|
37
37
|
ssl = HTTPI::Auth::SSL.new
|
38
38
|
ssl.verify_mode = :none
|
39
39
|
ssl.should be_present
|
@@ -41,46 +41,46 @@ describe HTTPI::Auth::SSL do
|
|
41
41
|
end
|
42
42
|
|
43
43
|
describe "#verify_mode" do
|
44
|
-
it "
|
44
|
+
it "defaults to return :peer" do
|
45
45
|
ssl.verify_mode.should == :peer
|
46
46
|
end
|
47
47
|
|
48
|
-
it "
|
48
|
+
it "sets the verify mode to use" do
|
49
49
|
ssl = HTTPI::Auth::SSL.new
|
50
50
|
|
51
51
|
ssl.verify_mode = :none
|
52
52
|
ssl.verify_mode.should == :none
|
53
53
|
end
|
54
54
|
|
55
|
-
it "
|
56
|
-
|
55
|
+
it "raises an ArgumentError if the given mode is not supported" do
|
56
|
+
expect { ssl.verify_mode = :invalid }.to raise_error(ArgumentError)
|
57
57
|
end
|
58
58
|
end
|
59
59
|
|
60
60
|
describe "#cert" do
|
61
|
-
it "
|
61
|
+
it "returns an OpenSSL::X509::Certificate for the given cert_file" do
|
62
62
|
ssl.cert.should be_a(OpenSSL::X509::Certificate)
|
63
63
|
end
|
64
64
|
|
65
|
-
it "
|
65
|
+
it "returns nil if no cert_file was given" do
|
66
66
|
ssl = HTTPI::Auth::SSL.new
|
67
67
|
ssl.cert.should be_nil
|
68
68
|
end
|
69
69
|
end
|
70
70
|
|
71
71
|
describe "#cert_key" do
|
72
|
-
it "
|
72
|
+
it "returns a OpenSSL::PKey::RSA for the given cert_key" do
|
73
73
|
ssl.cert_key.should be_a(OpenSSL::PKey::RSA)
|
74
74
|
end
|
75
75
|
|
76
|
-
it "
|
76
|
+
it "returns nil if no cert_key_file was given" do
|
77
77
|
ssl = HTTPI::Auth::SSL.new
|
78
78
|
ssl.cert_key.should be_nil
|
79
79
|
end
|
80
80
|
end
|
81
81
|
|
82
82
|
describe "#ca_cert" do
|
83
|
-
it "
|
83
|
+
it "returns an OpenSSL::X509::Certificate for the given ca_cert_file" do
|
84
84
|
ssl = HTTPI::Auth::SSL.new
|
85
85
|
|
86
86
|
ssl.ca_cert_file = "spec/fixtures/client_cert.pem"
|
@@ -89,28 +89,28 @@ describe HTTPI::Auth::SSL do
|
|
89
89
|
end
|
90
90
|
|
91
91
|
describe "#openssl_verify_mode" do
|
92
|
-
it "
|
92
|
+
it "returns the OpenSSL verify mode for :none" do
|
93
93
|
ssl = HTTPI::Auth::SSL.new
|
94
94
|
|
95
95
|
ssl.verify_mode = :none
|
96
96
|
ssl.openssl_verify_mode.should == OpenSSL::SSL::VERIFY_NONE
|
97
97
|
end
|
98
98
|
|
99
|
-
it "
|
99
|
+
it "returns the OpenSSL verify mode for :peer" do
|
100
100
|
ssl = HTTPI::Auth::SSL.new
|
101
101
|
|
102
102
|
ssl.verify_mode = :peer
|
103
103
|
ssl.openssl_verify_mode.should == OpenSSL::SSL::VERIFY_PEER
|
104
104
|
end
|
105
105
|
|
106
|
-
it "
|
106
|
+
it "returns the OpenSSL verify mode for :fail_if_no_peer_cert" do
|
107
107
|
ssl = HTTPI::Auth::SSL.new
|
108
108
|
|
109
109
|
ssl.verify_mode = :fail_if_no_peer_cert
|
110
110
|
ssl.openssl_verify_mode.should == OpenSSL::SSL::VERIFY_FAIL_IF_NO_PEER_CERT
|
111
111
|
end
|
112
112
|
|
113
|
-
it "
|
113
|
+
it "returns the OpenSSL verify mode for :client_once" do
|
114
114
|
ssl = HTTPI::Auth::SSL.new
|
115
115
|
|
116
116
|
ssl.verify_mode = :client_once
|
data/spec/httpi/httpi_spec.rb
CHANGED
@@ -7,7 +7,7 @@ describe HTTPI do
|
|
7
7
|
let(:curb) { HTTPI::Adapter.load(:curb)[1] }
|
8
8
|
|
9
9
|
describe ".get(request)" do
|
10
|
-
it "
|
10
|
+
it "executes a GET request using the default adapter" do
|
11
11
|
request = HTTPI::Request.new
|
12
12
|
httpclient.any_instance.expects(:get).with(request)
|
13
13
|
|
@@ -16,7 +16,7 @@ describe HTTPI do
|
|
16
16
|
end
|
17
17
|
|
18
18
|
describe ".get(request, adapter)" do
|
19
|
-
it "
|
19
|
+
it "executes a GET request using the given adapter" do
|
20
20
|
request = HTTPI::Request.new
|
21
21
|
curb.any_instance.expects(:get).with(request)
|
22
22
|
|
@@ -25,7 +25,7 @@ describe HTTPI do
|
|
25
25
|
end
|
26
26
|
|
27
27
|
describe ".get(url)" do
|
28
|
-
it "
|
28
|
+
it "executes a GET request using the default adapter" do
|
29
29
|
HTTPI::Request.any_instance.expects(:url=).with("http://example.com")
|
30
30
|
httpclient.any_instance.expects(:get).with(instance_of(HTTPI::Request))
|
31
31
|
|
@@ -34,7 +34,7 @@ describe HTTPI do
|
|
34
34
|
end
|
35
35
|
|
36
36
|
describe ".get(url, adapter)" do
|
37
|
-
it "
|
37
|
+
it "executes a GET request using the given adapter" do
|
38
38
|
HTTPI::Request.any_instance.expects(:url=).with("http://example.com")
|
39
39
|
curb.any_instance.expects(:get).with(instance_of(HTTPI::Request))
|
40
40
|
|
@@ -43,7 +43,7 @@ describe HTTPI do
|
|
43
43
|
end
|
44
44
|
|
45
45
|
describe ".post(request)" do
|
46
|
-
it "
|
46
|
+
it "executes a POST request using the default adapter" do
|
47
47
|
request = HTTPI::Request.new
|
48
48
|
httpclient.any_instance.expects(:post).with(request)
|
49
49
|
|
@@ -52,7 +52,7 @@ describe HTTPI do
|
|
52
52
|
end
|
53
53
|
|
54
54
|
describe ".post(request, adapter)" do
|
55
|
-
it "
|
55
|
+
it "executes a POST request using the given adapter" do
|
56
56
|
request = HTTPI::Request.new
|
57
57
|
curb.any_instance.expects(:post).with(request)
|
58
58
|
|
@@ -61,7 +61,7 @@ describe HTTPI do
|
|
61
61
|
end
|
62
62
|
|
63
63
|
describe ".post(url, body)" do
|
64
|
-
it "
|
64
|
+
it "executes a POST request using the default adapter" do
|
65
65
|
HTTPI::Request.any_instance.expects(:url=).with("http://example.com")
|
66
66
|
HTTPI::Request.any_instance.expects(:body=).with("<some>xml</some>")
|
67
67
|
httpclient.any_instance.expects(:post).with(instance_of(HTTPI::Request))
|
@@ -71,7 +71,7 @@ describe HTTPI do
|
|
71
71
|
end
|
72
72
|
|
73
73
|
describe ".post(url, body, adapter)" do
|
74
|
-
it "
|
74
|
+
it "executes a POST request using the given adapter" do
|
75
75
|
HTTPI::Request.any_instance.expects(:url=).with("http://example.com")
|
76
76
|
HTTPI::Request.any_instance.expects(:body=).with("<some>xml</some>")
|
77
77
|
curb.any_instance.expects(:post).with(instance_of(HTTPI::Request))
|
@@ -81,7 +81,7 @@ describe HTTPI do
|
|
81
81
|
end
|
82
82
|
|
83
83
|
describe ".head(request)" do
|
84
|
-
it "
|
84
|
+
it "executes a HEAD request using the default adapter" do
|
85
85
|
request = HTTPI::Request.new
|
86
86
|
httpclient.any_instance.expects(:head).with(request)
|
87
87
|
|
@@ -90,7 +90,7 @@ describe HTTPI do
|
|
90
90
|
end
|
91
91
|
|
92
92
|
describe ".head(request, adapter)" do
|
93
|
-
it "
|
93
|
+
it "executes a HEAD request using the given adapter" do
|
94
94
|
request = HTTPI::Request.new
|
95
95
|
curb.any_instance.expects(:head).with(request)
|
96
96
|
|
@@ -99,7 +99,7 @@ describe HTTPI do
|
|
99
99
|
end
|
100
100
|
|
101
101
|
describe ".head(url)" do
|
102
|
-
it "
|
102
|
+
it "executes a HEAD request using the default adapter" do
|
103
103
|
HTTPI::Request.any_instance.expects(:url=).with("http://example.com")
|
104
104
|
httpclient.any_instance.expects(:head).with(instance_of(HTTPI::Request))
|
105
105
|
|
@@ -108,7 +108,7 @@ describe HTTPI do
|
|
108
108
|
end
|
109
109
|
|
110
110
|
describe ".head(url, adapter)" do
|
111
|
-
it "
|
111
|
+
it "executes a HEAD request using the given adapter" do
|
112
112
|
HTTPI::Request.any_instance.expects(:url=).with("http://example.com")
|
113
113
|
curb.any_instance.expects(:head).with(instance_of(HTTPI::Request))
|
114
114
|
|
@@ -117,7 +117,7 @@ describe HTTPI do
|
|
117
117
|
end
|
118
118
|
|
119
119
|
describe ".put(request)" do
|
120
|
-
it "
|
120
|
+
it "executes a PUT request using the default adapter" do
|
121
121
|
request = HTTPI::Request.new
|
122
122
|
httpclient.any_instance.expects(:put).with(request)
|
123
123
|
|
@@ -126,7 +126,7 @@ describe HTTPI do
|
|
126
126
|
end
|
127
127
|
|
128
128
|
describe ".put(request, adapter)" do
|
129
|
-
it "
|
129
|
+
it "executes a PUT request using the given adapter" do
|
130
130
|
request = HTTPI::Request.new
|
131
131
|
curb.any_instance.expects(:put).with(request)
|
132
132
|
|
@@ -135,7 +135,7 @@ describe HTTPI do
|
|
135
135
|
end
|
136
136
|
|
137
137
|
describe ".put(url, body)" do
|
138
|
-
it "
|
138
|
+
it "executes a PUT request using the default adapter" do
|
139
139
|
HTTPI::Request.any_instance.expects(:url=).with("http://example.com")
|
140
140
|
HTTPI::Request.any_instance.expects(:body=).with("<some>xml</some>")
|
141
141
|
httpclient.any_instance.expects(:put).with(instance_of(HTTPI::Request))
|
@@ -145,7 +145,7 @@ describe HTTPI do
|
|
145
145
|
end
|
146
146
|
|
147
147
|
describe ".put(url, body, adapter)" do
|
148
|
-
it "
|
148
|
+
it "executes a PUT request using the given adapter" do
|
149
149
|
HTTPI::Request.any_instance.expects(:url=).with("http://example.com")
|
150
150
|
HTTPI::Request.any_instance.expects(:body=).with("<some>xml</some>")
|
151
151
|
curb.any_instance.expects(:put).with(instance_of(HTTPI::Request))
|
@@ -155,7 +155,7 @@ describe HTTPI do
|
|
155
155
|
end
|
156
156
|
|
157
157
|
describe ".delete(request)" do
|
158
|
-
it "
|
158
|
+
it "executes a DELETE request using the default adapter" do
|
159
159
|
request = HTTPI::Request.new
|
160
160
|
httpclient.any_instance.expects(:delete).with(request)
|
161
161
|
|
@@ -164,7 +164,7 @@ describe HTTPI do
|
|
164
164
|
end
|
165
165
|
|
166
166
|
describe ".delete(request, adapter)" do
|
167
|
-
it "
|
167
|
+
it "executes a DELETE request using the given adapter" do
|
168
168
|
request = HTTPI::Request.new
|
169
169
|
curb.any_instance.expects(:delete).with(request)
|
170
170
|
|
@@ -173,7 +173,7 @@ describe HTTPI do
|
|
173
173
|
end
|
174
174
|
|
175
175
|
describe ".delete(url)" do
|
176
|
-
it "
|
176
|
+
it "executes a DELETE request using the default adapter" do
|
177
177
|
HTTPI::Request.any_instance.expects(:url=).with("http://example.com")
|
178
178
|
httpclient.any_instance.expects(:delete).with(instance_of(HTTPI::Request))
|
179
179
|
|
@@ -182,7 +182,7 @@ describe HTTPI do
|
|
182
182
|
end
|
183
183
|
|
184
184
|
describe ".delete(url, adapter)" do
|
185
|
-
it "
|
185
|
+
it "executes a DELETE request using the given adapter" do
|
186
186
|
HTTPI::Request.any_instance.expects(:url=).with("http://example.com")
|
187
187
|
curb.any_instance.expects(:delete).with(instance_of(HTTPI::Request))
|
188
188
|
|
@@ -191,14 +191,21 @@ describe HTTPI do
|
|
191
191
|
end
|
192
192
|
|
193
193
|
describe ".request" do
|
194
|
-
it "
|
195
|
-
|
194
|
+
it "raises an ArgumentError in case of an invalid request method" do
|
195
|
+
expect { client.request :invalid, HTTPI::Request.new }.to raise_error(ArgumentError)
|
196
|
+
end
|
197
|
+
end
|
198
|
+
|
199
|
+
describe ".adapter=" do
|
200
|
+
it "sets the default adapter to use" do
|
201
|
+
HTTPI::Adapter.expects(:use=).with(:net_http)
|
202
|
+
HTTPI.adapter = :net_http
|
196
203
|
end
|
197
204
|
end
|
198
205
|
|
199
206
|
HTTPI::REQUEST_METHODS.each do |method|
|
200
207
|
describe ".request(#{method}, request, adapter)" do
|
201
|
-
it "
|
208
|
+
it "delegates to the .#{method} method" do
|
202
209
|
HTTPI.expects(method)
|
203
210
|
client.request method, HTTPI::Request.new
|
204
211
|
end
|
@@ -207,15 +214,15 @@ describe HTTPI do
|
|
207
214
|
describe ".#{method}" do
|
208
215
|
let(:request) { HTTPI::Request.new :url => "http://example.com" }
|
209
216
|
|
210
|
-
it "
|
211
|
-
|
217
|
+
it "raises an ArgumentError in case of an invalid adapter" do
|
218
|
+
expect { client.request method, request, :invalid }.to raise_error(ArgumentError)
|
212
219
|
end
|
213
220
|
|
214
|
-
it "
|
215
|
-
|
221
|
+
it "raises an ArgumentError in case of an invalid request" do
|
222
|
+
expect { client.request method, "invalid" }.to raise_error(ArgumentError)
|
216
223
|
end
|
217
224
|
|
218
|
-
HTTPI::Adapter::ADAPTERS.each do |adapter,
|
225
|
+
HTTPI::Adapter::ADAPTERS.each do |adapter, opts|
|
219
226
|
client_class = {
|
220
227
|
:httpclient => lambda { HTTPClient },
|
221
228
|
:curb => lambda { Curl::Easy },
|
@@ -223,15 +230,15 @@ describe HTTPI do
|
|
223
230
|
}
|
224
231
|
|
225
232
|
context "using #{adapter}" do
|
226
|
-
before {
|
233
|
+
before { opts[:class].any_instance.expects(method) }
|
227
234
|
|
228
|
-
it "
|
235
|
+
it "logs that we're executing a request" do
|
229
236
|
HTTPI.expects(:log).with(:debug, "HTTPI executes HTTP #{method.to_s.upcase} using the #{adapter} adapter")
|
230
237
|
client.request method, request, adapter
|
231
238
|
end
|
232
239
|
|
233
|
-
it "
|
234
|
-
block = lambda { |http| http.
|
240
|
+
it "yields the HTTP client instance used for the request" do
|
241
|
+
block = lambda { |http| http.be_a(client_class[adapter].call) }
|
235
242
|
client.request(method, request, adapter, &block)
|
236
243
|
end
|
237
244
|
end
|
@@ -239,7 +246,7 @@ describe HTTPI do
|
|
239
246
|
end
|
240
247
|
end
|
241
248
|
|
242
|
-
context "with
|
249
|
+
context "(with reset)" do
|
243
250
|
before { HTTPI.reset_config! }
|
244
251
|
|
245
252
|
after do
|
@@ -248,41 +255,25 @@ describe HTTPI do
|
|
248
255
|
end
|
249
256
|
|
250
257
|
describe ".log" do
|
251
|
-
it "
|
258
|
+
it "defaults to true" do
|
252
259
|
HTTPI.log?.should be_true
|
253
260
|
end
|
254
|
-
|
255
|
-
it "should set whether to log" do
|
256
|
-
HTTPI.log = false
|
257
|
-
HTTPI.log?.should be_false
|
258
|
-
end
|
259
261
|
end
|
260
262
|
|
261
263
|
describe ".logger" do
|
262
|
-
it "
|
264
|
+
it "defaults to Logger writing to STDOUT" do
|
263
265
|
HTTPI.logger.should be_a(Logger)
|
264
266
|
end
|
265
|
-
|
266
|
-
it "should set the logger to use" do
|
267
|
-
MyLogger = Class.new
|
268
|
-
HTTPI.logger = MyLogger
|
269
|
-
HTTPI.logger.should == MyLogger
|
270
|
-
end
|
271
267
|
end
|
272
268
|
|
273
269
|
describe ".log_level" do
|
274
|
-
it "
|
270
|
+
it "defaults to :warn" do
|
275
271
|
HTTPI.log_level.should == :warn
|
276
272
|
end
|
277
|
-
|
278
|
-
it "should set the log level to use" do
|
279
|
-
HTTPI.log_level = :info
|
280
|
-
HTTPI.log_level.should == :info
|
281
|
-
end
|
282
273
|
end
|
283
274
|
|
284
275
|
describe ".log" do
|
285
|
-
it "
|
276
|
+
it "logs the given messages" do
|
286
277
|
HTTPI.log_level = :debug
|
287
278
|
HTTPI.logger.expects(:debug).with("Log this")
|
288
279
|
HTTPI.log "Log", "this"
|