rest-client 1.8.0-x64-mingw32 → 2.0.0.rc1-x64-mingw32

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: x64-mingw32
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
  - !ruby/object:Gem::Dependency
144
158
  name: ffi
145
159
  requirement: !ruby/object:Gem::Requirement
@@ -166,6 +180,8 @@ extra_rdoc_files:
166
180
  files:
167
181
  - ".gitignore"
168
182
  - ".rspec"
183
+ - ".rubocop-disables.yml"
184
+ - ".rubocop.yml"
169
185
  - ".travis.yml"
170
186
  - AUTHORS
171
187
  - Gemfile
@@ -185,11 +201,14 @@ files:
185
201
  - lib/restclient/request.rb
186
202
  - lib/restclient/resource.rb
187
203
  - lib/restclient/response.rb
204
+ - lib/restclient/utils.rb
188
205
  - lib/restclient/version.rb
189
206
  - lib/restclient/windows.rb
190
207
  - lib/restclient/windows/root_certs.rb
191
208
  - rest-client.gemspec
192
209
  - rest-client.windows.gemspec
210
+ - spec/helpers.rb
211
+ - spec/integration/_lib.rb
193
212
  - spec/integration/capath_digicert/244b5494.0
194
213
  - spec/integration/capath_digicert/81b9768f.0
195
214
  - spec/integration/capath_digicert/README
@@ -200,9 +219,11 @@ files:
200
219
  - spec/integration/capath_verisign/verisign.crt
201
220
  - spec/integration/certs/digicert.crt
202
221
  - spec/integration/certs/verisign.crt
222
+ - spec/integration/httpbin_spec.rb
203
223
  - spec/integration/integration_spec.rb
204
224
  - spec/integration/request_spec.rb
205
225
  - spec/spec_helper.rb
226
+ - spec/unit/_lib.rb
206
227
  - spec/unit/abstract_response_spec.rb
207
228
  - spec/unit/exceptions_spec.rb
208
229
  - spec/unit/master_shake.jpg
@@ -213,6 +234,7 @@ files:
213
234
  - spec/unit/resource_spec.rb
214
235
  - spec/unit/response_spec.rb
215
236
  - spec/unit/restclient_spec.rb
237
+ - spec/unit/utils_spec.rb
216
238
  - spec/unit/windows/root_certs_spec.rb
217
239
  homepage: https://github.com/rest-client/rest-client
218
240
  licenses:
@@ -226,20 +248,22 @@ required_ruby_version: !ruby/object:Gem::Requirement
226
248
  requirements:
227
249
  - - ">="
228
250
  - !ruby/object:Gem::Version
229
- version: 1.9.2
251
+ version: 1.9.3
230
252
  required_rubygems_version: !ruby/object:Gem::Requirement
231
253
  requirements:
232
- - - ">="
254
+ - - ">"
233
255
  - !ruby/object:Gem::Version
234
- version: '0'
256
+ version: 1.3.1
235
257
  requirements: []
236
258
  rubyforge_project:
237
- rubygems_version: 2.2.2
259
+ rubygems_version: 2.2.3
238
260
  signing_key:
239
261
  specification_version: 4
240
262
  summary: Simple HTTP and REST client for Ruby, inspired by microframework syntax for
241
263
  specifying actions.
242
264
  test_files:
265
+ - spec/helpers.rb
266
+ - spec/integration/_lib.rb
243
267
  - spec/integration/capath_digicert/244b5494.0
244
268
  - spec/integration/capath_digicert/81b9768f.0
245
269
  - spec/integration/capath_digicert/README
@@ -250,9 +274,11 @@ test_files:
250
274
  - spec/integration/capath_verisign/verisign.crt
251
275
  - spec/integration/certs/digicert.crt
252
276
  - spec/integration/certs/verisign.crt
277
+ - spec/integration/httpbin_spec.rb
253
278
  - spec/integration/integration_spec.rb
254
279
  - spec/integration/request_spec.rb
255
280
  - spec/spec_helper.rb
281
+ - spec/unit/_lib.rb
256
282
  - spec/unit/abstract_response_spec.rb
257
283
  - spec/unit/exceptions_spec.rb
258
284
  - spec/unit/master_shake.jpg
@@ -263,5 +289,6 @@ test_files:
263
289
  - spec/unit/resource_spec.rb
264
290
  - spec/unit/response_spec.rb
265
291
  - spec/unit/restclient_spec.rb
292
+ - spec/unit/utils_spec.rb
266
293
  - spec/unit/windows/root_certs_spec.rb
267
294
  has_rdoc: