rest-client 2.0.0.rc2-x64-mingw32 → 2.0.0.rc3-x64-mingw32

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.
@@ -7,37 +7,37 @@ describe RestClient::Resource do
7
7
 
8
8
  context "Resource delegation" do
9
9
  it "GET" do
10
- RestClient::Request.should_receive(:execute).with(:method => :get, :url => 'http://some/resource', :headers => {'X-Something' => '1'}, :user => 'jane', :password => 'mypass')
10
+ expect(RestClient::Request).to receive(:execute).with(:method => :get, :url => 'http://some/resource', :headers => {'X-Something' => '1'}, :user => 'jane', :password => 'mypass')
11
11
  @resource.get
12
12
  end
13
13
 
14
14
  it "HEAD" do
15
- RestClient::Request.should_receive(:execute).with(:method => :head, :url => 'http://some/resource', :headers => {'X-Something' => '1'}, :user => 'jane', :password => 'mypass')
15
+ expect(RestClient::Request).to receive(:execute).with(:method => :head, :url => 'http://some/resource', :headers => {'X-Something' => '1'}, :user => 'jane', :password => 'mypass')
16
16
  @resource.head
17
17
  end
18
18
 
19
19
  it "POST" do
20
- RestClient::Request.should_receive(:execute).with(:method => :post, :url => 'http://some/resource', :payload => 'abc', :headers => {:content_type => 'image/jpg', 'X-Something' => '1'}, :user => 'jane', :password => 'mypass')
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
21
  @resource.post 'abc', :content_type => 'image/jpg'
22
22
  end
23
23
 
24
24
  it "PUT" do
25
- RestClient::Request.should_receive(:execute).with(:method => :put, :url => 'http://some/resource', :payload => 'abc', :headers => {:content_type => 'image/jpg', 'X-Something' => '1'}, :user => 'jane', :password => 'mypass')
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
26
  @resource.put 'abc', :content_type => 'image/jpg'
27
27
  end
28
28
 
29
29
  it "PATCH" do
30
- RestClient::Request.should_receive(:execute).with(:method => :patch, :url => 'http://some/resource', :payload => 'abc', :headers => {:content_type => 'image/jpg', 'X-Something' => '1'}, :user => 'jane', :password => 'mypass')
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
31
  @resource.patch 'abc', :content_type => 'image/jpg'
32
32
  end
33
33
 
34
34
  it "DELETE" do
35
- RestClient::Request.should_receive(:execute).with(:method => :delete, :url => 'http://some/resource', :headers => {'X-Something' => '1'}, :user => 'jane', :password => 'mypass')
35
+ expect(RestClient::Request).to receive(:execute).with(:method => :delete, :url => 'http://some/resource', :headers => {'X-Something' => '1'}, :user => 'jane', :password => 'mypass')
36
36
  @resource.delete
37
37
  end
38
38
 
39
39
  it "overrides resource headers" do
40
- RestClient::Request.should_receive(:execute).with(:method => :get, :url => 'http://some/resource', :headers => {'X-Something' => '2'}, :user => 'jane', :password => 'mypass')
40
+ expect(RestClient::Request).to receive(:execute).with(:method => :get, :url => 'http://some/resource', :headers => {'X-Something' => '2'}, :user => 'jane', :password => 'mypass')
41
41
  @resource.get 'X-Something' => '2'
42
42
  end
43
43
  end
@@ -48,41 +48,41 @@ describe RestClient::Resource do
48
48
 
49
49
  it "is backwards compatible with previous constructor" do
50
50
  @resource = RestClient::Resource.new('http://some/resource', 'user', 'pass')
51
- @resource.user.should eq 'user'
52
- @resource.password.should eq 'pass'
51
+ expect(@resource.user).to eq 'user'
52
+ expect(@resource.password).to eq 'pass'
53
53
  end
54
54
 
55
55
  it "concatenates urls, inserting a slash when it needs one" do
56
- @resource.concat_urls('http://example.com', 'resource').should eq 'http://example.com/resource'
56
+ expect(@resource.concat_urls('http://example.com', 'resource')).to eq 'http://example.com/resource'
57
57
  end
58
58
 
59
59
  it "concatenates urls, using no slash if the first url ends with a slash" do
60
- @resource.concat_urls('http://example.com/', 'resource').should eq 'http://example.com/resource'
60
+ expect(@resource.concat_urls('http://example.com/', 'resource')).to eq 'http://example.com/resource'
61
61
  end
62
62
 
63
63
  it "concatenates urls, using no slash if the second url starts with a slash" do
64
- @resource.concat_urls('http://example.com', '/resource').should eq 'http://example.com/resource'
64
+ expect(@resource.concat_urls('http://example.com', '/resource')).to eq 'http://example.com/resource'
65
65
  end
66
66
 
67
67
  it "concatenates even non-string urls, :posts + 1 => 'posts/1'" do
68
- @resource.concat_urls(:posts, 1).should eq 'posts/1'
68
+ expect(@resource.concat_urls(:posts, 1)).to eq 'posts/1'
69
69
  end
70
70
 
71
71
  it "offers subresources via []" do
72
72
  parent = RestClient::Resource.new('http://example.com')
73
- parent['posts'].url.should eq 'http://example.com/posts'
73
+ expect(parent['posts'].url).to eq 'http://example.com/posts'
74
74
  end
75
75
 
76
76
  it "transports options to subresources" do
77
77
  parent = RestClient::Resource.new('http://example.com', :user => 'user', :password => 'password')
78
- parent['posts'].user.should eq 'user'
79
- parent['posts'].password.should eq 'password'
78
+ expect(parent['posts'].user).to eq 'user'
79
+ expect(parent['posts'].password).to eq 'password'
80
80
  end
81
81
 
82
82
  it "passes a given block to subresources" do
83
83
  block = proc {|r| r}
84
84
  parent = RestClient::Resource.new('http://example.com', &block)
85
- parent['posts'].block.should eq block
85
+ expect(parent['posts'].block).to eq block
86
86
  end
87
87
 
88
88
  it "the block should be overrideable" do
@@ -90,8 +90,8 @@ describe RestClient::Resource do
90
90
  block2 = proc {|r| }
91
91
  parent = RestClient::Resource.new('http://example.com', &block1)
92
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
93
+ expect(parent.send(:[], 'posts', &block2).block).to eq block2
94
+ expect(parent.send(:[], 'posts', &block2).block).not_to eq block1
95
95
  end
96
96
 
97
97
  it "the block should be overrideable in ruby 1.9 syntax" do
@@ -99,31 +99,31 @@ describe RestClient::Resource do
99
99
  block2 = ->(r) {}
100
100
 
101
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
102
+ expect(parent['posts', &block2].block).to eq block2
103
+ expect(parent['posts', &block2].block).not_to eq block1
104
104
  end
105
105
 
106
106
  it "prints its url with to_s" do
107
- RestClient::Resource.new('x').to_s.should eq 'x'
107
+ expect(RestClient::Resource.new('x').to_s).to eq 'x'
108
108
  end
109
109
 
110
110
  describe 'block' do
111
111
  it 'can use block when creating the resource' do
112
112
  stub_request(:get, 'www.example.com').to_return(:body => '', :status => 404)
113
113
  resource = RestClient::Resource.new('www.example.com') { |response, request| 'foo' }
114
- resource.get.should eq 'foo'
114
+ expect(resource.get).to eq 'foo'
115
115
  end
116
116
 
117
117
  it 'can use block when executing the resource' do
118
118
  stub_request(:get, 'www.example.com').to_return(:body => '', :status => 404)
119
119
  resource = RestClient::Resource.new('www.example.com')
120
- resource.get { |response, request| 'foo' }.should eq 'foo'
120
+ expect(resource.get { |response, request| 'foo' }).to eq 'foo'
121
121
  end
122
122
 
123
123
  it 'execution block override resource block' do
124
124
  stub_request(:get, 'www.example.com').to_return(:body => '', :status => 404)
125
125
  resource = RestClient::Resource.new('www.example.com') { |response, request| 'foo' }
126
- resource.get { |response, request| 'bar' }.should eq 'bar'
126
+ expect(resource.get { |response, request| 'bar' }).to eq 'bar'
127
127
  end
128
128
 
129
129
  end
@@ -4,36 +4,36 @@ 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, :redirection_history => nil)
8
- @response = RestClient::Response.create('abc', @net_http_res, {}, @request)
7
+ @request = request_double(url: @example_url, method: 'get')
8
+ @response = RestClient::Response.create('abc', @net_http_res, @request)
9
9
  end
10
10
 
11
11
  it "behaves like string" do
12
- @response.to_s.should eq 'abc'
13
- @response.to_str.should eq 'abc'
12
+ expect(@response.to_s).to eq 'abc'
13
+ expect(@response.to_str).to eq 'abc'
14
14
 
15
- @response.should_receive(:warn)
16
- @response.to_i.should eq 0
15
+ expect(@response).to receive(:warn)
16
+ expect(@response.to_i).to eq 0
17
17
  end
18
18
 
19
19
  it "accepts nil strings and sets it to empty for the case of HEAD" do
20
- RestClient::Response.create(nil, @net_http_res, {}, @request).to_s.should eq ""
20
+ expect(RestClient::Response.create(nil, @net_http_res, @request).to_s).to eq ""
21
21
  end
22
22
 
23
23
  describe 'header processing' do
24
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"
25
+ expect(@response.raw_headers["Status"][0]).to eq "200 OK"
26
+ expect(@response.headers[:status]).to eq "200 OK"
27
27
  end
28
28
 
29
29
  it 'handles multiple headers by joining with comma' do
30
30
  @net_http_res = double('net http response', :to_hash => {'My-Header' => ['foo', 'bar']}, :code => 200)
31
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)
32
+ @request = request_double(url: @example_url, method: 'get')
33
+ @response = RestClient::Response.create('abc', @net_http_res, @request)
34
34
 
35
- @response.raw_headers['My-Header'].should eq ['foo', 'bar']
36
- @response.headers[:my_header].should eq 'foo, bar'
35
+ expect(@response.raw_headers['My-Header']).to eq ['foo', 'bar']
36
+ expect(@response.headers[:my_header]).to eq 'foo, bar'
37
37
  end
38
38
  end
39
39
 
@@ -42,16 +42,16 @@ describe RestClient::Response, :include_helpers do
42
42
  header_val = "main_page=main_page_no_rewrite; path=/; expires=Sat, 10-Jan-2037 15:03:14 GMT".freeze
43
43
 
44
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
- response.headers[:set_cookie].should eq [header_val]
47
- response.cookies.should eq({ "main_page" => "main_page_no_rewrite" })
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
48
  end
49
49
 
50
50
  it "should correctly deal with multiple cookies [multiple Set-Cookie headers]" do
51
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
- 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"]
54
- response.cookies.should eq({
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
55
  "main_page" => "main_page_no_rewrite",
56
56
  "remember_me" => "",
57
57
  "user" => "somebody"
@@ -60,8 +60,8 @@ describe RestClient::Response, :include_helpers do
60
60
 
61
61
  it "should correctly deal with multiple cookies [one Set-Cookie header with multiple cookies]" do
62
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
- response.cookies.should eq({
63
+ response = RestClient::Response.create('abc', net_http_res, @request)
64
+ expect(response.cookies).to eq({
65
65
  "main_page" => "main_page_no_rewrite",
66
66
  "remember_me" => "",
67
67
  "user" => "somebody"
@@ -73,17 +73,18 @@ describe RestClient::Response, :include_helpers do
73
73
  it "should return itself for normal codes" do
74
74
  (200..206).each do |code|
75
75
  net_http_res = response_double(:code => '200')
76
- resp = RestClient::Response.create('abc', net_http_res, {}, @request)
76
+ resp = RestClient::Response.create('abc', net_http_res, @request)
77
77
  resp.return!
78
78
  end
79
79
  end
80
80
 
81
81
  it "should throw an exception for other codes" do
82
- RestClient::Exceptions::EXCEPTIONS_MAP.each_key do |code|
82
+ RestClient::Exceptions::EXCEPTIONS_MAP.each_pair do |code, exc|
83
83
  unless (200..207).include? code
84
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
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)
87
88
  end
88
89
  end
89
90
  end
@@ -95,124 +96,145 @@ describe RestClient::Response, :include_helpers do
95
96
  it "follows a redirection when the request is a get" do
96
97
  stub_request(:get, 'http://some/resource').to_return(:body => '', :status => 301, :headers => {'Location' => 'http://new/resource'})
97
98
  stub_request(:get, 'http://new/resource').to_return(:body => 'Foo')
98
- RestClient::Request.execute(:url => 'http://some/resource', :method => :get).body.should eq 'Foo'
99
+ expect(RestClient::Request.execute(:url => 'http://some/resource', :method => :get).body).to eq 'Foo'
99
100
  end
100
101
 
101
102
  it "keeps redirection history" do
102
103
  stub_request(:get, 'http://some/resource').to_return(:body => '', :status => 301, :headers => {'Location' => 'http://new/resource'})
103
104
  stub_request(:get, 'http://new/resource').to_return(:body => 'Foo')
104
105
  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
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
109
110
  end
110
111
 
111
112
  it "follows a redirection and keep the parameters" do
112
- stub_request(:get, 'http://foo:bar@some/resource').with(:headers => {'Accept' => 'application/json'}).to_return(:body => '', :status => 301, :headers => {'Location' => 'http://new/resource'})
113
- stub_request(:get, 'http://foo:bar@new/resource').with(:headers => {'Accept' => 'application/json'}).to_return(:body => 'Foo')
114
- RestClient::Request.execute(:url => 'http://some/resource', :method => :get, :user => 'foo', :password => 'bar', :headers => {:accept => :json}).body.should eq 'Foo'
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'
115
116
  end
116
117
 
117
118
  it "follows a redirection and keep the cookies" do
118
119
  stub_request(:get, 'http://some/resource').to_return(:body => '', :status => 301, :headers => {'Set-Cookie' => 'Foo=Bar', 'Location' => 'http://some/new_resource', })
119
120
  stub_request(:get, 'http://some/new_resource').with(:headers => {'Cookie' => 'Foo=Bar'}).to_return(:body => 'Qux')
120
- RestClient::Request.execute(:url => 'http://some/resource', :method => :get).body.should eq 'Qux'
121
+ expect(RestClient::Request.execute(:url => 'http://some/resource', :method => :get).body).to eq 'Qux'
121
122
  end
122
123
 
123
- it 'does not keep cookies across domains' do
124
- stub_request(:get, 'http://some/resource').to_return(:body => '', :status => 301, :headers => {'Set-Cookie' => 'Foo=Bar', 'Location' => 'http://new/resource', })
125
- stub_request(:get, 'http://new/resource').with(:headers => {'Cookie' => ''}).to_return(:body => 'Qux')
126
- RestClient::Request.execute(:url => 'http://some/resource', :method => :get).body.should eq 'Qux'
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'
127
131
  end
128
132
 
129
133
  it "doesn't follow a 301 when the request is a post" do
130
134
  net_http_res = response_double(:code => 301)
135
+
131
136
  response = RestClient::Response.create('abc', net_http_res,
132
- {:method => :post}, @request)
133
- lambda {
137
+ request_double(method: 'post'))
138
+ expect {
134
139
  response.return!
135
- }.should raise_error(RestClient::MovedPermanently)
140
+ }.to raise_error(RestClient::MovedPermanently)
136
141
  end
137
142
 
138
143
  it "doesn't follow a 302 when the request is a post" do
139
144
  net_http_res = response_double(:code => 302)
140
145
  response = RestClient::Response.create('abc', net_http_res,
141
- {:method => :post}, @request)
142
- lambda {
146
+ request_double(method: 'post'))
147
+ expect {
143
148
  response.return!
144
- }.should raise_error(RestClient::Found)
149
+ }.to raise_error(RestClient::Found)
145
150
  end
146
151
 
147
152
  it "doesn't follow a 307 when the request is a post" do
148
153
  net_http_res = response_double(:code => 307)
149
154
  response = RestClient::Response.create('abc', net_http_res,
150
- {:method => :post}, @request)
151
- lambda {
155
+ request_double(method: 'post'))
156
+ expect(response).not_to receive(:follow_redirection)
157
+ expect {
152
158
  response.return!
153
- }.should raise_error(RestClient::TemporaryRedirect)
159
+ }.to raise_error(RestClient::TemporaryRedirect)
154
160
  end
155
161
 
156
162
  it "doesn't follow a redirection when the request is a put" do
157
163
  net_http_res = response_double(:code => 301)
158
164
  response = RestClient::Response.create('abc', net_http_res,
159
- {:method => :put}, @request)
160
- lambda {
165
+ request_double(method: 'put'))
166
+ expect {
161
167
  response.return!
162
- }.should raise_error(RestClient::MovedPermanently)
168
+ }.to raise_error(RestClient::MovedPermanently)
163
169
  end
164
170
 
165
171
  it "follows a redirection when the request is a post and result is a 303" do
166
172
  stub_request(:put, 'http://some/resource').to_return(:body => '', :status => 303, :headers => {'Location' => 'http://new/resource'})
167
173
  stub_request(:get, 'http://new/resource').to_return(:body => 'Foo')
168
- RestClient::Request.execute(:url => 'http://some/resource', :method => :put).body.should eq 'Foo'
174
+ expect(RestClient::Request.execute(:url => 'http://some/resource', :method => :put).body).to eq 'Foo'
169
175
  end
170
176
 
171
177
  it "follows a redirection when the request is a head" do
172
178
  stub_request(:head, 'http://some/resource').to_return(:body => '', :status => 301, :headers => {'Location' => 'http://new/resource'})
173
179
  stub_request(:head, 'http://new/resource').to_return(:body => 'Foo')
174
- RestClient::Request.execute(:url => 'http://some/resource', :method => :head).body.should eq 'Foo'
180
+ expect(RestClient::Request.execute(:url => 'http://some/resource', :method => :head).body).to eq 'Foo'
175
181
  end
176
182
 
177
183
  it "handles redirects with relative paths" do
178
184
  stub_request(:get, 'http://some/resource').to_return(:body => '', :status => 301, :headers => {'Location' => 'index'})
179
185
  stub_request(:get, 'http://some/index').to_return(:body => 'Foo')
180
- RestClient::Request.execute(:url => 'http://some/resource', :method => :get).body.should eq 'Foo'
186
+ expect(RestClient::Request.execute(:url => 'http://some/resource', :method => :get).body).to eq 'Foo'
181
187
  end
182
188
 
183
189
  it "handles redirects with relative path and query string" do
184
190
  stub_request(:get, 'http://some/resource').to_return(:body => '', :status => 301, :headers => {'Location' => 'index?q=1'})
185
191
  stub_request(:get, 'http://some/index?q=1').to_return(:body => 'Foo')
186
- RestClient::Request.execute(:url => 'http://some/resource', :method => :get).body.should eq 'Foo'
192
+ expect(RestClient::Request.execute(:url => 'http://some/resource', :method => :get).body).to eq 'Foo'
187
193
  end
188
194
 
189
195
  it "follow a redirection when the request is a get and the response is in the 30x range" do
190
196
  stub_request(:get, 'http://some/resource').to_return(:body => '', :status => 301, :headers => {'Location' => 'http://new/resource'})
191
197
  stub_request(:get, 'http://new/resource').to_return(:body => 'Foo')
192
- RestClient::Request.execute(:url => 'http://some/resource', :method => :get).body.should eq 'Foo'
198
+ expect(RestClient::Request.execute(:url => 'http://some/resource', :method => :get).body).to eq 'Foo'
193
199
  end
194
200
 
195
201
  it "follows no more than 10 redirections before raising error" do
196
202
  stub_request(:get, 'http://some/redirect-1').to_return(:body => '', :status => 301, :headers => {'Location' => 'http://some/redirect-2'})
197
203
  stub_request(:get, 'http://some/redirect-2').to_return(:body => '', :status => 301, :headers => {'Location' => 'http://some/redirect-2'})
198
- lambda {
204
+ expect {
199
205
  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
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
203
209
  }
204
- WebMock.should have_requested(:get, 'http://some/redirect-2').times(10)
210
+ expect(WebMock).to have_requested(:get, 'http://some/redirect-2').times(10)
205
211
  end
206
212
 
207
213
  it "follows no more than max_redirects redirections, if specified" do
208
214
  stub_request(:get, 'http://some/redirect-1').to_return(:body => '', :status => 301, :headers => {'Location' => 'http://some/redirect-2'})
209
215
  stub_request(:get, 'http://some/redirect-2').to_return(:body => '', :status => 301, :headers => {'Location' => 'http://some/redirect-2'})
210
- lambda {
216
+ expect {
211
217
  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
218
+ }.to raise_error(RestClient::MovedPermanently) { |ex|
219
+ expect(ex.response.history.length).to eq 5
214
220
  }
215
- WebMock.should have_requested(:get, 'http://some/redirect-2').times(5)
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'
216
238
  end
217
239
  end
218
240
 
@@ -3,37 +3,37 @@ require_relative '_lib'
3
3
  describe RestClient do
4
4
  describe "API" do
5
5
  it "GET" do
6
- RestClient::Request.should_receive(:execute).with(:method => :get, :url => 'http://some/resource', :headers => {})
6
+ expect(RestClient::Request).to receive(:execute).with(:method => :get, :url => 'http://some/resource', :headers => {})
7
7
  RestClient.get('http://some/resource')
8
8
  end
9
9
 
10
10
  it "POST" do
11
- RestClient::Request.should_receive(:execute).with(:method => :post, :url => 'http://some/resource', :payload => 'payload', :headers => {})
11
+ expect(RestClient::Request).to receive(:execute).with(:method => :post, :url => 'http://some/resource', :payload => 'payload', :headers => {})
12
12
  RestClient.post('http://some/resource', 'payload')
13
13
  end
14
14
 
15
15
  it "PUT" do
16
- RestClient::Request.should_receive(:execute).with(:method => :put, :url => 'http://some/resource', :payload => 'payload', :headers => {})
16
+ expect(RestClient::Request).to receive(:execute).with(:method => :put, :url => 'http://some/resource', :payload => 'payload', :headers => {})
17
17
  RestClient.put('http://some/resource', 'payload')
18
18
  end
19
19
 
20
20
  it "PATCH" do
21
- RestClient::Request.should_receive(:execute).with(:method => :patch, :url => 'http://some/resource', :payload => 'payload', :headers => {})
21
+ expect(RestClient::Request).to receive(:execute).with(:method => :patch, :url => 'http://some/resource', :payload => 'payload', :headers => {})
22
22
  RestClient.patch('http://some/resource', 'payload')
23
23
  end
24
24
 
25
25
  it "DELETE" do
26
- RestClient::Request.should_receive(:execute).with(:method => :delete, :url => 'http://some/resource', :headers => {})
26
+ expect(RestClient::Request).to receive(:execute).with(:method => :delete, :url => 'http://some/resource', :headers => {})
27
27
  RestClient.delete('http://some/resource')
28
28
  end
29
29
 
30
30
  it "HEAD" do
31
- RestClient::Request.should_receive(:execute).with(:method => :head, :url => 'http://some/resource', :headers => {})
31
+ expect(RestClient::Request).to receive(:execute).with(:method => :head, :url => 'http://some/resource', :headers => {})
32
32
  RestClient.head('http://some/resource')
33
33
  end
34
34
 
35
35
  it "OPTIONS" do
36
- RestClient::Request.should_receive(:execute).with(:method => :options, :url => 'http://some/resource', :headers => {})
36
+ expect(RestClient::Request).to receive(:execute).with(:method => :options, :url => 'http://some/resource', :headers => {})
37
37
  RestClient.options('http://some/resource')
38
38
  end
39
39
  end
@@ -45,27 +45,27 @@ describe RestClient do
45
45
 
46
46
  it "uses << if the log is not a string" do
47
47
  log = RestClient.log = []
48
- log.should_receive(:<<).with('xyz')
48
+ expect(log).to receive(:<<).with('xyz')
49
49
  RestClient.log << 'xyz'
50
50
  end
51
51
 
52
52
  it "displays the log to stdout" do
53
53
  RestClient.log = 'stdout'
54
- STDOUT.should_receive(:puts).with('xyz')
54
+ expect(STDOUT).to receive(:puts).with('xyz')
55
55
  RestClient.log << 'xyz'
56
56
  end
57
57
 
58
58
  it "displays the log to stderr" do
59
59
  RestClient.log = 'stderr'
60
- STDERR.should_receive(:puts).with('xyz')
60
+ expect(STDERR).to receive(:puts).with('xyz')
61
61
  RestClient.log << 'xyz'
62
62
  end
63
63
 
64
64
  it "append the log to the requested filename" do
65
65
  RestClient.log = '/tmp/restclient.log'
66
66
  f = double('file handle')
67
- File.should_receive(:open).with('/tmp/restclient.log', 'a').and_yield(f)
68
- f.should_receive(:puts).with('xyz')
67
+ expect(File).to receive(:open).with('/tmp/restclient.log', 'a').and_yield(f)
68
+ expect(f).to receive(:puts).with('xyz')
69
69
  RestClient.log << 'xyz'
70
70
  end
71
71
  end
@@ -73,7 +73,7 @@ describe RestClient do
73
73
  describe 'version' do
74
74
  it 'has a version ~> 2.0.0.alpha' do
75
75
  ver = Gem::Version.new(RestClient.version)
76
- Gem::Requirement.new('~> 2.0.0.alpha').should be_satisfied_by(ver)
76
+ expect(Gem::Requirement.new('~> 2.0.0.alpha')).to be_satisfied_by(ver)
77
77
  end
78
78
  end
79
79
  end