rest-client 1.6.1 → 1.6.14
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.
Potentially problematic release.
This version of rest-client might be problematic. Click here for more details.
- checksums.yaml +7 -0
- data/.gitignore +8 -0
- data/.rspec +1 -0
- data/.travis.yml +3 -0
- data/AUTHORS +75 -0
- data/Gemfile +7 -0
- data/README.rdoc +52 -21
- data/Rakefile +15 -35
- data/bin/restclient +45 -39
- data/history.md +67 -1
- data/lib/restclient.rb +11 -6
- data/lib/restclient/abstract_response.rb +6 -2
- data/lib/restclient/exceptions.rb +22 -5
- data/lib/restclient/net_http_ext.rb +41 -7
- data/lib/restclient/payload.rb +28 -8
- data/lib/restclient/platform.rb +29 -0
- data/lib/restclient/request.rb +96 -36
- data/lib/restclient/resource.rb +17 -0
- data/lib/restclient/response.rb +3 -1
- data/lib/restclient/version.rb +7 -0
- data/rest-client.gemspec +26 -0
- data/spec/abstract_response_spec.rb +28 -10
- data/spec/base.rb +1 -4
- data/spec/exceptions_spec.rb +31 -12
- data/spec/integration/capath_digicert/244b5494.0 +19 -0
- data/spec/integration/capath_digicert/81b9768f.0 +19 -0
- data/spec/integration/capath_digicert/README +8 -0
- data/spec/integration/capath_digicert/digicert.crt +19 -0
- data/spec/integration/certs/digicert.crt +19 -0
- data/spec/integration/certs/verisign.crt +14 -14
- data/spec/integration/request_spec.rb +54 -4
- data/spec/integration_spec.rb +9 -9
- data/spec/master_shake.jpg +0 -0
- data/spec/payload_spec.rb +60 -35
- data/spec/raw_response_spec.rb +4 -4
- data/spec/request2_spec.rb +22 -4
- data/spec/request_spec.rb +129 -130
- data/spec/resource_spec.rb +30 -18
- data/spec/response_spec.rb +48 -36
- data/spec/restclient_spec.rb +6 -1
- metadata +142 -74
- data/VERSION +0 -1
- data/spec/integration/certs/equifax.crt +0 -19
data/spec/integration_spec.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require File.join( File.dirname(File.expand_path(__FILE__)), 'base')
|
2
2
|
|
3
3
|
require 'webmock/rspec'
|
4
|
-
include WebMock
|
4
|
+
include WebMock::API
|
5
5
|
|
6
6
|
describe RestClient do
|
7
7
|
|
@@ -9,15 +9,15 @@ describe RestClient do
|
|
9
9
|
body = 'abc'
|
10
10
|
stub_request(:get, "www.example.com").to_return(:body => body, :status => 200)
|
11
11
|
response = RestClient.get "www.example.com"
|
12
|
-
response.code.should
|
13
|
-
response.body.should
|
12
|
+
response.code.should eq 200
|
13
|
+
response.body.should eq body
|
14
14
|
end
|
15
15
|
|
16
16
|
it "a simple request with gzipped content" do
|
17
17
|
stub_request(:get, "www.example.com").with(:headers => { 'Accept-Encoding' => 'gzip, deflate' }).to_return(:body => "\037\213\b\b\006'\252H\000\003t\000\313T\317UH\257\312,HM\341\002\000G\242(\r\v\000\000\000", :status => 200, :headers => { 'Content-Encoding' => 'gzip' } )
|
18
18
|
response = RestClient.get "www.example.com"
|
19
|
-
response.code.should
|
20
|
-
response.body.should
|
19
|
+
response.code.should eq 200
|
20
|
+
response.body.should eq "i'm gziped\n"
|
21
21
|
end
|
22
22
|
|
23
23
|
it "a 404" do
|
@@ -27,10 +27,10 @@ describe RestClient do
|
|
27
27
|
RestClient.get "www.example.com"
|
28
28
|
raise
|
29
29
|
rescue RestClient::ResourceNotFound => e
|
30
|
-
e.http_code.should
|
31
|
-
e.response.code.should
|
32
|
-
e.response.body.should
|
33
|
-
e.http_body.should
|
30
|
+
e.http_code.should eq 404
|
31
|
+
e.response.code.should eq 404
|
32
|
+
e.response.body.should eq body
|
33
|
+
e.http_body.should eq body
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
data/spec/master_shake.jpg
CHANGED
Binary file
|
data/spec/payload_spec.rb
CHANGED
@@ -1,29 +1,30 @@
|
|
1
|
-
|
1
|
+
# encoding: binary
|
2
|
+
require File.join(File.dirname(File.expand_path(__FILE__)), 'base')
|
2
3
|
|
3
4
|
describe RestClient::Payload do
|
4
5
|
context "A regular Payload" do
|
5
6
|
it "should use standard enctype as default content-type" do
|
6
7
|
RestClient::Payload::UrlEncoded.new({}).headers['Content-Type'].
|
7
|
-
|
8
|
+
should eq 'application/x-www-form-urlencoded'
|
8
9
|
end
|
9
10
|
|
10
11
|
it "should form properly encoded params" do
|
11
12
|
RestClient::Payload::UrlEncoded.new({:foo => 'bar'}).to_s.
|
12
|
-
|
13
|
+
should eq "foo=bar"
|
13
14
|
["foo=bar&baz=qux", "baz=qux&foo=bar"].should include(
|
14
|
-
|
15
|
+
RestClient::Payload::UrlEncoded.new({:foo => 'bar', :baz => 'qux'}).to_s)
|
15
16
|
end
|
16
17
|
|
17
18
|
it "should escape parameters" do
|
18
19
|
RestClient::Payload::UrlEncoded.new({'foo ' => 'bar'}).to_s.
|
19
|
-
|
20
|
+
should eq "foo%20=bar"
|
20
21
|
end
|
21
22
|
|
22
23
|
it "should properly handle hashes as parameter" do
|
23
|
-
RestClient::Payload::UrlEncoded.new({:foo => {:bar => 'baz'
|
24
|
-
|
25
|
-
RestClient::Payload::UrlEncoded.new({:foo => {:bar => {:baz => 'qux'
|
26
|
-
|
24
|
+
RestClient::Payload::UrlEncoded.new({:foo => {:bar => 'baz'}}).to_s.
|
25
|
+
should eq "foo[bar]=baz"
|
26
|
+
RestClient::Payload::UrlEncoded.new({:foo => {:bar => {:baz => 'qux'}}}).to_s.
|
27
|
+
should eq "foo[bar][baz]=qux"
|
27
28
|
end
|
28
29
|
|
29
30
|
it "should handle many attributes inside a hash" do
|
@@ -37,22 +38,27 @@ describe RestClient::Payload do
|
|
37
38
|
end
|
38
39
|
|
39
40
|
it "should handle attributes inside a an array inside an array inside an hash" do
|
40
|
-
parameters = RestClient::Payload::UrlEncoded.new({"foo" => [
|
41
|
+
parameters = RestClient::Payload::UrlEncoded.new({"foo" => [[{"bar" => 'baz'}, {"bar" => 'qux'}]]}).to_s
|
41
42
|
parameters.should include("foo[bar]=baz", "foo[bar]=qux")
|
42
43
|
end
|
43
44
|
|
44
45
|
it "should form properly use symbols as parameters" do
|
45
46
|
RestClient::Payload::UrlEncoded.new({:foo => :bar}).to_s.
|
46
|
-
|
47
|
-
RestClient::Payload::UrlEncoded.new({:foo => {:bar => :baz
|
48
|
-
|
47
|
+
should eq "foo=bar"
|
48
|
+
RestClient::Payload::UrlEncoded.new({:foo => {:bar => :baz}}).to_s.
|
49
|
+
should eq "foo[bar]=baz"
|
49
50
|
end
|
50
51
|
|
51
52
|
it "should properly handle arrays as repeated parameters" do
|
52
53
|
RestClient::Payload::UrlEncoded.new({:foo => ['bar']}).to_s.
|
53
|
-
|
54
|
+
should eq "foo[]=bar"
|
54
55
|
RestClient::Payload::UrlEncoded.new({:foo => ['bar', 'baz']}).to_s.
|
55
|
-
|
56
|
+
should eq "foo[]=bar&foo[]=baz"
|
57
|
+
end
|
58
|
+
|
59
|
+
it 'should not close if stream already closed' do
|
60
|
+
p = RestClient::Payload::UrlEncoded.new({'foo ' => 'bar'})
|
61
|
+
3.times {p.close}
|
56
62
|
end
|
57
63
|
|
58
64
|
end
|
@@ -60,13 +66,18 @@ describe RestClient::Payload do
|
|
60
66
|
context "A multipart Payload" do
|
61
67
|
it "should use standard enctype as default content-type" do
|
62
68
|
m = RestClient::Payload::Multipart.new({})
|
63
|
-
m.stub
|
64
|
-
m.headers['Content-Type'].should
|
69
|
+
m.stub(:boundary).and_return(123)
|
70
|
+
m.headers['Content-Type'].should eq 'multipart/form-data; boundary=123'
|
71
|
+
end
|
72
|
+
|
73
|
+
it 'should not error on close if stream already closed' do
|
74
|
+
m = RestClient::Payload::Multipart.new(:file => File.new(File.join(File.dirname(File.expand_path(__FILE__)), 'master_shake.jpg')))
|
75
|
+
3.times {m.close}
|
65
76
|
end
|
66
77
|
|
67
78
|
it "should form properly separated multipart data" do
|
68
79
|
m = RestClient::Payload::Multipart.new([[:bar, "baz"], [:foo, "bar"]])
|
69
|
-
m.to_s.should
|
80
|
+
m.to_s.should eq <<-EOS
|
70
81
|
--#{m.boundary}\r
|
71
82
|
Content-Disposition: form-data; name="bar"\r
|
72
83
|
\r
|
@@ -81,7 +92,7 @@ bar\r
|
|
81
92
|
|
82
93
|
it "should not escape parameters names" do
|
83
94
|
m = RestClient::Payload::Multipart.new([["bar ", "baz"]])
|
84
|
-
m.to_s.should
|
95
|
+
m.to_s.should eq <<-EOS
|
85
96
|
--#{m.boundary}\r
|
86
97
|
Content-Disposition: form-data; name="bar "\r
|
87
98
|
\r
|
@@ -93,12 +104,12 @@ baz\r
|
|
93
104
|
it "should form properly separated multipart data" do
|
94
105
|
f = File.new(File.dirname(__FILE__) + "/master_shake.jpg")
|
95
106
|
m = RestClient::Payload::Multipart.new({:foo => f})
|
96
|
-
m.to_s.should
|
107
|
+
m.to_s.should eq <<-EOS
|
97
108
|
--#{m.boundary}\r
|
98
109
|
Content-Disposition: form-data; name="foo"; filename="master_shake.jpg"\r
|
99
110
|
Content-Type: image/jpeg\r
|
100
111
|
\r
|
101
|
-
#{
|
112
|
+
#{File.open(f.path, 'rb'){|bin| bin.read}}\r
|
102
113
|
--#{m.boundary}--\r
|
103
114
|
EOS
|
104
115
|
end
|
@@ -106,12 +117,12 @@ Content-Type: image/jpeg\r
|
|
106
117
|
it "should ignore the name attribute when it's not set" do
|
107
118
|
f = File.new(File.dirname(__FILE__) + "/master_shake.jpg")
|
108
119
|
m = RestClient::Payload::Multipart.new({nil => f})
|
109
|
-
m.to_s.should
|
120
|
+
m.to_s.should eq <<-EOS
|
110
121
|
--#{m.boundary}\r
|
111
122
|
Content-Disposition: form-data; filename="master_shake.jpg"\r
|
112
123
|
Content-Type: image/jpeg\r
|
113
124
|
\r
|
114
|
-
#{
|
125
|
+
#{File.open(f.path, 'rb'){|bin| bin.read}}\r
|
115
126
|
--#{m.boundary}--\r
|
116
127
|
EOS
|
117
128
|
end
|
@@ -121,19 +132,19 @@ Content-Type: image/jpeg\r
|
|
121
132
|
f.instance_eval "def content_type; 'text/plain'; end"
|
122
133
|
f.instance_eval "def original_filename; 'foo.txt'; end"
|
123
134
|
m = RestClient::Payload::Multipart.new({:foo => f})
|
124
|
-
m.to_s.should
|
135
|
+
m.to_s.should eq <<-EOS
|
125
136
|
--#{m.boundary}\r
|
126
137
|
Content-Disposition: form-data; name="foo"; filename="foo.txt"\r
|
127
138
|
Content-Type: text/plain\r
|
128
139
|
\r
|
129
|
-
#{
|
140
|
+
#{File.open(f.path, 'rb'){|bin| bin.read}}\r
|
130
141
|
--#{m.boundary}--\r
|
131
142
|
EOS
|
132
143
|
end
|
133
144
|
|
134
145
|
it "should handle hash in hash parameters" do
|
135
146
|
m = RestClient::Payload::Multipart.new({:bar => {:baz => "foo"}})
|
136
|
-
m.to_s.should
|
147
|
+
m.to_s.should eq <<-EOS
|
137
148
|
--#{m.boundary}\r
|
138
149
|
Content-Disposition: form-data; name="bar[baz]"\r
|
139
150
|
\r
|
@@ -145,12 +156,12 @@ foo\r
|
|
145
156
|
f.instance_eval "def content_type; 'text/plain'; end"
|
146
157
|
f.instance_eval "def original_filename; 'foo.txt'; end"
|
147
158
|
m = RestClient::Payload::Multipart.new({:foo => {:bar => f}})
|
148
|
-
m.to_s.should
|
159
|
+
m.to_s.should eq <<-EOS
|
149
160
|
--#{m.boundary}\r
|
150
161
|
Content-Disposition: form-data; name="foo[bar]"; filename="foo.txt"\r
|
151
162
|
Content-Type: text/plain\r
|
152
163
|
\r
|
153
|
-
#{
|
164
|
+
#{File.open(f.path, 'rb'){|bin| bin.read}}\r
|
154
165
|
--#{m.boundary}--\r
|
155
166
|
EOS
|
156
167
|
end
|
@@ -161,23 +172,23 @@ Content-Type: text/plain\r
|
|
161
172
|
it "should properly determine the size of file payloads" do
|
162
173
|
f = File.new(File.dirname(__FILE__) + "/master_shake.jpg")
|
163
174
|
payload = RestClient::Payload.generate(f)
|
164
|
-
payload.size.should
|
165
|
-
payload.length.should
|
175
|
+
payload.size.should eq 76_988
|
176
|
+
payload.length.should eq 76_988
|
166
177
|
end
|
167
178
|
|
168
179
|
it "should properly determine the size of other kinds of streaming payloads" do
|
169
180
|
s = StringIO.new 'foo'
|
170
181
|
payload = RestClient::Payload.generate(s)
|
171
|
-
payload.size.should
|
172
|
-
payload.length.should
|
182
|
+
payload.size.should eq 3
|
183
|
+
payload.length.should eq 3
|
173
184
|
|
174
185
|
begin
|
175
186
|
f = Tempfile.new "rest-client"
|
176
187
|
f.write 'foo bar'
|
177
188
|
|
178
189
|
payload = RestClient::Payload.generate(f)
|
179
|
-
payload.size.should
|
180
|
-
payload.length.should
|
190
|
+
payload.size.should eq 7
|
191
|
+
payload.length.should eq 7
|
181
192
|
ensure
|
182
193
|
f.close
|
183
194
|
end
|
@@ -202,11 +213,16 @@ Content-Type: text/plain\r
|
|
202
213
|
RestClient::Payload.generate("data").should be_kind_of(RestClient::Payload::Base)
|
203
214
|
end
|
204
215
|
|
205
|
-
it "should recognize nested multipart payloads" do
|
216
|
+
it "should recognize nested multipart payloads in hashes" do
|
206
217
|
f = File.new(File.dirname(__FILE__) + "/master_shake.jpg")
|
207
218
|
RestClient::Payload.generate({"foo" => {"file" => f}}).should be_kind_of(RestClient::Payload::Multipart)
|
208
219
|
end
|
209
220
|
|
221
|
+
it "should recognize nested multipart payloads in arrays" do
|
222
|
+
f = File.new(File.dirname(__FILE__) + "/master_shake.jpg")
|
223
|
+
RestClient::Payload.generate({"foo" => [f]}).should be_kind_of(RestClient::Payload::Multipart)
|
224
|
+
end
|
225
|
+
|
210
226
|
it "should recognize file payloads that can be streamed" do
|
211
227
|
f = File.new(File.dirname(__FILE__) + "/master_shake.jpg")
|
212
228
|
RestClient::Payload.generate(f).should be_kind_of(RestClient::Payload::Streamed)
|
@@ -215,5 +231,14 @@ Content-Type: text/plain\r
|
|
215
231
|
it "should recognize other payloads that can be streamed" do
|
216
232
|
RestClient::Payload.generate(StringIO.new('foo')).should be_kind_of(RestClient::Payload::Streamed)
|
217
233
|
end
|
234
|
+
|
235
|
+
# hashery gem introduces Hash#read convenience method. Existence of #read method used to determine of content is streameable :/
|
236
|
+
it "shouldn't treat hashes as streameable" do
|
237
|
+
RestClient::Payload.generate({"foo" => 'bar'}).should be_kind_of(RestClient::Payload::UrlEncoded)
|
238
|
+
end
|
239
|
+
end
|
240
|
+
|
241
|
+
class HashMapForTesting < Hash
|
242
|
+
alias :read :[]
|
218
243
|
end
|
219
244
|
end
|
data/spec/raw_response_spec.rb
CHANGED
@@ -2,16 +2,16 @@ require File.join( File.dirname(File.expand_path(__FILE__)), 'base')
|
|
2
2
|
|
3
3
|
describe RestClient::RawResponse do
|
4
4
|
before do
|
5
|
-
@tf =
|
6
|
-
@net_http_res =
|
5
|
+
@tf = double("Tempfile", :read => "the answer is 42", :open => true)
|
6
|
+
@net_http_res = double('net http response')
|
7
7
|
@response = RestClient::RawResponse.new(@tf, @net_http_res, {})
|
8
8
|
end
|
9
9
|
|
10
10
|
it "behaves like string" do
|
11
|
-
@response.to_s.should
|
11
|
+
@response.to_s.should eq 'the answer is 42'
|
12
12
|
end
|
13
13
|
|
14
14
|
it "exposes a Tempfile" do
|
15
|
-
@response.file.should
|
15
|
+
@response.file.should eq @tf
|
16
16
|
end
|
17
17
|
end
|
data/spec/request2_spec.rb
CHANGED
@@ -1,17 +1,35 @@
|
|
1
1
|
require File.join( File.dirname(File.expand_path(__FILE__)), 'base')
|
2
2
|
|
3
3
|
require 'webmock/rspec'
|
4
|
-
include WebMock
|
4
|
+
include WebMock::API
|
5
5
|
|
6
6
|
describe RestClient::Request do
|
7
7
|
|
8
8
|
it "manage params for get requests" do
|
9
9
|
stub_request(:get, 'http://some/resource?a=b&c=d').with(:headers => {'Accept'=>'*/*; q=0.5, application/xml', 'Accept-Encoding'=>'gzip, deflate', 'Foo'=>'bar'}).to_return(:body => 'foo', :status => 200)
|
10
|
-
RestClient::Request.execute(:url => 'http://some/resource', :method => :get, :headers => {:foo => :bar, :params => {:a => :b, 'c' => 'd'}}).body.should
|
10
|
+
RestClient::Request.execute(:url => 'http://some/resource', :method => :get, :headers => {:foo => :bar, :params => {:a => :b, 'c' => 'd'}}).body.should eq 'foo'
|
11
11
|
|
12
12
|
stub_request(:get, 'http://some/resource').with(:headers => {'Accept'=>'*/*; q=0.5, application/xml', 'Accept-Encoding'=>'gzip, deflate', 'Foo'=>'bar', 'params' => 'a'}).to_return(:body => 'foo', :status => 200)
|
13
|
-
RestClient::Request.execute(:url => 'http://some/resource', :method => :get, :headers => {:foo => :bar, :params => :a}).body.should
|
13
|
+
RestClient::Request.execute(:url => 'http://some/resource', :method => :get, :headers => {:foo => :bar, :params => :a}).body.should eq 'foo'
|
14
14
|
end
|
15
15
|
|
16
|
-
|
16
|
+
it "can use a block to process response" do
|
17
|
+
response_value = nil
|
18
|
+
block = Proc.new do |http_response|
|
19
|
+
response_value = http_response.body
|
20
|
+
end
|
21
|
+
stub_request(:get, 'http://some/resource?a=b&c=d').with(:headers => {'Accept'=>'*/*; q=0.5, application/xml', 'Accept-Encoding'=>'gzip, deflate', 'Foo'=>'bar'}).to_return(:body => 'foo', :status => 200)
|
22
|
+
RestClient::Request.execute(:url => 'http://some/resource', :method => :get, :headers => {:foo => :bar, :params => {:a => :b, 'c' => 'd'}}, :block_response => block)
|
23
|
+
response_value.should eq "foo"
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'closes payload if not nil' do
|
27
|
+
test_file = File.new(File.join( File.dirname(File.expand_path(__FILE__)), 'master_shake.jpg'))
|
17
28
|
|
29
|
+
stub_request(:post, 'http://some/resource').with(:headers => {'Accept'=>'*/*; q=0.5, application/xml', 'Accept-Encoding'=>'gzip, deflate'}).to_return(:body => 'foo', :status => 200)
|
30
|
+
RestClient::Request.execute(:url => 'http://some/resource', :method => :post, :payload => {:file => test_file})
|
31
|
+
|
32
|
+
test_file.closed?.should be_true
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
data/spec/request_spec.rb
CHANGED
@@ -1,34 +1,34 @@
|
|
1
1
|
require File.join( File.dirname(File.expand_path(__FILE__)), 'base')
|
2
2
|
|
3
3
|
require 'webmock/rspec'
|
4
|
-
include WebMock
|
4
|
+
include WebMock::API
|
5
5
|
|
6
6
|
describe RestClient::Request do
|
7
7
|
before do
|
8
8
|
@request = RestClient::Request.new(:method => :put, :url => 'http://some/resource', :payload => 'payload')
|
9
9
|
|
10
|
-
@uri =
|
11
|
-
@uri.stub
|
12
|
-
@uri.stub
|
13
|
-
@uri.stub
|
14
|
-
|
15
|
-
@net =
|
16
|
-
@http =
|
17
|
-
Net::HTTP.stub
|
18
|
-
@net.stub
|
19
|
-
@net.stub
|
20
|
-
@net.stub
|
10
|
+
@uri = double("uri")
|
11
|
+
@uri.stub(:request_uri).and_return('/resource')
|
12
|
+
@uri.stub(:host).and_return('some')
|
13
|
+
@uri.stub(:port).and_return(80)
|
14
|
+
|
15
|
+
@net = double("net::http base")
|
16
|
+
@http = double("net::http connection")
|
17
|
+
Net::HTTP.stub(:new).and_return(@net)
|
18
|
+
@net.stub(:start).and_yield(@http)
|
19
|
+
@net.stub(:use_ssl=)
|
20
|
+
@net.stub(:verify_mode=)
|
21
21
|
RestClient.log = nil
|
22
22
|
end
|
23
23
|
|
24
24
|
it "accept */* mimetype, preferring xml" do
|
25
|
-
@request.default_headers[:accept].should
|
25
|
+
@request.default_headers[:accept].should eq '*/*; q=0.5, application/xml'
|
26
26
|
end
|
27
27
|
|
28
28
|
describe "compression" do
|
29
29
|
|
30
30
|
it "decodes an uncompressed result body by passing it straight through" do
|
31
|
-
RestClient::Request.decode(nil, 'xyz').should
|
31
|
+
RestClient::Request.decode(nil, 'xyz').should eq 'xyz'
|
32
32
|
end
|
33
33
|
|
34
34
|
it "doesn't fail for nil bodies" do
|
@@ -37,7 +37,7 @@ describe RestClient::Request do
|
|
37
37
|
|
38
38
|
|
39
39
|
it "decodes a gzip body" do
|
40
|
-
RestClient::Request.decode('gzip', "\037\213\b\b\006'\252H\000\003t\000\313T\317UH\257\312,HM\341\002\000G\242(\r\v\000\000\000").should
|
40
|
+
RestClient::Request.decode('gzip', "\037\213\b\b\006'\252H\000\003t\000\313T\317UH\257\312,HM\341\002\000G\242(\r\v\000\000\000").should eq "i'm gziped\n"
|
41
41
|
end
|
42
42
|
|
43
43
|
it "ingores gzip for empty bodies" do
|
@@ -45,25 +45,25 @@ describe RestClient::Request do
|
|
45
45
|
end
|
46
46
|
|
47
47
|
it "decodes a deflated body" do
|
48
|
-
RestClient::Request.decode('deflate', "x\234+\316\317MUHIM\313I,IMQ(I\255(\001\000A\223\006\363").should
|
48
|
+
RestClient::Request.decode('deflate', "x\234+\316\317MUHIM\313I,IMQ(I\255(\001\000A\223\006\363").should eq "some deflated text"
|
49
49
|
end
|
50
50
|
end
|
51
51
|
|
52
52
|
it "processes a successful result" do
|
53
|
-
res =
|
54
|
-
res.stub
|
55
|
-
res.stub
|
56
|
-
res.stub
|
57
|
-
@request.process_result(res).body.should
|
58
|
-
@request.process_result(res).to_s.should
|
53
|
+
res = double("result")
|
54
|
+
res.stub(:code).and_return("200")
|
55
|
+
res.stub(:body).and_return('body')
|
56
|
+
res.stub(:[]).with('content-encoding').and_return(nil)
|
57
|
+
@request.process_result(res).body.should eq 'body'
|
58
|
+
@request.process_result(res).to_s.should eq 'body'
|
59
59
|
end
|
60
60
|
|
61
61
|
it "doesn't classify successful requests as failed" do
|
62
62
|
203.upto(207) do |code|
|
63
|
-
res =
|
64
|
-
res.stub
|
65
|
-
res.stub
|
66
|
-
res.stub
|
63
|
+
res = double("result")
|
64
|
+
res.stub(:code).and_return(code.to_s)
|
65
|
+
res.stub(:body).and_return("")
|
66
|
+
res.stub(:[]).with('content-encoding').and_return(nil)
|
67
67
|
@request.process_result(res).should be_empty
|
68
68
|
end
|
69
69
|
end
|
@@ -80,37 +80,37 @@ describe RestClient::Request do
|
|
80
80
|
|
81
81
|
describe "user - password" do
|
82
82
|
it "extracts the username and password when parsing http://user:password@example.com/" do
|
83
|
-
URI.stub
|
83
|
+
URI.stub(:parse).and_return(double('uri', :user => 'joe', :password => 'pass1'))
|
84
84
|
@request.parse_url_with_auth('http://joe:pass1@example.com/resource')
|
85
|
-
@request.user.should
|
86
|
-
@request.password.should
|
85
|
+
@request.user.should eq 'joe'
|
86
|
+
@request.password.should eq 'pass1'
|
87
87
|
end
|
88
88
|
|
89
89
|
it "extracts with escaping the username and password when parsing http://user:password@example.com/" do
|
90
|
-
URI.stub
|
90
|
+
URI.stub(:parse).and_return(double('uri', :user => 'joe%20', :password => 'pass1'))
|
91
91
|
@request.parse_url_with_auth('http://joe%20:pass1@example.com/resource')
|
92
|
-
@request.user.should
|
93
|
-
@request.password.should
|
92
|
+
@request.user.should eq 'joe '
|
93
|
+
@request.password.should eq 'pass1'
|
94
94
|
end
|
95
95
|
|
96
96
|
it "doesn't overwrite user and password (which may have already been set by the Resource constructor) if there is no user/password in the url" do
|
97
|
-
URI.stub
|
97
|
+
URI.stub(:parse).and_return(double('uri', :user => nil, :password => nil))
|
98
98
|
@request = RestClient::Request.new(:method => 'get', :url => 'example.com', :user => 'beth', :password => 'pass2')
|
99
99
|
@request.parse_url_with_auth('http://example.com/resource')
|
100
|
-
@request.user.should
|
101
|
-
@request.password.should
|
100
|
+
@request.user.should eq 'beth'
|
101
|
+
@request.password.should eq 'pass2'
|
102
102
|
end
|
103
103
|
end
|
104
104
|
|
105
105
|
it "correctly formats cookies provided to the constructor" do
|
106
|
-
URI.stub
|
106
|
+
URI.stub(:parse).and_return(double('uri', :user => nil, :password => nil))
|
107
107
|
@request = RestClient::Request.new(:method => 'get', :url => 'example.com', :cookies => {:session_id => '1', :user_id => "someone" })
|
108
108
|
@request.should_receive(:default_headers).and_return({'Foo' => 'bar'})
|
109
|
-
@request.make_headers({}).should
|
109
|
+
@request.make_headers({}).should eq({ 'Foo' => 'bar', 'Cookie' => 'session_id=1; user_id=someone'})
|
110
110
|
end
|
111
111
|
|
112
112
|
it "determines the Net::HTTP class to instantiate by the method name" do
|
113
|
-
@request.net_http_request_class(:put).should
|
113
|
+
@request.net_http_request_class(:put).should eq Net::HTTP::Put
|
114
114
|
end
|
115
115
|
|
116
116
|
describe "user headers" do
|
@@ -118,16 +118,16 @@ describe RestClient::Request do
|
|
118
118
|
@request.should_receive(:default_headers).and_return({ :accept => '*/*; q=0.5, application/xml', :accept_encoding => 'gzip, deflate' })
|
119
119
|
headers = @request.make_headers("Accept" => "application/json", :accept_encoding => 'gzip')
|
120
120
|
headers.should have_key "Accept-Encoding"
|
121
|
-
headers["Accept-Encoding"].should
|
121
|
+
headers["Accept-Encoding"].should eq "gzip"
|
122
122
|
headers.should have_key "Accept"
|
123
|
-
headers["Accept"].should
|
123
|
+
headers["Accept"].should eq "application/json"
|
124
124
|
end
|
125
125
|
|
126
126
|
it "prefers the user header when the same header exists in the defaults" do
|
127
127
|
@request.should_receive(:default_headers).and_return({ '1' => '2' })
|
128
128
|
headers = @request.make_headers('1' => '3')
|
129
129
|
headers.should have_key('1')
|
130
|
-
headers['1'].should
|
130
|
+
headers['1'].should eq '3'
|
131
131
|
end
|
132
132
|
end
|
133
133
|
|
@@ -137,43 +137,43 @@ describe RestClient::Request do
|
|
137
137
|
@request.should_receive(:default_headers).and_return({})
|
138
138
|
headers = @request.make_headers(:content_type => 'abc')
|
139
139
|
headers.should have_key('Content-Type')
|
140
|
-
headers['Content-Type'].should
|
140
|
+
headers['Content-Type'].should eq 'abc'
|
141
141
|
end
|
142
142
|
|
143
143
|
it "converts content-type from extension to real content-type" do
|
144
144
|
@request.should_receive(:default_headers).and_return({})
|
145
145
|
headers = @request.make_headers(:content_type => 'json')
|
146
146
|
headers.should have_key('Content-Type')
|
147
|
-
headers['Content-Type'].should
|
147
|
+
headers['Content-Type'].should eq 'application/json'
|
148
148
|
end
|
149
149
|
|
150
150
|
it "converts accept from extension(s) to real content-type(s)" do
|
151
151
|
@request.should_receive(:default_headers).and_return({})
|
152
152
|
headers = @request.make_headers(:accept => 'json, mp3')
|
153
153
|
headers.should have_key('Accept')
|
154
|
-
headers['Accept'].should
|
154
|
+
headers['Accept'].should eq 'application/json, audio/mpeg'
|
155
155
|
|
156
156
|
@request.should_receive(:default_headers).and_return({})
|
157
157
|
headers = @request.make_headers(:accept => :json)
|
158
158
|
headers.should have_key('Accept')
|
159
|
-
headers['Accept'].should
|
159
|
+
headers['Accept'].should eq 'application/json'
|
160
160
|
end
|
161
161
|
|
162
162
|
it "only convert symbols in header" do
|
163
163
|
@request.should_receive(:default_headers).and_return({})
|
164
164
|
headers = @request.make_headers({:foo_bar => 'value', "bar_bar" => 'value'})
|
165
|
-
headers['Foo-Bar'].should
|
166
|
-
headers['bar_bar'].should
|
165
|
+
headers['Foo-Bar'].should eq 'value'
|
166
|
+
headers['bar_bar'].should eq 'value'
|
167
167
|
end
|
168
168
|
|
169
169
|
it "converts header values to strings" do
|
170
|
-
@request.make_headers('A' => 1)['A'].should
|
170
|
+
@request.make_headers('A' => 1)['A'].should eq '1'
|
171
171
|
end
|
172
172
|
end
|
173
173
|
|
174
174
|
it "executes by constructing the Net::HTTP object, headers, and payload and calling transmit" do
|
175
175
|
@request.should_receive(:parse_url_with_auth).with('http://some/resource').and_return(@uri)
|
176
|
-
klass =
|
176
|
+
klass = double("net:http class")
|
177
177
|
@request.should_receive(:net_http_request_class).with(:put).and_return(klass)
|
178
178
|
klass.should_receive(:new).and_return('result')
|
179
179
|
@request.should_receive(:transmit).with(@uri, 'result', kind_of(RestClient::Payload::Base))
|
@@ -190,16 +190,16 @@ describe RestClient::Request do
|
|
190
190
|
it "sends nil payloads" do
|
191
191
|
@http.should_receive(:request).with('req', nil)
|
192
192
|
@request.should_receive(:process_result)
|
193
|
-
@request.stub
|
193
|
+
@request.stub(:response_log)
|
194
194
|
@request.transmit(@uri, 'req', nil)
|
195
195
|
end
|
196
196
|
|
197
197
|
it "passes non-hash payloads straight through" do
|
198
|
-
@request.process_payload("x").should
|
198
|
+
@request.process_payload("x").should eq "x"
|
199
199
|
end
|
200
200
|
|
201
201
|
it "converts a hash payload to urlencoded data" do
|
202
|
-
@request.process_payload(:a => 'b c+d').should
|
202
|
+
@request.process_payload(:a => 'b c+d').should eq "a=b%20c%2Bd"
|
203
203
|
end
|
204
204
|
|
205
205
|
it "accepts nested hashes in payload" do
|
@@ -212,45 +212,45 @@ describe RestClient::Request do
|
|
212
212
|
|
213
213
|
it "set urlencoded content_type header on hash payloads" do
|
214
214
|
@request.process_payload(:a => 1)
|
215
|
-
@request.headers[:content_type].should
|
215
|
+
@request.headers[:content_type].should eq 'application/x-www-form-urlencoded'
|
216
216
|
end
|
217
217
|
|
218
218
|
describe "credentials" do
|
219
219
|
it "sets up the credentials prior to the request" do
|
220
|
-
@http.stub
|
221
|
-
@request.stub
|
222
|
-
@request.stub
|
220
|
+
@http.stub(:request)
|
221
|
+
@request.stub(:process_result)
|
222
|
+
@request.stub(:response_log)
|
223
223
|
|
224
|
-
@request.stub
|
225
|
-
@request.stub
|
224
|
+
@request.stub(:user).and_return('joe')
|
225
|
+
@request.stub(:password).and_return('mypass')
|
226
226
|
@request.should_receive(:setup_credentials).with('req')
|
227
227
|
|
228
228
|
@request.transmit(@uri, 'req', nil)
|
229
229
|
end
|
230
230
|
|
231
231
|
it "does not attempt to send any credentials if user is nil" do
|
232
|
-
@request.stub
|
233
|
-
req =
|
232
|
+
@request.stub(:user).and_return(nil)
|
233
|
+
req = double("request")
|
234
234
|
req.should_not_receive(:basic_auth)
|
235
235
|
@request.setup_credentials(req)
|
236
236
|
end
|
237
237
|
|
238
238
|
it "setup credentials when there's a user" do
|
239
|
-
@request.stub
|
240
|
-
@request.stub
|
241
|
-
req =
|
239
|
+
@request.stub(:user).and_return('joe')
|
240
|
+
@request.stub(:password).and_return('mypass')
|
241
|
+
req = double("request")
|
242
242
|
req.should_receive(:basic_auth).with('joe', 'mypass')
|
243
243
|
@request.setup_credentials(req)
|
244
244
|
end
|
245
245
|
end
|
246
246
|
|
247
247
|
it "catches EOFError and shows the more informative ServerBrokeConnection" do
|
248
|
-
@http.stub
|
248
|
+
@http.stub(:request).and_raise(EOFError)
|
249
249
|
lambda { @request.transmit(@uri, 'req', nil) }.should raise_error(RestClient::ServerBrokeConnection)
|
250
250
|
end
|
251
251
|
|
252
252
|
it "class method execute wraps constructor" do
|
253
|
-
req =
|
253
|
+
req = double("rest request")
|
254
254
|
RestClient::Request.should_receive(:new).with(1 => 2).and_return(req)
|
255
255
|
req.should_receive(:execute)
|
256
256
|
RestClient::Request.execute(1 => 2)
|
@@ -258,36 +258,36 @@ describe RestClient::Request do
|
|
258
258
|
|
259
259
|
describe "exception" do
|
260
260
|
it "raises Unauthorized when the response is 401" do
|
261
|
-
res =
|
261
|
+
res = double('response', :code => '401', :[] => ['content-encoding' => ''], :body => '' )
|
262
262
|
lambda { @request.process_result(res) }.should raise_error(RestClient::Unauthorized)
|
263
263
|
end
|
264
264
|
|
265
265
|
it "raises ResourceNotFound when the response is 404" do
|
266
|
-
res =
|
266
|
+
res = double('response', :code => '404', :[] => ['content-encoding' => ''], :body => '' )
|
267
267
|
lambda { @request.process_result(res) }.should raise_error(RestClient::ResourceNotFound)
|
268
268
|
end
|
269
269
|
|
270
270
|
it "raises RequestFailed otherwise" do
|
271
|
-
res =
|
271
|
+
res = double('response', :code => '500', :[] => ['content-encoding' => ''], :body => '' )
|
272
272
|
lambda { @request.process_result(res) }.should raise_error(RestClient::InternalServerError)
|
273
273
|
end
|
274
274
|
end
|
275
275
|
|
276
276
|
describe "block usage" do
|
277
277
|
it "returns what asked to" do
|
278
|
-
res =
|
279
|
-
@request.process_result(res){|response, request| "foo"}.should
|
278
|
+
res = double('response', :code => '401', :[] => ['content-encoding' => ''], :body => '' )
|
279
|
+
@request.process_result(res){|response, request| "foo"}.should eq "foo"
|
280
280
|
end
|
281
281
|
end
|
282
282
|
|
283
283
|
describe "proxy" do
|
284
284
|
it "creates a proxy class if a proxy url is given" do
|
285
|
-
RestClient.stub
|
286
|
-
@request.net_http_class.should
|
285
|
+
RestClient.stub(:proxy).and_return("http://example.com/")
|
286
|
+
@request.net_http_class.proxy_class?.should be_true
|
287
287
|
end
|
288
288
|
|
289
289
|
it "creates a non-proxy class if a proxy url is not given" do
|
290
|
-
@request.net_http_class.
|
290
|
+
@request.net_http_class.proxy_class?.should be_false
|
291
291
|
end
|
292
292
|
end
|
293
293
|
|
@@ -296,66 +296,66 @@ describe RestClient::Request do
|
|
296
296
|
it "logs a get request" do
|
297
297
|
log = RestClient.log = []
|
298
298
|
RestClient::Request.new(:method => :get, :url => 'http://url').log_request
|
299
|
-
log[0].should
|
299
|
+
log[0].should eq %Q{RestClient.get "http://url", "Accept"=>"*/*; q=0.5, application/xml", "Accept-Encoding"=>"gzip, deflate"\n}
|
300
300
|
end
|
301
301
|
|
302
302
|
it "logs a post request with a small payload" do
|
303
303
|
log = RestClient.log = []
|
304
304
|
RestClient::Request.new(:method => :post, :url => 'http://url', :payload => 'foo').log_request
|
305
|
-
log[0].should
|
305
|
+
log[0].should eq %Q{RestClient.post "http://url", "foo", "Accept"=>"*/*; q=0.5, application/xml", "Accept-Encoding"=>"gzip, deflate", "Content-Length"=>"3"\n}
|
306
306
|
end
|
307
307
|
|
308
308
|
it "logs a post request with a large payload" do
|
309
309
|
log = RestClient.log = []
|
310
310
|
RestClient::Request.new(:method => :post, :url => 'http://url', :payload => ('x' * 1000)).log_request
|
311
|
-
log[0].should
|
311
|
+
log[0].should eq %Q{RestClient.post "http://url", 1000 byte(s) length, "Accept"=>"*/*; q=0.5, application/xml", "Accept-Encoding"=>"gzip, deflate", "Content-Length"=>"1000"\n}
|
312
312
|
end
|
313
313
|
|
314
314
|
it "logs input headers as a hash" do
|
315
315
|
log = RestClient.log = []
|
316
316
|
RestClient::Request.new(:method => :get, :url => 'http://url', :headers => { :accept => 'text/plain' }).log_request
|
317
|
-
log[0].should
|
317
|
+
log[0].should eq %Q{RestClient.get "http://url", "Accept"=>"text/plain", "Accept-Encoding"=>"gzip, deflate"\n}
|
318
318
|
end
|
319
319
|
|
320
320
|
it "logs a response including the status code, content type, and result body size in bytes" do
|
321
321
|
log = RestClient.log = []
|
322
|
-
res =
|
323
|
-
res.stub
|
322
|
+
res = double('result', :code => '200', :class => Net::HTTPOK, :body => 'abcd')
|
323
|
+
res.stub(:[]).with('Content-type').and_return('text/html')
|
324
324
|
@request.log_response res
|
325
|
-
log[0].should
|
325
|
+
log[0].should eq "# => 200 OK | text/html 4 bytes\n"
|
326
326
|
end
|
327
327
|
|
328
328
|
it "logs a response with a nil Content-type" do
|
329
329
|
log = RestClient.log = []
|
330
|
-
res =
|
331
|
-
res.stub
|
330
|
+
res = double('result', :code => '200', :class => Net::HTTPOK, :body => 'abcd')
|
331
|
+
res.stub(:[]).with('Content-type').and_return(nil)
|
332
332
|
@request.log_response res
|
333
|
-
log[0].should
|
333
|
+
log[0].should eq "# => 200 OK | 4 bytes\n"
|
334
334
|
end
|
335
335
|
|
336
336
|
it "logs a response with a nil body" do
|
337
337
|
log = RestClient.log = []
|
338
|
-
res =
|
339
|
-
res.stub
|
338
|
+
res = double('result', :code => '200', :class => Net::HTTPOK, :body => nil)
|
339
|
+
res.stub(:[]).with('Content-type').and_return('text/html; charset=utf-8')
|
340
340
|
@request.log_response res
|
341
|
-
log[0].should
|
341
|
+
log[0].should eq "# => 200 OK | text/html 0 bytes\n"
|
342
342
|
end
|
343
343
|
end
|
344
344
|
|
345
345
|
it "strips the charset from the response content type" do
|
346
346
|
log = RestClient.log = []
|
347
|
-
res =
|
348
|
-
res.stub
|
347
|
+
res = double('result', :code => '200', :class => Net::HTTPOK, :body => 'abcd')
|
348
|
+
res.stub(:[]).with('Content-type').and_return('text/html; charset=utf-8')
|
349
349
|
@request.log_response res
|
350
|
-
log[0].should
|
350
|
+
log[0].should eq "# => 200 OK | text/html 4 bytes\n"
|
351
351
|
end
|
352
352
|
|
353
353
|
describe "timeout" do
|
354
354
|
it "set read_timeout" do
|
355
355
|
@request = RestClient::Request.new(:method => :put, :url => 'http://some/resource', :payload => 'payload', :timeout => 123)
|
356
|
-
@http.stub
|
357
|
-
@request.stub
|
358
|
-
@request.stub
|
356
|
+
@http.stub(:request)
|
357
|
+
@request.stub(:process_result)
|
358
|
+
@request.stub(:response_log)
|
359
359
|
|
360
360
|
@net.should_receive(:read_timeout=).with(123)
|
361
361
|
|
@@ -364,9 +364,9 @@ describe RestClient::Request do
|
|
364
364
|
|
365
365
|
it "set open_timeout" do
|
366
366
|
@request = RestClient::Request.new(:method => :put, :url => 'http://some/resource', :payload => 'payload', :open_timeout => 123)
|
367
|
-
@http.stub
|
368
|
-
@request.stub
|
369
|
-
@request.stub
|
367
|
+
@http.stub(:request)
|
368
|
+
@request.stub(:process_result)
|
369
|
+
@request.stub(:response_log)
|
370
370
|
|
371
371
|
@net.should_receive(:open_timeout=).with(123)
|
372
372
|
|
@@ -376,32 +376,32 @@ describe RestClient::Request do
|
|
376
376
|
|
377
377
|
describe "ssl" do
|
378
378
|
it "uses SSL when the URI refers to a https address" do
|
379
|
-
@uri.stub
|
379
|
+
@uri.stub(:is_a?).with(URI::HTTPS).and_return(true)
|
380
380
|
@net.should_receive(:use_ssl=).with(true)
|
381
|
-
@http.stub
|
382
|
-
@request.stub
|
383
|
-
@request.stub
|
381
|
+
@http.stub(:request)
|
382
|
+
@request.stub(:process_result)
|
383
|
+
@request.stub(:response_log)
|
384
384
|
@request.transmit(@uri, 'req', 'payload')
|
385
385
|
end
|
386
386
|
|
387
387
|
it "should default to not verifying ssl certificates" do
|
388
|
-
@request.verify_ssl.should
|
388
|
+
@request.verify_ssl.should eq false
|
389
389
|
end
|
390
390
|
|
391
391
|
it "should set net.verify_mode to OpenSSL::SSL::VERIFY_NONE if verify_ssl is false" do
|
392
392
|
@net.should_receive(:verify_mode=).with(OpenSSL::SSL::VERIFY_NONE)
|
393
|
-
@http.stub
|
394
|
-
@request.stub
|
395
|
-
@request.stub
|
393
|
+
@http.stub(:request)
|
394
|
+
@request.stub(:process_result)
|
395
|
+
@request.stub(:response_log)
|
396
396
|
@request.transmit(@uri, 'req', 'payload')
|
397
397
|
end
|
398
398
|
|
399
399
|
it "should not set net.verify_mode to OpenSSL::SSL::VERIFY_NONE if verify_ssl is true" do
|
400
400
|
@request = RestClient::Request.new(:method => :put, :url => 'https://some/resource', :payload => 'payload', :verify_ssl => true)
|
401
401
|
@net.should_not_receive(:verify_mode=).with(OpenSSL::SSL::VERIFY_NONE)
|
402
|
-
@http.stub
|
403
|
-
@request.stub
|
404
|
-
@request.stub
|
402
|
+
@http.stub(:request)
|
403
|
+
@request.stub(:process_result)
|
404
|
+
@request.stub(:response_log)
|
405
405
|
@request.transmit(@uri, 'req', 'payload')
|
406
406
|
end
|
407
407
|
|
@@ -412,10 +412,9 @@ describe RestClient::Request do
|
|
412
412
|
:payload => 'payload',
|
413
413
|
:verify_ssl => mode )
|
414
414
|
@net.should_receive(:verify_mode=).with(mode)
|
415
|
-
@
|
416
|
-
@
|
417
|
-
@request.stub
|
418
|
-
@request.stub!(:response_log)
|
415
|
+
@http.stub(:request)
|
416
|
+
@request.stub(:process_result)
|
417
|
+
@request.stub(:response_log)
|
419
418
|
@request.transmit(@uri, 'req', 'payload')
|
420
419
|
end
|
421
420
|
|
@@ -431,9 +430,9 @@ describe RestClient::Request do
|
|
431
430
|
:ssl_client_cert => "whatsupdoc!"
|
432
431
|
)
|
433
432
|
@net.should_receive(:cert=).with("whatsupdoc!")
|
434
|
-
@http.stub
|
435
|
-
@request.stub
|
436
|
-
@request.stub
|
433
|
+
@http.stub(:request)
|
434
|
+
@request.stub(:process_result)
|
435
|
+
@request.stub(:response_log)
|
437
436
|
@request.transmit(@uri, 'req', 'payload')
|
438
437
|
end
|
439
438
|
|
@@ -444,9 +443,9 @@ describe RestClient::Request do
|
|
444
443
|
:payload => 'payload'
|
445
444
|
)
|
446
445
|
@net.should_not_receive(:cert=).with("whatsupdoc!")
|
447
|
-
@http.stub
|
448
|
-
@request.stub
|
449
|
-
@request.stub
|
446
|
+
@http.stub(:request)
|
447
|
+
@request.stub(:process_result)
|
448
|
+
@request.stub(:response_log)
|
450
449
|
@request.transmit(@uri, 'req', 'payload')
|
451
450
|
end
|
452
451
|
|
@@ -462,9 +461,9 @@ describe RestClient::Request do
|
|
462
461
|
:ssl_client_key => "whatsupdoc!"
|
463
462
|
)
|
464
463
|
@net.should_receive(:key=).with("whatsupdoc!")
|
465
|
-
@http.stub
|
466
|
-
@request.stub
|
467
|
-
@request.stub
|
464
|
+
@http.stub(:request)
|
465
|
+
@request.stub(:process_result)
|
466
|
+
@request.stub(:response_log)
|
468
467
|
@request.transmit(@uri, 'req', 'payload')
|
469
468
|
end
|
470
469
|
|
@@ -475,9 +474,9 @@ describe RestClient::Request do
|
|
475
474
|
:payload => 'payload'
|
476
475
|
)
|
477
476
|
@net.should_not_receive(:key=).with("whatsupdoc!")
|
478
|
-
@http.stub
|
479
|
-
@request.stub
|
480
|
-
@request.stub
|
477
|
+
@http.stub(:request)
|
478
|
+
@request.stub(:process_result)
|
479
|
+
@request.stub(:response_log)
|
481
480
|
@request.transmit(@uri, 'req', 'payload')
|
482
481
|
end
|
483
482
|
|
@@ -493,9 +492,9 @@ describe RestClient::Request do
|
|
493
492
|
:ssl_ca_file => "Certificate Authority File"
|
494
493
|
)
|
495
494
|
@net.should_receive(:ca_file=).with("Certificate Authority File")
|
496
|
-
@http.stub
|
497
|
-
@request.stub
|
498
|
-
@request.stub
|
495
|
+
@http.stub(:request)
|
496
|
+
@request.stub(:process_result)
|
497
|
+
@request.stub(:response_log)
|
499
498
|
@request.transmit(@uri, 'req', 'payload')
|
500
499
|
end
|
501
500
|
|
@@ -506,9 +505,9 @@ describe RestClient::Request do
|
|
506
505
|
:payload => 'payload'
|
507
506
|
)
|
508
507
|
@net.should_not_receive(:ca_file=).with("Certificate Authority File")
|
509
|
-
@http.stub
|
510
|
-
@request.stub
|
511
|
-
@request.stub
|
508
|
+
@http.stub(:request)
|
509
|
+
@request.stub(:process_result)
|
510
|
+
@request.stub(:response_log)
|
512
511
|
@request.transmit(@uri, 'req', 'payload')
|
513
512
|
end
|
514
513
|
end
|
@@ -520,10 +519,10 @@ describe RestClient::Request do
|
|
520
519
|
:payload => 'payload'
|
521
520
|
)
|
522
521
|
net_http_res = Net::HTTPNoContent.new("", "204", "No Content")
|
523
|
-
net_http_res.stub
|
522
|
+
net_http_res.stub(:read_body).and_return(nil)
|
524
523
|
@http.should_receive(:request).and_return(@request.fetch_body(net_http_res))
|
525
524
|
response = @request.transmit(@uri, 'req', 'payload')
|
526
525
|
response.should_not be_nil
|
527
|
-
response.code.should
|
526
|
+
response.code.should eq 204
|
528
527
|
end
|
529
528
|
end
|