rest-client 1.8.0 → 2.0.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,4 +1,4 @@
1
- require 'spec_helper'
1
+ require_relative '_lib'
2
2
 
3
3
  describe RestClient::Resource do
4
4
  before do
@@ -1,26 +1,40 @@
1
- require 'spec_helper'
1
+ require_relative '_lib'
2
2
 
3
- describe RestClient::Response do
3
+ describe RestClient::Response, :include_helpers do
4
4
  before do
5
5
  @net_http_res = double('net http response', :to_hash => {"Status" => ["200 OK"]}, :code => 200)
6
6
  @example_url = 'http://example.com'
7
- @request = double('http request', :user => nil, :password => nil, :url => @example_url)
7
+ @request = double('http request', :user => nil, :password => nil, :url => @example_url, :redirection_history => nil)
8
8
  @response = RestClient::Response.create('abc', @net_http_res, {}, @request)
9
9
  end
10
10
 
11
11
  it "behaves like string" do
12
12
  @response.to_s.should eq 'abc'
13
13
  @response.to_str.should eq 'abc'
14
- @response.to_i.should eq 200
14
+
15
+ @response.should_receive(:warn)
16
+ @response.to_i.should eq 0
15
17
  end
16
18
 
17
19
  it "accepts nil strings and sets it to empty for the case of HEAD" do
18
20
  RestClient::Response.create(nil, @net_http_res, {}, @request).to_s.should eq ""
19
21
  end
20
22
 
21
- it "test headers and raw headers" do
22
- @response.raw_headers["Status"][0].should eq "200 OK"
23
- @response.headers[:status].should eq "200 OK"
23
+ describe 'header processing' do
24
+ it "test headers and raw headers" do
25
+ @response.raw_headers["Status"][0].should eq "200 OK"
26
+ @response.headers[:status].should 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 = double('http request', :user => nil, :password => nil, :url => @example_url, :redirection_history => nil)
33
+ @response = RestClient::Response.create('abc', @net_http_res, {}, @request)
34
+
35
+ @response.raw_headers['My-Header'].should eq ['foo', 'bar']
36
+ @response.headers[:my_header].should eq 'foo, bar'
37
+ end
24
38
  end
25
39
 
26
40
  describe "cookie processing" do
@@ -58,18 +72,18 @@ describe RestClient::Response do
58
72
  describe "exceptions processing" do
59
73
  it "should return itself for normal codes" do
60
74
  (200..206).each do |code|
61
- net_http_res = double('net http response', :code => '200')
62
- response = RestClient::Response.create('abc', net_http_res, {}, @request)
63
- response.return! @request
75
+ net_http_res = response_double(:code => '200')
76
+ resp = RestClient::Response.create('abc', net_http_res, {}, @request)
77
+ resp.return!
64
78
  end
65
79
  end
66
80
 
67
81
  it "should throw an exception for other codes" do
68
82
  RestClient::Exceptions::EXCEPTIONS_MAP.each_key do |code|
69
83
  unless (200..207).include? code
70
- net_http_res = double('net http response', :code => code.to_i)
71
- response = RestClient::Response.create('abc', net_http_res, {}, @request)
72
- lambda { response.return!}.should raise_error
84
+ net_http_res = response_double(:code => code.to_i)
85
+ resp = RestClient::Response.create('abc', net_http_res, {}, @request)
86
+ lambda { resp.return! }.should raise_error
73
87
  end
74
88
  end
75
89
  end
@@ -84,6 +98,16 @@ describe RestClient::Response do
84
98
  RestClient::Request.execute(:url => 'http://some/resource', :method => :get).body.should eq 'Foo'
85
99
  end
86
100
 
101
+ it "keeps redirection history" do
102
+ stub_request(:get, 'http://some/resource').to_return(:body => '', :status => 301, :headers => {'Location' => 'http://new/resource'})
103
+ stub_request(:get, 'http://new/resource').to_return(:body => 'Foo')
104
+ r = RestClient::Request.execute(url: 'http://some/resource', method: :get)
105
+ r.body.should eq 'Foo'
106
+ r.history.length.should eq 1
107
+ r.history.fetch(0).should be_a(RestClient::Response)
108
+ r.history.fetch(0).code.should be 301
109
+ end
110
+
87
111
  it "follows a redirection and keep the parameters" do
88
112
  stub_request(:get, 'http://foo:bar@some/resource').with(:headers => {'Accept' => 'application/json'}).to_return(:body => '', :status => 301, :headers => {'Location' => 'http://new/resource'})
89
113
  stub_request(:get, 'http://foo:bar@new/resource').with(:headers => {'Accept' => 'application/json'}).to_return(:body => 'Foo')
@@ -103,27 +127,39 @@ describe RestClient::Response do
103
127
  end
104
128
 
105
129
  it "doesn't follow a 301 when the request is a post" do
106
- net_http_res = double('net http response', :code => 301)
107
- response = RestClient::Response.create('abc', net_http_res, {:method => :post}, @request)
108
- lambda { response.return!(@request)}.should raise_error(RestClient::MovedPermanently)
130
+ net_http_res = response_double(:code => 301)
131
+ response = RestClient::Response.create('abc', net_http_res,
132
+ {:method => :post}, @request)
133
+ lambda {
134
+ response.return!
135
+ }.should raise_error(RestClient::MovedPermanently)
109
136
  end
110
137
 
111
138
  it "doesn't follow a 302 when the request is a post" do
112
- net_http_res = double('net http response', :code => 302)
113
- response = RestClient::Response.create('abc', net_http_res, {:method => :post}, @request)
114
- lambda { response.return!(@request)}.should raise_error(RestClient::Found)
139
+ net_http_res = response_double(:code => 302)
140
+ response = RestClient::Response.create('abc', net_http_res,
141
+ {:method => :post}, @request)
142
+ lambda {
143
+ response.return!
144
+ }.should raise_error(RestClient::Found)
115
145
  end
116
146
 
117
147
  it "doesn't follow a 307 when the request is a post" do
118
- net_http_res = double('net http response', :code => 307)
119
- response = RestClient::Response.create('abc', net_http_res, {:method => :post}, @request)
120
- lambda { response.return!(@request)}.should raise_error(RestClient::TemporaryRedirect)
148
+ net_http_res = response_double(:code => 307)
149
+ response = RestClient::Response.create('abc', net_http_res,
150
+ {:method => :post}, @request)
151
+ lambda {
152
+ response.return!
153
+ }.should raise_error(RestClient::TemporaryRedirect)
121
154
  end
122
155
 
123
156
  it "doesn't follow a redirection when the request is a put" do
124
- net_http_res = double('net http response', :code => 301)
125
- response = RestClient::Response.create('abc', net_http_res, {:method => :put}, @request)
126
- lambda { response.return!(@request)}.should raise_error(RestClient::MovedPermanently)
157
+ net_http_res = response_double(:code => 301)
158
+ response = RestClient::Response.create('abc', net_http_res,
159
+ {:method => :put}, @request)
160
+ lambda {
161
+ response.return!
162
+ }.should raise_error(RestClient::MovedPermanently)
127
163
  end
128
164
 
129
165
  it "follows a redirection when the request is a post and result is a 303" do
@@ -159,17 +195,25 @@ describe RestClient::Response do
159
195
  it "follows no more than 10 redirections before raising error" do
160
196
  stub_request(:get, 'http://some/redirect-1').to_return(:body => '', :status => 301, :headers => {'Location' => 'http://some/redirect-2'})
161
197
  stub_request(:get, 'http://some/redirect-2').to_return(:body => '', :status => 301, :headers => {'Location' => 'http://some/redirect-2'})
162
- lambda { RestClient::Request.execute(:url => 'http://some/redirect-1', :method => :get) }.should raise_error(RestClient::MaxRedirectsReached)
198
+ lambda {
199
+ RestClient::Request.execute(url: 'http://some/redirect-1', method: :get)
200
+ }.should raise_error(RestClient::MovedPermanently) { |ex|
201
+ ex.response.history.each {|r| r.should be_a(RestClient::Response) }
202
+ ex.response.history.length.should eq 10
203
+ }
163
204
  WebMock.should have_requested(:get, 'http://some/redirect-2').times(10)
164
205
  end
165
206
 
166
207
  it "follows no more than max_redirects redirections, if specified" do
167
208
  stub_request(:get, 'http://some/redirect-1').to_return(:body => '', :status => 301, :headers => {'Location' => 'http://some/redirect-2'})
168
209
  stub_request(:get, 'http://some/redirect-2').to_return(:body => '', :status => 301, :headers => {'Location' => 'http://some/redirect-2'})
169
- lambda { RestClient::Request.execute(:url => 'http://some/redirect-1', :method => :get, :max_redirects => 5) }.should raise_error(RestClient::MaxRedirectsReached)
210
+ lambda {
211
+ RestClient::Request.execute(url: 'http://some/redirect-1', method: :get, max_redirects: 5)
212
+ }.should raise_error(RestClient::MovedPermanently) { |ex|
213
+ ex.response.history.length.should eq 5
214
+ }
170
215
  WebMock.should have_requested(:get, 'http://some/redirect-2').times(5)
171
216
  end
172
217
  end
173
218
 
174
-
175
219
  end
@@ -1,4 +1,4 @@
1
- require 'spec_helper'
1
+ require_relative '_lib'
2
2
 
3
3
  describe RestClient do
4
4
  describe "API" do
@@ -71,9 +71,9 @@ describe RestClient do
71
71
  end
72
72
 
73
73
  describe 'version' do
74
- it 'has a version ~> 1.8.0.alpha' do
74
+ it 'has a version ~> 2.0.0.alpha' do
75
75
  ver = Gem::Version.new(RestClient.version)
76
- Gem::Requirement.new('~> 1.8.0.alpha').should be_satisfied_by(ver)
76
+ Gem::Requirement.new('~> 2.0.0.alpha').should be_satisfied_by(ver)
77
77
  end
78
78
  end
79
79
  end
@@ -0,0 +1,71 @@
1
+ require_relative '_lib'
2
+
3
+ describe RestClient::Utils do
4
+ describe '.get_encoding_from_headers' do
5
+ it 'assumes no encoding by default for text' do
6
+ headers = {:content_type => 'text/plain'}
7
+ RestClient::Utils.get_encoding_from_headers(headers).
8
+ should eq nil
9
+ end
10
+
11
+ it 'returns nil on failures' do
12
+ RestClient::Utils.get_encoding_from_headers(
13
+ {:content_type => 'blah'}).should eq nil
14
+ RestClient::Utils.get_encoding_from_headers(
15
+ {}).should eq nil
16
+ RestClient::Utils.get_encoding_from_headers(
17
+ {:content_type => 'foo; bar=baz'}).should eq nil
18
+ end
19
+
20
+ it 'handles various charsets' do
21
+ RestClient::Utils.get_encoding_from_headers(
22
+ {:content_type => 'text/plain; charset=UTF-8'}).should eq 'UTF-8'
23
+ RestClient::Utils.get_encoding_from_headers(
24
+ {:content_type => 'application/json; charset=ISO-8859-1'}).
25
+ should eq 'ISO-8859-1'
26
+ RestClient::Utils.get_encoding_from_headers(
27
+ {:content_type => 'text/html; charset=windows-1251'}).
28
+ should eq 'windows-1251'
29
+
30
+ RestClient::Utils.get_encoding_from_headers(
31
+ {:content_type => 'text/html; charset="UTF-16"'}).
32
+ should eq 'UTF-16'
33
+ end
34
+ end
35
+
36
+ describe '.cgi_parse_header' do
37
+ it 'parses headers' do
38
+ RestClient::Utils.cgi_parse_header('text/plain').
39
+ should eq ['text/plain', {}]
40
+
41
+ RestClient::Utils.cgi_parse_header('text/vnd.just.made.this.up ; ').
42
+ should eq ['text/vnd.just.made.this.up', {}]
43
+
44
+ RestClient::Utils.cgi_parse_header('text/plain;charset=us-ascii').
45
+ should eq ['text/plain', {'charset' => 'us-ascii'}]
46
+
47
+ RestClient::Utils.cgi_parse_header('text/plain ; charset="us-ascii"').
48
+ should eq ['text/plain', {'charset' => 'us-ascii'}]
49
+
50
+ RestClient::Utils.cgi_parse_header(
51
+ 'text/plain ; charset="us-ascii"; another=opt').
52
+ should eq ['text/plain', {'charset' => 'us-ascii', 'another' => 'opt'}]
53
+
54
+ RestClient::Utils.cgi_parse_header(
55
+ 'attachment; filename="silly.txt"').
56
+ should eq ['attachment', {'filename' => 'silly.txt'}]
57
+
58
+ RestClient::Utils.cgi_parse_header(
59
+ 'attachment; filename="strange;name"').
60
+ should eq ['attachment', {'filename' => 'strange;name'}]
61
+
62
+ RestClient::Utils.cgi_parse_header(
63
+ 'attachment; filename="strange;name";size=123;').should eq \
64
+ ['attachment', {'filename' => 'strange;name', 'size' => '123'}]
65
+
66
+ RestClient::Utils.cgi_parse_header(
67
+ 'form-data; name="files"; filename="fo\\"o;bar"').should eq \
68
+ ['form-data', {'name' => 'files', 'filename' => 'fo"o;bar'}]
69
+ end
70
+ end
71
+ end
@@ -1,4 +1,4 @@
1
- require 'spec_helper'
1
+ require_relative '../_lib'
2
2
 
3
3
  describe 'RestClient::Windows::RootCerts',
4
4
  :if => RestClient::Platform.windows? do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rest-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.8.0
4
+ version: 2.0.0.rc1
5
5
  platform: ruby
6
6
  authors:
7
7
  - REST Client Team
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-24 00:00:00.000000000 Z
11
+ date: 2015-06-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: webmock
@@ -30,40 +30,40 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '2.4'
33
+ version: '2.99'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '2.4'
40
+ version: '2.99'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: pry
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ">="
45
+ - - "~>"
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ">="
52
+ - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: pry-doc
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ">="
59
+ - - "~>"
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ">="
66
+ - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  - !ruby/object:Gem::Dependency
@@ -86,6 +86,20 @@ dependencies:
86
86
  - - "<"
87
87
  - !ruby/object:Gem::Version
88
88
  version: '5.0'
89
+ - !ruby/object:Gem::Dependency
90
+ name: rubocop
91
+ requirement: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - "~>"
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ type: :development
97
+ prerelease: false
98
+ version_requirements: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - "~>"
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
89
103
  - !ruby/object:Gem::Dependency
90
104
  name: http-cookie
91
105
  requirement: !ruby/object:Gem::Requirement
@@ -132,14 +146,14 @@ dependencies:
132
146
  requirements:
133
147
  - - "~>"
134
148
  - !ruby/object:Gem::Version
135
- version: '0.7'
149
+ version: '0.8'
136
150
  type: :runtime
137
151
  prerelease: false
138
152
  version_requirements: !ruby/object:Gem::Requirement
139
153
  requirements:
140
154
  - - "~>"
141
155
  - !ruby/object:Gem::Version
142
- version: '0.7'
156
+ version: '0.8'
143
157
  description: 'A simple HTTP and REST client for Ruby, inspired by the Sinatra microframework
144
158
  style of specifying actions: get, put, post, delete.'
145
159
  email: rest.client@librelist.com
@@ -152,6 +166,8 @@ extra_rdoc_files:
152
166
  files:
153
167
  - ".gitignore"
154
168
  - ".rspec"
169
+ - ".rubocop-disables.yml"
170
+ - ".rubocop.yml"
155
171
  - ".travis.yml"
156
172
  - AUTHORS
157
173
  - Gemfile
@@ -171,11 +187,14 @@ files:
171
187
  - lib/restclient/request.rb
172
188
  - lib/restclient/resource.rb
173
189
  - lib/restclient/response.rb
190
+ - lib/restclient/utils.rb
174
191
  - lib/restclient/version.rb
175
192
  - lib/restclient/windows.rb
176
193
  - lib/restclient/windows/root_certs.rb
177
194
  - rest-client.gemspec
178
195
  - rest-client.windows.gemspec
196
+ - spec/helpers.rb
197
+ - spec/integration/_lib.rb
179
198
  - spec/integration/capath_digicert/244b5494.0
180
199
  - spec/integration/capath_digicert/81b9768f.0
181
200
  - spec/integration/capath_digicert/README
@@ -186,9 +205,11 @@ files:
186
205
  - spec/integration/capath_verisign/verisign.crt
187
206
  - spec/integration/certs/digicert.crt
188
207
  - spec/integration/certs/verisign.crt
208
+ - spec/integration/httpbin_spec.rb
189
209
  - spec/integration/integration_spec.rb
190
210
  - spec/integration/request_spec.rb
191
211
  - spec/spec_helper.rb
212
+ - spec/unit/_lib.rb
192
213
  - spec/unit/abstract_response_spec.rb
193
214
  - spec/unit/exceptions_spec.rb
194
215
  - spec/unit/master_shake.jpg
@@ -199,6 +220,7 @@ files:
199
220
  - spec/unit/resource_spec.rb
200
221
  - spec/unit/response_spec.rb
201
222
  - spec/unit/restclient_spec.rb
223
+ - spec/unit/utils_spec.rb
202
224
  - spec/unit/windows/root_certs_spec.rb
203
225
  homepage: https://github.com/rest-client/rest-client
204
226
  licenses:
@@ -212,20 +234,22 @@ required_ruby_version: !ruby/object:Gem::Requirement
212
234
  requirements:
213
235
  - - ">="
214
236
  - !ruby/object:Gem::Version
215
- version: 1.9.2
237
+ version: 1.9.3
216
238
  required_rubygems_version: !ruby/object:Gem::Requirement
217
239
  requirements:
218
- - - ">="
240
+ - - ">"
219
241
  - !ruby/object:Gem::Version
220
- version: '0'
242
+ version: 1.3.1
221
243
  requirements: []
222
244
  rubyforge_project:
223
- rubygems_version: 2.2.2
245
+ rubygems_version: 2.2.3
224
246
  signing_key:
225
247
  specification_version: 4
226
248
  summary: Simple HTTP and REST client for Ruby, inspired by microframework syntax for
227
249
  specifying actions.
228
250
  test_files:
251
+ - spec/helpers.rb
252
+ - spec/integration/_lib.rb
229
253
  - spec/integration/capath_digicert/244b5494.0
230
254
  - spec/integration/capath_digicert/81b9768f.0
231
255
  - spec/integration/capath_digicert/README
@@ -236,9 +260,11 @@ test_files:
236
260
  - spec/integration/capath_verisign/verisign.crt
237
261
  - spec/integration/certs/digicert.crt
238
262
  - spec/integration/certs/verisign.crt
263
+ - spec/integration/httpbin_spec.rb
239
264
  - spec/integration/integration_spec.rb
240
265
  - spec/integration/request_spec.rb
241
266
  - spec/spec_helper.rb
267
+ - spec/unit/_lib.rb
242
268
  - spec/unit/abstract_response_spec.rb
243
269
  - spec/unit/exceptions_spec.rb
244
270
  - spec/unit/master_shake.jpg
@@ -249,5 +275,6 @@ test_files:
249
275
  - spec/unit/resource_spec.rb
250
276
  - spec/unit/response_spec.rb
251
277
  - spec/unit/restclient_spec.rb
278
+ - spec/unit/utils_spec.rb
252
279
  - spec/unit/windows/root_certs_spec.rb
253
280
  has_rdoc: