rest-client 1.6.14 → 2.0.2

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.
Files changed (65) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +6 -6
  3. data/.rspec +2 -1
  4. data/.rubocop-disables.yml +384 -0
  5. data/.rubocop.yml +3 -0
  6. data/.travis.yml +46 -1
  7. data/AUTHORS +28 -5
  8. data/Gemfile +5 -1
  9. data/LICENSE +21 -0
  10. data/README.md +784 -0
  11. data/Rakefile +95 -12
  12. data/bin/restclient +11 -12
  13. data/history.md +180 -16
  14. data/lib/restclient.rb +25 -11
  15. data/lib/restclient/abstract_response.rb +171 -51
  16. data/lib/restclient/exceptions.rb +102 -56
  17. data/lib/restclient/params_array.rb +72 -0
  18. data/lib/restclient/payload.rb +43 -74
  19. data/lib/restclient/platform.rb +22 -2
  20. data/lib/restclient/raw_response.rb +7 -3
  21. data/lib/restclient/request.rb +672 -179
  22. data/lib/restclient/resource.rb +6 -7
  23. data/lib/restclient/response.rb +64 -10
  24. data/lib/restclient/utils.rb +235 -0
  25. data/lib/restclient/version.rb +2 -1
  26. data/lib/restclient/windows.rb +8 -0
  27. data/lib/restclient/windows/root_certs.rb +105 -0
  28. data/rest-client.gemspec +16 -11
  29. data/rest-client.windows.gemspec +19 -0
  30. data/spec/helpers.rb +22 -0
  31. data/spec/integration/_lib.rb +1 -0
  32. data/spec/integration/capath_verisign/415660c1.0 +14 -0
  33. data/spec/integration/capath_verisign/7651b327.0 +14 -0
  34. data/spec/integration/capath_verisign/README +8 -0
  35. data/spec/integration/capath_verisign/verisign.crt +14 -0
  36. data/spec/integration/httpbin_spec.rb +87 -0
  37. data/spec/integration/integration_spec.rb +125 -0
  38. data/spec/integration/request_spec.rb +72 -20
  39. data/spec/spec_helper.rb +29 -0
  40. data/spec/unit/_lib.rb +1 -0
  41. data/spec/unit/abstract_response_spec.rb +145 -0
  42. data/spec/unit/exceptions_spec.rb +108 -0
  43. data/spec/{master_shake.jpg → unit/master_shake.jpg} +0 -0
  44. data/spec/unit/params_array_spec.rb +36 -0
  45. data/spec/{payload_spec.rb → unit/payload_spec.rb} +73 -54
  46. data/spec/{raw_response_spec.rb → unit/raw_response_spec.rb} +5 -4
  47. data/spec/unit/request2_spec.rb +54 -0
  48. data/spec/unit/request_spec.rb +1250 -0
  49. data/spec/unit/resource_spec.rb +134 -0
  50. data/spec/unit/response_spec.rb +241 -0
  51. data/spec/unit/restclient_spec.rb +79 -0
  52. data/spec/unit/utils_spec.rb +147 -0
  53. data/spec/unit/windows/root_certs_spec.rb +22 -0
  54. metadata +143 -53
  55. data/README.rdoc +0 -300
  56. data/lib/restclient/net_http_ext.rb +0 -55
  57. data/spec/abstract_response_spec.rb +0 -85
  58. data/spec/base.rb +0 -13
  59. data/spec/exceptions_spec.rb +0 -98
  60. data/spec/integration_spec.rb +0 -38
  61. data/spec/request2_spec.rb +0 -35
  62. data/spec/request_spec.rb +0 -528
  63. data/spec/resource_spec.rb +0 -136
  64. data/spec/response_spec.rb +0 -169
  65. data/spec/restclient_spec.rb +0 -73
@@ -0,0 +1,134 @@
1
+ require_relative '_lib'
2
+
3
+ describe RestClient::Resource do
4
+ before do
5
+ @resource = RestClient::Resource.new('http://some/resource', :user => 'jane', :password => 'mypass', :headers => {'X-Something' => '1'})
6
+ end
7
+
8
+ context "Resource delegation" do
9
+ it "GET" do
10
+ expect(RestClient::Request).to receive(:execute).with(:method => :get, :url => 'http://some/resource', :headers => {'X-Something' => '1'}, :user => 'jane', :password => 'mypass')
11
+ @resource.get
12
+ end
13
+
14
+ it "HEAD" do
15
+ expect(RestClient::Request).to receive(:execute).with(:method => :head, :url => 'http://some/resource', :headers => {'X-Something' => '1'}, :user => 'jane', :password => 'mypass')
16
+ @resource.head
17
+ end
18
+
19
+ it "POST" do
20
+ expect(RestClient::Request).to receive(:execute).with(:method => :post, :url => 'http://some/resource', :payload => 'abc', :headers => {:content_type => 'image/jpg', 'X-Something' => '1'}, :user => 'jane', :password => 'mypass')
21
+ @resource.post 'abc', :content_type => 'image/jpg'
22
+ end
23
+
24
+ it "PUT" do
25
+ expect(RestClient::Request).to receive(:execute).with(:method => :put, :url => 'http://some/resource', :payload => 'abc', :headers => {:content_type => 'image/jpg', 'X-Something' => '1'}, :user => 'jane', :password => 'mypass')
26
+ @resource.put 'abc', :content_type => 'image/jpg'
27
+ end
28
+
29
+ it "PATCH" do
30
+ expect(RestClient::Request).to receive(:execute).with(:method => :patch, :url => 'http://some/resource', :payload => 'abc', :headers => {:content_type => 'image/jpg', 'X-Something' => '1'}, :user => 'jane', :password => 'mypass')
31
+ @resource.patch 'abc', :content_type => 'image/jpg'
32
+ end
33
+
34
+ it "DELETE" do
35
+ expect(RestClient::Request).to receive(:execute).with(:method => :delete, :url => 'http://some/resource', :headers => {'X-Something' => '1'}, :user => 'jane', :password => 'mypass')
36
+ @resource.delete
37
+ end
38
+
39
+ it "overrides resource headers" do
40
+ expect(RestClient::Request).to receive(:execute).with(:method => :get, :url => 'http://some/resource', :headers => {'X-Something' => '2'}, :user => 'jane', :password => 'mypass')
41
+ @resource.get 'X-Something' => '2'
42
+ end
43
+ end
44
+
45
+ it "can instantiate with no user/password" do
46
+ @resource = RestClient::Resource.new('http://some/resource')
47
+ end
48
+
49
+ it "is backwards compatible with previous constructor" do
50
+ @resource = RestClient::Resource.new('http://some/resource', 'user', 'pass')
51
+ expect(@resource.user).to eq 'user'
52
+ expect(@resource.password).to eq 'pass'
53
+ end
54
+
55
+ it "concatenates urls, inserting a slash when it needs one" do
56
+ expect(@resource.concat_urls('http://example.com', 'resource')).to eq 'http://example.com/resource'
57
+ end
58
+
59
+ it "concatenates urls, using no slash if the first url ends with a slash" do
60
+ expect(@resource.concat_urls('http://example.com/', 'resource')).to eq 'http://example.com/resource'
61
+ end
62
+
63
+ it "concatenates urls, using no slash if the second url starts with a slash" do
64
+ expect(@resource.concat_urls('http://example.com', '/resource')).to eq 'http://example.com/resource'
65
+ end
66
+
67
+ it "concatenates even non-string urls, :posts + 1 => 'posts/1'" do
68
+ expect(@resource.concat_urls(:posts, 1)).to eq 'posts/1'
69
+ end
70
+
71
+ it "offers subresources via []" do
72
+ parent = RestClient::Resource.new('http://example.com')
73
+ expect(parent['posts'].url).to eq 'http://example.com/posts'
74
+ end
75
+
76
+ it "transports options to subresources" do
77
+ parent = RestClient::Resource.new('http://example.com', :user => 'user', :password => 'password')
78
+ expect(parent['posts'].user).to eq 'user'
79
+ expect(parent['posts'].password).to eq 'password'
80
+ end
81
+
82
+ it "passes a given block to subresources" do
83
+ block = proc {|r| r}
84
+ parent = RestClient::Resource.new('http://example.com', &block)
85
+ expect(parent['posts'].block).to eq block
86
+ end
87
+
88
+ it "the block should be overrideable" do
89
+ block1 = proc {|r| r}
90
+ block2 = proc {|r| }
91
+ parent = RestClient::Resource.new('http://example.com', &block1)
92
+ # parent['posts', &block2].block.should eq block2 # ruby 1.9 syntax
93
+ expect(parent.send(:[], 'posts', &block2).block).to eq block2
94
+ expect(parent.send(:[], 'posts', &block2).block).not_to eq block1
95
+ end
96
+
97
+ # Test fails on jruby 9.1.[0-5].* due to
98
+ # https://github.com/jruby/jruby/issues/4217
99
+ it "the block should be overrideable in ruby 1.9 syntax",
100
+ :unless => (RUBY_ENGINE == 'jruby' && JRUBY_VERSION =~ /\A9\.1\.[0-5]\./) \
101
+ do
102
+ block1 = proc {|r| r}
103
+ block2 = ->(r) {}
104
+
105
+ parent = RestClient::Resource.new('http://example.com', &block1)
106
+ expect(parent['posts', &block2].block).to eq block2
107
+ expect(parent['posts', &block2].block).not_to eq block1
108
+ end
109
+
110
+ it "prints its url with to_s" do
111
+ expect(RestClient::Resource.new('x').to_s).to eq 'x'
112
+ end
113
+
114
+ describe 'block' do
115
+ it 'can use block when creating the resource' do
116
+ stub_request(:get, 'www.example.com').to_return(:body => '', :status => 404)
117
+ resource = RestClient::Resource.new('www.example.com') { |response, request| 'foo' }
118
+ expect(resource.get).to eq 'foo'
119
+ end
120
+
121
+ it 'can use block when executing the resource' do
122
+ stub_request(:get, 'www.example.com').to_return(:body => '', :status => 404)
123
+ resource = RestClient::Resource.new('www.example.com')
124
+ expect(resource.get { |response, request| 'foo' }).to eq 'foo'
125
+ end
126
+
127
+ it 'execution block override resource block' do
128
+ stub_request(:get, 'www.example.com').to_return(:body => '', :status => 404)
129
+ resource = RestClient::Resource.new('www.example.com') { |response, request| 'foo' }
130
+ expect(resource.get { |response, request| 'bar' }).to eq 'bar'
131
+ end
132
+
133
+ end
134
+ end
@@ -0,0 +1,241 @@
1
+ require_relative '_lib'
2
+
3
+ describe RestClient::Response, :include_helpers do
4
+ before do
5
+ @net_http_res = double('net http response', :to_hash => {"Status" => ["200 OK"]}, :code => 200)
6
+ @example_url = 'http://example.com'
7
+ @request = request_double(url: @example_url, method: 'get')
8
+ @response = RestClient::Response.create('abc', @net_http_res, @request)
9
+ end
10
+
11
+ it "behaves like string" do
12
+ expect(@response.to_s).to eq 'abc'
13
+ expect(@response.to_str).to eq 'abc'
14
+
15
+ expect(@response).to receive(:warn)
16
+ expect(@response.to_i).to eq 0
17
+ end
18
+
19
+ it "accepts nil strings and sets it to empty for the case of HEAD" do
20
+ expect(RestClient::Response.create(nil, @net_http_res, @request).to_s).to eq ""
21
+ end
22
+
23
+ describe 'header processing' do
24
+ it "test headers and raw headers" do
25
+ expect(@response.raw_headers["Status"][0]).to eq "200 OK"
26
+ expect(@response.headers[:status]).to eq "200 OK"
27
+ end
28
+
29
+ it 'handles multiple headers by joining with comma' do
30
+ @net_http_res = double('net http response', :to_hash => {'My-Header' => ['foo', 'bar']}, :code => 200)
31
+ @example_url = 'http://example.com'
32
+ @request = request_double(url: @example_url, method: 'get')
33
+ @response = RestClient::Response.create('abc', @net_http_res, @request)
34
+
35
+ expect(@response.raw_headers['My-Header']).to eq ['foo', 'bar']
36
+ expect(@response.headers[:my_header]).to eq 'foo, bar'
37
+ end
38
+ end
39
+
40
+ describe "cookie processing" do
41
+ it "should correctly deal with one Set-Cookie header with one cookie inside" do
42
+ header_val = "main_page=main_page_no_rewrite; path=/; expires=Sat, 10-Jan-2037 15:03:14 GMT".freeze
43
+
44
+ net_http_res = double('net http response', :to_hash => {"etag" => ["\"e1ac1a2df945942ef4cac8116366baad\""], "set-cookie" => [header_val]})
45
+ response = RestClient::Response.create('abc', net_http_res, @request)
46
+ expect(response.headers[:set_cookie]).to eq [header_val]
47
+ expect(response.cookies).to eq({ "main_page" => "main_page_no_rewrite" })
48
+ end
49
+
50
+ it "should correctly deal with multiple cookies [multiple Set-Cookie headers]" do
51
+ net_http_res = double('net http response', :to_hash => {"etag" => ["\"e1ac1a2df945942ef4cac8116366baad\""], "set-cookie" => ["main_page=main_page_no_rewrite; path=/; expires=Sat, 10-Jan-2037 15:03:14 GMT", "remember_me=; path=/; expires=Sat, 10-Jan-2037 00:00:00 GMT", "user=somebody; path=/; expires=Sat, 10-Jan-2037 00:00:00 GMT"]})
52
+ response = RestClient::Response.create('abc', net_http_res, @request)
53
+ expect(response.headers[:set_cookie]).to eq ["main_page=main_page_no_rewrite; path=/; expires=Sat, 10-Jan-2037 15:03:14 GMT", "remember_me=; path=/; expires=Sat, 10-Jan-2037 00:00:00 GMT", "user=somebody; path=/; expires=Sat, 10-Jan-2037 00:00:00 GMT"]
54
+ expect(response.cookies).to eq({
55
+ "main_page" => "main_page_no_rewrite",
56
+ "remember_me" => "",
57
+ "user" => "somebody"
58
+ })
59
+ end
60
+
61
+ it "should correctly deal with multiple cookies [one Set-Cookie header with multiple cookies]" do
62
+ net_http_res = double('net http response', :to_hash => {"etag" => ["\"e1ac1a2df945942ef4cac8116366baad\""], "set-cookie" => ["main_page=main_page_no_rewrite; path=/; expires=Sat, 10-Jan-2037 15:03:14 GMT, remember_me=; path=/; expires=Sat, 10-Jan-2037 00:00:00 GMT, user=somebody; path=/; expires=Sat, 10-Jan-2037 00:00:00 GMT"]})
63
+ response = RestClient::Response.create('abc', net_http_res, @request)
64
+ expect(response.cookies).to eq({
65
+ "main_page" => "main_page_no_rewrite",
66
+ "remember_me" => "",
67
+ "user" => "somebody"
68
+ })
69
+ end
70
+ end
71
+
72
+ describe "exceptions processing" do
73
+ it "should return itself for normal codes" do
74
+ (200..206).each do |code|
75
+ net_http_res = response_double(:code => '200')
76
+ resp = RestClient::Response.create('abc', net_http_res, @request)
77
+ resp.return!
78
+ end
79
+ end
80
+
81
+ it "should throw an exception for other codes" do
82
+ RestClient::Exceptions::EXCEPTIONS_MAP.each_pair do |code, exc|
83
+ unless (200..207).include? code
84
+ net_http_res = response_double(:code => code.to_i)
85
+ resp = RestClient::Response.create('abc', net_http_res, @request)
86
+ allow(@request).to receive(:max_redirects).and_return(5)
87
+ expect { resp.return! }.to raise_error(exc)
88
+ end
89
+ end
90
+ end
91
+
92
+ end
93
+
94
+ describe "redirection" do
95
+
96
+ it "follows a redirection when the request is a get" do
97
+ stub_request(:get, 'http://some/resource').to_return(:body => '', :status => 301, :headers => {'Location' => 'http://new/resource'})
98
+ stub_request(:get, 'http://new/resource').to_return(:body => 'Foo')
99
+ expect(RestClient::Request.execute(:url => 'http://some/resource', :method => :get).body).to eq 'Foo'
100
+ end
101
+
102
+ it "keeps redirection history" do
103
+ stub_request(:get, 'http://some/resource').to_return(:body => '', :status => 301, :headers => {'Location' => 'http://new/resource'})
104
+ stub_request(:get, 'http://new/resource').to_return(:body => 'Foo')
105
+ r = RestClient::Request.execute(url: 'http://some/resource', method: :get)
106
+ expect(r.body).to eq 'Foo'
107
+ expect(r.history.length).to eq 1
108
+ expect(r.history.fetch(0)).to be_a(RestClient::Response)
109
+ expect(r.history.fetch(0).code).to be 301
110
+ end
111
+
112
+ it "follows a redirection and keep the parameters" do
113
+ stub_request(:get, 'http://some/resource').with(:headers => {'Accept' => 'application/json'}, :basic_auth => ['foo', 'bar']).to_return(:body => '', :status => 301, :headers => {'Location' => 'http://new/resource'})
114
+ stub_request(:get, 'http://new/resource').with(:headers => {'Accept' => 'application/json'}, :basic_auth => ['foo', 'bar']).to_return(:body => 'Foo')
115
+ expect(RestClient::Request.execute(:url => 'http://some/resource', :method => :get, :user => 'foo', :password => 'bar', :headers => {:accept => :json}).body).to eq 'Foo'
116
+ end
117
+
118
+ it "follows a redirection and keep the cookies" do
119
+ stub_request(:get, 'http://some/resource').to_return(:body => '', :status => 301, :headers => {'Set-Cookie' => 'Foo=Bar', 'Location' => 'http://some/new_resource', })
120
+ stub_request(:get, 'http://some/new_resource').with(:headers => {'Cookie' => 'Foo=Bar'}).to_return(:body => 'Qux')
121
+ expect(RestClient::Request.execute(:url => 'http://some/resource', :method => :get).body).to eq 'Qux'
122
+ end
123
+
124
+ it 'respects cookie domains on redirect' do
125
+ stub_request(:get, 'http://some.example.com/').to_return(:body => '', :status => 301,
126
+ :headers => {'Set-Cookie' => 'Foo=Bar', 'Location' => 'http://new.example.com/', })
127
+ stub_request(:get, 'http://new.example.com/').with(
128
+ :headers => {'Cookie' => 'passedthrough=1'}).to_return(:body => 'Qux')
129
+
130
+ expect(RestClient::Request.execute(:url => 'http://some.example.com/', :method => :get, cookies: [HTTP::Cookie.new('passedthrough', '1', domain: 'new.example.com', path: '/')]).body).to eq 'Qux'
131
+ end
132
+
133
+ it "doesn't follow a 301 when the request is a post" do
134
+ net_http_res = response_double(:code => 301)
135
+
136
+ response = RestClient::Response.create('abc', net_http_res,
137
+ request_double(method: 'post'))
138
+ expect {
139
+ response.return!
140
+ }.to raise_error(RestClient::MovedPermanently)
141
+ end
142
+
143
+ it "doesn't follow a 302 when the request is a post" do
144
+ net_http_res = response_double(:code => 302)
145
+ response = RestClient::Response.create('abc', net_http_res,
146
+ request_double(method: 'post'))
147
+ expect {
148
+ response.return!
149
+ }.to raise_error(RestClient::Found)
150
+ end
151
+
152
+ it "doesn't follow a 307 when the request is a post" do
153
+ net_http_res = response_double(:code => 307)
154
+ response = RestClient::Response.create('abc', net_http_res,
155
+ request_double(method: 'post'))
156
+ expect(response).not_to receive(:follow_redirection)
157
+ expect {
158
+ response.return!
159
+ }.to raise_error(RestClient::TemporaryRedirect)
160
+ end
161
+
162
+ it "doesn't follow a redirection when the request is a put" do
163
+ net_http_res = response_double(:code => 301)
164
+ response = RestClient::Response.create('abc', net_http_res,
165
+ request_double(method: 'put'))
166
+ expect {
167
+ response.return!
168
+ }.to raise_error(RestClient::MovedPermanently)
169
+ end
170
+
171
+ it "follows a redirection when the request is a post and result is a 303" do
172
+ stub_request(:put, 'http://some/resource').to_return(:body => '', :status => 303, :headers => {'Location' => 'http://new/resource'})
173
+ stub_request(:get, 'http://new/resource').to_return(:body => 'Foo')
174
+ expect(RestClient::Request.execute(:url => 'http://some/resource', :method => :put).body).to eq 'Foo'
175
+ end
176
+
177
+ it "follows a redirection when the request is a head" do
178
+ stub_request(:head, 'http://some/resource').to_return(:body => '', :status => 301, :headers => {'Location' => 'http://new/resource'})
179
+ stub_request(:head, 'http://new/resource').to_return(:body => 'Foo')
180
+ expect(RestClient::Request.execute(:url => 'http://some/resource', :method => :head).body).to eq 'Foo'
181
+ end
182
+
183
+ it "handles redirects with relative paths" do
184
+ stub_request(:get, 'http://some/resource').to_return(:body => '', :status => 301, :headers => {'Location' => 'index'})
185
+ stub_request(:get, 'http://some/index').to_return(:body => 'Foo')
186
+ expect(RestClient::Request.execute(:url => 'http://some/resource', :method => :get).body).to eq 'Foo'
187
+ end
188
+
189
+ it "handles redirects with relative path and query string" do
190
+ stub_request(:get, 'http://some/resource').to_return(:body => '', :status => 301, :headers => {'Location' => 'index?q=1'})
191
+ stub_request(:get, 'http://some/index?q=1').to_return(:body => 'Foo')
192
+ expect(RestClient::Request.execute(:url => 'http://some/resource', :method => :get).body).to eq 'Foo'
193
+ end
194
+
195
+ it "follow a redirection when the request is a get and the response is in the 30x range" do
196
+ stub_request(:get, 'http://some/resource').to_return(:body => '', :status => 301, :headers => {'Location' => 'http://new/resource'})
197
+ stub_request(:get, 'http://new/resource').to_return(:body => 'Foo')
198
+ expect(RestClient::Request.execute(:url => 'http://some/resource', :method => :get).body).to eq 'Foo'
199
+ end
200
+
201
+ it "follows no more than 10 redirections before raising error" do
202
+ stub_request(:get, 'http://some/redirect-1').to_return(:body => '', :status => 301, :headers => {'Location' => 'http://some/redirect-2'})
203
+ stub_request(:get, 'http://some/redirect-2').to_return(:body => '', :status => 301, :headers => {'Location' => 'http://some/redirect-2'})
204
+ expect {
205
+ RestClient::Request.execute(url: 'http://some/redirect-1', method: :get)
206
+ }.to raise_error(RestClient::MovedPermanently) { |ex|
207
+ ex.response.history.each {|r| expect(r).to be_a(RestClient::Response) }
208
+ expect(ex.response.history.length).to eq 10
209
+ }
210
+ expect(WebMock).to have_requested(:get, 'http://some/redirect-2').times(10)
211
+ end
212
+
213
+ it "follows no more than max_redirects redirections, if specified" do
214
+ stub_request(:get, 'http://some/redirect-1').to_return(:body => '', :status => 301, :headers => {'Location' => 'http://some/redirect-2'})
215
+ stub_request(:get, 'http://some/redirect-2').to_return(:body => '', :status => 301, :headers => {'Location' => 'http://some/redirect-2'})
216
+ expect {
217
+ RestClient::Request.execute(url: 'http://some/redirect-1', method: :get, max_redirects: 5)
218
+ }.to raise_error(RestClient::MovedPermanently) { |ex|
219
+ expect(ex.response.history.length).to eq 5
220
+ }
221
+ expect(WebMock).to have_requested(:get, 'http://some/redirect-2').times(5)
222
+ end
223
+
224
+ it "allows for manual following of redirects" do
225
+ stub_request(:get, 'http://some/redirect-1').to_return(:body => '', :status => 301, :headers => {'Location' => 'http://some/resource'})
226
+ stub_request(:get, 'http://some/resource').to_return(:body => 'Qux', :status => 200)
227
+
228
+ begin
229
+ RestClient::Request.execute(url: 'http://some/redirect-1', method: :get, max_redirects: 0)
230
+ rescue RestClient::MovedPermanently => err
231
+ resp = err.response.follow_redirection
232
+ else
233
+ raise 'notreached'
234
+ end
235
+
236
+ expect(resp.code).to eq 200
237
+ expect(resp.body).to eq 'Qux'
238
+ end
239
+ end
240
+
241
+ end
@@ -0,0 +1,79 @@
1
+ require_relative '_lib'
2
+
3
+ describe RestClient do
4
+ describe "API" do
5
+ it "GET" do
6
+ expect(RestClient::Request).to receive(:execute).with(:method => :get, :url => 'http://some/resource', :headers => {})
7
+ RestClient.get('http://some/resource')
8
+ end
9
+
10
+ it "POST" do
11
+ expect(RestClient::Request).to receive(:execute).with(:method => :post, :url => 'http://some/resource', :payload => 'payload', :headers => {})
12
+ RestClient.post('http://some/resource', 'payload')
13
+ end
14
+
15
+ it "PUT" do
16
+ expect(RestClient::Request).to receive(:execute).with(:method => :put, :url => 'http://some/resource', :payload => 'payload', :headers => {})
17
+ RestClient.put('http://some/resource', 'payload')
18
+ end
19
+
20
+ it "PATCH" do
21
+ expect(RestClient::Request).to receive(:execute).with(:method => :patch, :url => 'http://some/resource', :payload => 'payload', :headers => {})
22
+ RestClient.patch('http://some/resource', 'payload')
23
+ end
24
+
25
+ it "DELETE" do
26
+ expect(RestClient::Request).to receive(:execute).with(:method => :delete, :url => 'http://some/resource', :headers => {})
27
+ RestClient.delete('http://some/resource')
28
+ end
29
+
30
+ it "HEAD" do
31
+ expect(RestClient::Request).to receive(:execute).with(:method => :head, :url => 'http://some/resource', :headers => {})
32
+ RestClient.head('http://some/resource')
33
+ end
34
+
35
+ it "OPTIONS" do
36
+ expect(RestClient::Request).to receive(:execute).with(:method => :options, :url => 'http://some/resource', :headers => {})
37
+ RestClient.options('http://some/resource')
38
+ end
39
+ end
40
+
41
+ describe "logging" do
42
+ after do
43
+ RestClient.log = nil
44
+ end
45
+
46
+ it "uses << if the log is not a string" do
47
+ log = RestClient.log = []
48
+ expect(log).to receive(:<<).with('xyz')
49
+ RestClient.log << 'xyz'
50
+ end
51
+
52
+ it "displays the log to stdout" do
53
+ RestClient.log = 'stdout'
54
+ expect(STDOUT).to receive(:puts).with('xyz')
55
+ RestClient.log << 'xyz'
56
+ end
57
+
58
+ it "displays the log to stderr" do
59
+ RestClient.log = 'stderr'
60
+ expect(STDERR).to receive(:puts).with('xyz')
61
+ RestClient.log << 'xyz'
62
+ end
63
+
64
+ it "append the log to the requested filename" do
65
+ RestClient.log = '/tmp/restclient.log'
66
+ f = double('file handle')
67
+ expect(File).to receive(:open).with('/tmp/restclient.log', 'a').and_yield(f)
68
+ expect(f).to receive(:puts).with('xyz')
69
+ RestClient.log << 'xyz'
70
+ end
71
+ end
72
+
73
+ describe 'version' do
74
+ it 'has a version ~> 2.0.0.alpha' do
75
+ ver = Gem::Version.new(RestClient.version)
76
+ expect(Gem::Requirement.new('~> 2.0.0.alpha')).to be_satisfied_by(ver)
77
+ end
78
+ end
79
+ end