rest-client 1.6.7 → 1.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +7 -0
- data/.rspec +1 -0
- data/.travis.yml +14 -0
- data/AUTHORS +81 -0
- data/Gemfile +11 -0
- data/LICENSE +21 -0
- data/README.rdoc +63 -24
- data/Rakefile +85 -35
- data/bin/restclient +9 -8
- data/history.md +63 -1
- data/lib/restclient/abstract_response.rb +44 -15
- data/lib/restclient/exceptions.rb +20 -10
- data/lib/restclient/payload.rb +21 -18
- data/lib/restclient/platform.rb +30 -0
- data/lib/restclient/raw_response.rb +3 -2
- data/lib/restclient/request.rb +368 -63
- data/lib/restclient/resource.rb +3 -4
- data/lib/restclient/response.rb +2 -5
- data/lib/restclient/version.rb +7 -0
- data/lib/restclient/windows/root_certs.rb +105 -0
- data/lib/restclient/windows.rb +8 -0
- data/lib/restclient.rb +6 -15
- data/rest-client.gemspec +30 -0
- data/rest-client.windows.gemspec +19 -0
- 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/capath_verisign/415660c1.0 +14 -0
- data/spec/integration/capath_verisign/7651b327.0 +14 -0
- data/spec/integration/capath_verisign/README +8 -0
- data/spec/integration/capath_verisign/verisign.crt +14 -0
- data/spec/integration/certs/digicert.crt +19 -0
- data/spec/{integration_spec.rb → integration/integration_spec.rb} +10 -13
- data/spec/integration/request_spec.rb +86 -7
- data/spec/spec_helper.rb +2 -0
- data/spec/{abstract_response_spec.rb → unit/abstract_response_spec.rb} +18 -15
- data/spec/{exceptions_spec.rb → unit/exceptions_spec.rb} +17 -20
- data/spec/unit/master_shake.jpg +0 -0
- data/spec/{payload_spec.rb → unit/payload_spec.rb} +42 -31
- data/spec/unit/raw_response_spec.rb +18 -0
- data/spec/{request2_spec.rb → unit/request2_spec.rb} +6 -14
- data/spec/unit/request_spec.rb +917 -0
- data/spec/{resource_spec.rb → unit/resource_spec.rb} +27 -31
- data/spec/{response_spec.rb → unit/response_spec.rb} +63 -57
- data/spec/{restclient_spec.rb → unit/restclient_spec.rb} +8 -2
- data/spec/unit/windows/root_certs_spec.rb +22 -0
- metadata +210 -112
- data/VERSION +0 -1
- data/lib/restclient/net_http_ext.rb +0 -55
- data/spec/base.rb +0 -16
- data/spec/integration/certs/equifax.crt +0 -19
- data/spec/master_shake.jpg +0 -0
- data/spec/raw_response_spec.rb +0 -17
- data/spec/request_spec.rb +0 -529
@@ -1,7 +1,4 @@
|
|
1
|
-
require
|
2
|
-
|
3
|
-
require 'webmock/rspec'
|
4
|
-
include WebMock
|
1
|
+
require 'spec_helper'
|
5
2
|
|
6
3
|
describe RestClient::Resource do
|
7
4
|
before do
|
@@ -51,83 +48,82 @@ describe RestClient::Resource do
|
|
51
48
|
|
52
49
|
it "is backwards compatible with previous constructor" do
|
53
50
|
@resource = RestClient::Resource.new('http://some/resource', 'user', 'pass')
|
54
|
-
@resource.user.should
|
55
|
-
@resource.password.should
|
51
|
+
@resource.user.should eq 'user'
|
52
|
+
@resource.password.should eq 'pass'
|
56
53
|
end
|
57
54
|
|
58
55
|
it "concatenates urls, inserting a slash when it needs one" do
|
59
|
-
@resource.concat_urls('http://example.com', 'resource').should
|
56
|
+
@resource.concat_urls('http://example.com', 'resource').should eq 'http://example.com/resource'
|
60
57
|
end
|
61
58
|
|
62
59
|
it "concatenates urls, using no slash if the first url ends with a slash" do
|
63
|
-
@resource.concat_urls('http://example.com/', 'resource').should
|
60
|
+
@resource.concat_urls('http://example.com/', 'resource').should eq 'http://example.com/resource'
|
64
61
|
end
|
65
62
|
|
66
63
|
it "concatenates urls, using no slash if the second url starts with a slash" do
|
67
|
-
@resource.concat_urls('http://example.com', '/resource').should
|
64
|
+
@resource.concat_urls('http://example.com', '/resource').should eq 'http://example.com/resource'
|
68
65
|
end
|
69
66
|
|
70
67
|
it "concatenates even non-string urls, :posts + 1 => 'posts/1'" do
|
71
|
-
@resource.concat_urls(:posts, 1).should
|
68
|
+
@resource.concat_urls(:posts, 1).should eq 'posts/1'
|
72
69
|
end
|
73
70
|
|
74
71
|
it "offers subresources via []" do
|
75
72
|
parent = RestClient::Resource.new('http://example.com')
|
76
|
-
parent['posts'].url.should
|
73
|
+
parent['posts'].url.should eq 'http://example.com/posts'
|
77
74
|
end
|
78
75
|
|
79
76
|
it "transports options to subresources" do
|
80
77
|
parent = RestClient::Resource.new('http://example.com', :user => 'user', :password => 'password')
|
81
|
-
parent['posts'].user.should
|
82
|
-
parent['posts'].password.should
|
78
|
+
parent['posts'].user.should eq 'user'
|
79
|
+
parent['posts'].password.should eq 'password'
|
83
80
|
end
|
84
81
|
|
85
82
|
it "passes a given block to subresources" do
|
86
|
-
block =
|
83
|
+
block = proc {|r| r}
|
87
84
|
parent = RestClient::Resource.new('http://example.com', &block)
|
88
|
-
parent['posts'].block.should
|
85
|
+
parent['posts'].block.should eq block
|
89
86
|
end
|
90
87
|
|
91
88
|
it "the block should be overrideable" do
|
92
|
-
block1 =
|
93
|
-
block2 =
|
89
|
+
block1 = proc {|r| r}
|
90
|
+
block2 = proc {|r| }
|
94
91
|
parent = RestClient::Resource.new('http://example.com', &block1)
|
95
|
-
# parent['posts', &block2].block.should
|
96
|
-
parent.send(:[], 'posts', &block2).block.should
|
92
|
+
# parent['posts', &block2].block.should eq block2 # ruby 1.9 syntax
|
93
|
+
parent.send(:[], 'posts', &block2).block.should eq block2
|
94
|
+
parent.send(:[], 'posts', &block2).block.should_not eq block1
|
97
95
|
end
|
98
96
|
|
99
97
|
it "the block should be overrideable in ruby 1.9 syntax" do
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
eval(r19_syntax)
|
107
|
-
end
|
98
|
+
block1 = proc {|r| r}
|
99
|
+
block2 = ->(r) {}
|
100
|
+
|
101
|
+
parent = RestClient::Resource.new('http://example.com', &block1)
|
102
|
+
parent['posts', &block2].block.should eq block2
|
103
|
+
parent['posts', &block2].block.should_not eq block1
|
108
104
|
end
|
109
105
|
|
110
106
|
it "prints its url with to_s" do
|
111
|
-
RestClient::Resource.new('x').to_s.should
|
107
|
+
RestClient::Resource.new('x').to_s.should eq 'x'
|
112
108
|
end
|
113
109
|
|
114
110
|
describe 'block' do
|
115
111
|
it 'can use block when creating the resource' do
|
116
112
|
stub_request(:get, 'www.example.com').to_return(:body => '', :status => 404)
|
117
113
|
resource = RestClient::Resource.new('www.example.com') { |response, request| 'foo' }
|
118
|
-
resource.get.should
|
114
|
+
resource.get.should eq 'foo'
|
119
115
|
end
|
120
116
|
|
121
117
|
it 'can use block when executing the resource' do
|
122
118
|
stub_request(:get, 'www.example.com').to_return(:body => '', :status => 404)
|
123
119
|
resource = RestClient::Resource.new('www.example.com')
|
124
|
-
resource.get { |response, request| 'foo' }.should
|
120
|
+
resource.get { |response, request| 'foo' }.should eq 'foo'
|
125
121
|
end
|
126
122
|
|
127
123
|
it 'execution block override resource block' do
|
128
124
|
stub_request(:get, 'www.example.com').to_return(:body => '', :status => 404)
|
129
125
|
resource = RestClient::Resource.new('www.example.com') { |response, request| 'foo' }
|
130
|
-
resource.get { |response, request| 'bar' }.should
|
126
|
+
resource.get { |response, request| 'bar' }.should eq 'bar'
|
131
127
|
end
|
132
128
|
|
133
129
|
end
|
@@ -1,65 +1,65 @@
|
|
1
|
-
require
|
2
|
-
|
3
|
-
require 'webmock/rspec'
|
4
|
-
include WebMock
|
1
|
+
require 'spec_helper'
|
5
2
|
|
6
3
|
describe RestClient::Response do
|
7
4
|
before do
|
8
|
-
@net_http_res =
|
9
|
-
@
|
10
|
-
@
|
5
|
+
@net_http_res = double('net http response', :to_hash => {"Status" => ["200 OK"]}, :code => 200)
|
6
|
+
@example_url = 'http://example.com'
|
7
|
+
@request = double('http request', :user => nil, :password => nil, :url => @example_url)
|
8
|
+
@response = RestClient::Response.create('abc', @net_http_res, {}, @request)
|
11
9
|
end
|
12
10
|
|
13
11
|
it "behaves like string" do
|
14
|
-
@response.should
|
15
|
-
@response.to_str.should
|
16
|
-
@response.to_i.should
|
12
|
+
@response.to_s.should eq 'abc'
|
13
|
+
@response.to_str.should eq 'abc'
|
14
|
+
@response.to_i.should eq 200
|
17
15
|
end
|
18
16
|
|
19
17
|
it "accepts nil strings and sets it to empty for the case of HEAD" do
|
20
|
-
RestClient::Response.create(nil, @net_http_res, {}).should
|
18
|
+
RestClient::Response.create(nil, @net_http_res, {}, @request).to_s.should eq ""
|
21
19
|
end
|
22
20
|
|
23
21
|
it "test headers and raw headers" do
|
24
|
-
@response.raw_headers["Status"][0].should
|
25
|
-
@response.headers[:status].should
|
22
|
+
@response.raw_headers["Status"][0].should eq "200 OK"
|
23
|
+
@response.headers[:status].should eq "200 OK"
|
26
24
|
end
|
27
25
|
|
28
26
|
describe "cookie processing" do
|
29
27
|
it "should correctly deal with one Set-Cookie header with one cookie inside" do
|
30
|
-
|
31
|
-
|
32
|
-
response
|
33
|
-
response.
|
28
|
+
header_val = "main_page=main_page_no_rewrite; path=/; expires=Sat, 10-Jan-2037 15:03:14 GMT".freeze
|
29
|
+
|
30
|
+
net_http_res = double('net http response', :to_hash => {"etag" => ["\"e1ac1a2df945942ef4cac8116366baad\""], "set-cookie" => [header_val]})
|
31
|
+
response = RestClient::Response.create('abc', net_http_res, {}, @request)
|
32
|
+
response.headers[:set_cookie].should eq [header_val]
|
33
|
+
response.cookies.should eq({ "main_page" => "main_page_no_rewrite" })
|
34
34
|
end
|
35
35
|
|
36
36
|
it "should correctly deal with multiple cookies [multiple Set-Cookie headers]" do
|
37
|
-
net_http_res =
|
38
|
-
response = RestClient::Response.create('abc', net_http_res, {})
|
39
|
-
response.headers[:set_cookie].should
|
40
|
-
response.cookies.should
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
}
|
37
|
+
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"]})
|
38
|
+
response = RestClient::Response.create('abc', net_http_res, {}, @request)
|
39
|
+
response.headers[:set_cookie].should 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"]
|
40
|
+
response.cookies.should eq({
|
41
|
+
"main_page" => "main_page_no_rewrite",
|
42
|
+
"remember_me" => "",
|
43
|
+
"user" => "somebody"
|
44
|
+
})
|
45
45
|
end
|
46
46
|
|
47
47
|
it "should correctly deal with multiple cookies [one Set-Cookie header with multiple cookies]" do
|
48
|
-
net_http_res =
|
49
|
-
response = RestClient::Response.create('abc', net_http_res, {})
|
50
|
-
response.cookies.should
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
}
|
48
|
+
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"]})
|
49
|
+
response = RestClient::Response.create('abc', net_http_res, {}, @request)
|
50
|
+
response.cookies.should eq({
|
51
|
+
"main_page" => "main_page_no_rewrite",
|
52
|
+
"remember_me" => "",
|
53
|
+
"user" => "somebody"
|
54
|
+
})
|
55
55
|
end
|
56
56
|
end
|
57
57
|
|
58
58
|
describe "exceptions processing" do
|
59
59
|
it "should return itself for normal codes" do
|
60
60
|
(200..206).each do |code|
|
61
|
-
net_http_res =
|
62
|
-
response = RestClient::Response.create('abc', net_http_res, {})
|
61
|
+
net_http_res = double('net http response', :code => '200')
|
62
|
+
response = RestClient::Response.create('abc', net_http_res, {}, @request)
|
63
63
|
response.return! @request
|
64
64
|
end
|
65
65
|
end
|
@@ -67,8 +67,8 @@ describe RestClient::Response do
|
|
67
67
|
it "should throw an exception for other codes" do
|
68
68
|
RestClient::Exceptions::EXCEPTIONS_MAP.each_key do |code|
|
69
69
|
unless (200..207).include? code
|
70
|
-
net_http_res =
|
71
|
-
response = RestClient::Response.create('abc', net_http_res, {})
|
70
|
+
net_http_res = double('net http response', :code => code.to_i)
|
71
|
+
response = RestClient::Response.create('abc', net_http_res, {}, @request)
|
72
72
|
lambda { response.return!}.should raise_error
|
73
73
|
end
|
74
74
|
end
|
@@ -77,86 +77,92 @@ describe RestClient::Response do
|
|
77
77
|
end
|
78
78
|
|
79
79
|
describe "redirection" do
|
80
|
-
|
80
|
+
|
81
81
|
it "follows a redirection when the request is a get" do
|
82
82
|
stub_request(:get, 'http://some/resource').to_return(:body => '', :status => 301, :headers => {'Location' => 'http://new/resource'})
|
83
83
|
stub_request(:get, 'http://new/resource').to_return(:body => 'Foo')
|
84
|
-
RestClient::Request.execute(:url => 'http://some/resource', :method => :get).body.should
|
84
|
+
RestClient::Request.execute(:url => 'http://some/resource', :method => :get).body.should eq 'Foo'
|
85
85
|
end
|
86
86
|
|
87
87
|
it "follows a redirection and keep the parameters" do
|
88
88
|
stub_request(:get, 'http://foo:bar@some/resource').with(:headers => {'Accept' => 'application/json'}).to_return(:body => '', :status => 301, :headers => {'Location' => 'http://new/resource'})
|
89
89
|
stub_request(:get, 'http://foo:bar@new/resource').with(:headers => {'Accept' => 'application/json'}).to_return(:body => 'Foo')
|
90
|
-
RestClient::Request.execute(:url => 'http://some/resource', :method => :get, :user => 'foo', :password => 'bar', :headers => {:accept => :json}).body.should
|
90
|
+
RestClient::Request.execute(:url => 'http://some/resource', :method => :get, :user => 'foo', :password => 'bar', :headers => {:accept => :json}).body.should eq 'Foo'
|
91
91
|
end
|
92
92
|
|
93
93
|
it "follows a redirection and keep the cookies" do
|
94
|
-
stub_request(:get, 'http://some/resource').to_return(:body => '', :status => 301, :headers => {'Set-Cookie' =>
|
95
|
-
stub_request(:get, 'http://
|
96
|
-
RestClient::Request.execute(:url => 'http://some/resource', :method => :get).body.should
|
94
|
+
stub_request(:get, 'http://some/resource').to_return(:body => '', :status => 301, :headers => {'Set-Cookie' => 'Foo=Bar', 'Location' => 'http://some/new_resource', })
|
95
|
+
stub_request(:get, 'http://some/new_resource').with(:headers => {'Cookie' => 'Foo=Bar'}).to_return(:body => 'Qux')
|
96
|
+
RestClient::Request.execute(:url => 'http://some/resource', :method => :get).body.should eq 'Qux'
|
97
|
+
end
|
98
|
+
|
99
|
+
it 'does not keep cookies across domains' do
|
100
|
+
stub_request(:get, 'http://some/resource').to_return(:body => '', :status => 301, :headers => {'Set-Cookie' => 'Foo=Bar', 'Location' => 'http://new/resource', })
|
101
|
+
stub_request(:get, 'http://new/resource').with(:headers => {'Cookie' => ''}).to_return(:body => 'Qux')
|
102
|
+
RestClient::Request.execute(:url => 'http://some/resource', :method => :get).body.should eq 'Qux'
|
97
103
|
end
|
98
104
|
|
99
105
|
it "doesn't follow a 301 when the request is a post" do
|
100
|
-
net_http_res =
|
101
|
-
response = RestClient::Response.create('abc', net_http_res, {:method => :post})
|
106
|
+
net_http_res = double('net http response', :code => 301)
|
107
|
+
response = RestClient::Response.create('abc', net_http_res, {:method => :post}, @request)
|
102
108
|
lambda { response.return!(@request)}.should raise_error(RestClient::MovedPermanently)
|
103
109
|
end
|
104
110
|
|
105
111
|
it "doesn't follow a 302 when the request is a post" do
|
106
|
-
net_http_res =
|
107
|
-
response = RestClient::Response.create('abc', net_http_res, {:method => :post})
|
112
|
+
net_http_res = double('net http response', :code => 302)
|
113
|
+
response = RestClient::Response.create('abc', net_http_res, {:method => :post}, @request)
|
108
114
|
lambda { response.return!(@request)}.should raise_error(RestClient::Found)
|
109
115
|
end
|
110
116
|
|
111
117
|
it "doesn't follow a 307 when the request is a post" do
|
112
|
-
net_http_res =
|
113
|
-
response = RestClient::Response.create('abc', net_http_res, {:method => :post})
|
118
|
+
net_http_res = double('net http response', :code => 307)
|
119
|
+
response = RestClient::Response.create('abc', net_http_res, {:method => :post}, @request)
|
114
120
|
lambda { response.return!(@request)}.should raise_error(RestClient::TemporaryRedirect)
|
115
121
|
end
|
116
122
|
|
117
123
|
it "doesn't follow a redirection when the request is a put" do
|
118
|
-
net_http_res =
|
119
|
-
response = RestClient::Response.create('abc', net_http_res, {:method => :put})
|
124
|
+
net_http_res = double('net http response', :code => 301)
|
125
|
+
response = RestClient::Response.create('abc', net_http_res, {:method => :put}, @request)
|
120
126
|
lambda { response.return!(@request)}.should raise_error(RestClient::MovedPermanently)
|
121
127
|
end
|
122
128
|
|
123
129
|
it "follows a redirection when the request is a post and result is a 303" do
|
124
130
|
stub_request(:put, 'http://some/resource').to_return(:body => '', :status => 303, :headers => {'Location' => 'http://new/resource'})
|
125
131
|
stub_request(:get, 'http://new/resource').to_return(:body => 'Foo')
|
126
|
-
RestClient::Request.execute(:url => 'http://some/resource', :method => :put).body.should
|
132
|
+
RestClient::Request.execute(:url => 'http://some/resource', :method => :put).body.should eq 'Foo'
|
127
133
|
end
|
128
134
|
|
129
135
|
it "follows a redirection when the request is a head" do
|
130
136
|
stub_request(:head, 'http://some/resource').to_return(:body => '', :status => 301, :headers => {'Location' => 'http://new/resource'})
|
131
137
|
stub_request(:head, 'http://new/resource').to_return(:body => 'Foo')
|
132
|
-
RestClient::Request.execute(:url => 'http://some/resource', :method => :head).body.should
|
138
|
+
RestClient::Request.execute(:url => 'http://some/resource', :method => :head).body.should eq 'Foo'
|
133
139
|
end
|
134
140
|
|
135
141
|
it "handles redirects with relative paths" do
|
136
142
|
stub_request(:get, 'http://some/resource').to_return(:body => '', :status => 301, :headers => {'Location' => 'index'})
|
137
143
|
stub_request(:get, 'http://some/index').to_return(:body => 'Foo')
|
138
|
-
RestClient::Request.execute(:url => 'http://some/resource', :method => :get).body.should
|
144
|
+
RestClient::Request.execute(:url => 'http://some/resource', :method => :get).body.should eq 'Foo'
|
139
145
|
end
|
140
146
|
|
141
147
|
it "handles redirects with relative path and query string" do
|
142
148
|
stub_request(:get, 'http://some/resource').to_return(:body => '', :status => 301, :headers => {'Location' => 'index?q=1'})
|
143
149
|
stub_request(:get, 'http://some/index?q=1').to_return(:body => 'Foo')
|
144
|
-
RestClient::Request.execute(:url => 'http://some/resource', :method => :get).body.should
|
150
|
+
RestClient::Request.execute(:url => 'http://some/resource', :method => :get).body.should eq 'Foo'
|
145
151
|
end
|
146
152
|
|
147
153
|
it "follow a redirection when the request is a get and the response is in the 30x range" do
|
148
154
|
stub_request(:get, 'http://some/resource').to_return(:body => '', :status => 301, :headers => {'Location' => 'http://new/resource'})
|
149
155
|
stub_request(:get, 'http://new/resource').to_return(:body => 'Foo')
|
150
|
-
RestClient::Request.execute(:url => 'http://some/resource', :method => :get).body.should
|
156
|
+
RestClient::Request.execute(:url => 'http://some/resource', :method => :get).body.should eq 'Foo'
|
151
157
|
end
|
152
|
-
|
158
|
+
|
153
159
|
it "follows no more than 10 redirections before raising error" do
|
154
160
|
stub_request(:get, 'http://some/redirect-1').to_return(:body => '', :status => 301, :headers => {'Location' => 'http://some/redirect-2'})
|
155
161
|
stub_request(:get, 'http://some/redirect-2').to_return(:body => '', :status => 301, :headers => {'Location' => 'http://some/redirect-2'})
|
156
162
|
lambda { RestClient::Request.execute(:url => 'http://some/redirect-1', :method => :get) }.should raise_error(RestClient::MaxRedirectsReached)
|
157
163
|
WebMock.should have_requested(:get, 'http://some/redirect-2').times(10)
|
158
164
|
end
|
159
|
-
|
165
|
+
|
160
166
|
it "follows no more than max_redirects redirections, if specified" do
|
161
167
|
stub_request(:get, 'http://some/redirect-1').to_return(:body => '', :status => 301, :headers => {'Location' => 'http://some/redirect-2'})
|
162
168
|
stub_request(:get, 'http://some/redirect-2').to_return(:body => '', :status => 301, :headers => {'Location' => 'http://some/redirect-2'})
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
3
|
describe RestClient do
|
4
4
|
describe "API" do
|
@@ -63,11 +63,17 @@ describe RestClient do
|
|
63
63
|
|
64
64
|
it "append the log to the requested filename" do
|
65
65
|
RestClient.log = '/tmp/restclient.log'
|
66
|
-
f =
|
66
|
+
f = double('file handle')
|
67
67
|
File.should_receive(:open).with('/tmp/restclient.log', 'a').and_yield(f)
|
68
68
|
f.should_receive(:puts).with('xyz')
|
69
69
|
RestClient.log << 'xyz'
|
70
70
|
end
|
71
71
|
end
|
72
72
|
|
73
|
+
describe 'version' do
|
74
|
+
it 'has a version ~> 1.8.0.alpha' do
|
75
|
+
ver = Gem::Version.new(RestClient.version)
|
76
|
+
Gem::Requirement.new('~> 1.8.0.alpha').should be_satisfied_by(ver)
|
77
|
+
end
|
78
|
+
end
|
73
79
|
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'RestClient::Windows::RootCerts',
|
4
|
+
:if => RestClient::Platform.windows? do
|
5
|
+
let(:x509_store) { RestClient::Windows::RootCerts.instance.to_a }
|
6
|
+
|
7
|
+
it 'should return at least one X509 certificate' do
|
8
|
+
expect(x509_store.to_a).to have_at_least(1).items
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'should return an X509 certificate with a subject' do
|
12
|
+
x509 = x509_store.first
|
13
|
+
|
14
|
+
expect(x509.subject.to_s).to match(/CN=.*/)
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'should return X509 certificate objects' do
|
18
|
+
x509_store.each do |cert|
|
19
|
+
cert.should be_a(OpenSSL::X509::Certificate)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|