mirror of
https://github.com/rest-client/rest-client.git
synced 2022-11-09 13:49:40 -05:00
Convert specs to RSpec 2.99.2 syntax with Transpec
This conversion is done by Transpec 3.2.2 with the following command: transpec * 317 conversions from: obj.should to: expect(obj).to * 160 conversions from: obj.stub(:message) to: allow(obj).to receive(:message) * 100 conversions from: obj.should_receive(:message) to: expect(obj).to receive(:message) * 30 conversions from: lambda { }.should to: expect { }.to * 22 conversions from: obj.should_not_receive(:message) to: expect(obj).not_to receive(:message) * 4 conversions from: obj.should_not to: expect(obj).not_to * 2 conversions from: == expected to: eq(expected) * 1 conversion from: expect(collection).to have_at_least(n).items to: expect(collection.size).to be >= n * 1 conversion from: obj.unstub(:message) to: allow(obj).to receive(:message).and_call_original For more details: https://github.com/yujinakayama/transpec#supported-conversions
This commit is contained in:
parent
718c5ffb4e
commit
4971d1a6e1
15 changed files with 694 additions and 694 deletions
|
@ -41,22 +41,22 @@ describe RestClient::Request do
|
|||
describe '.execute' do
|
||||
it 'sends a user agent' do
|
||||
data = execute_httpbin_json('user-agent', method: :get)
|
||||
data['user-agent'].should match(/rest-client/)
|
||||
expect(data['user-agent']).to match(/rest-client/)
|
||||
end
|
||||
|
||||
it 'receives cookies on 302' do
|
||||
expect {
|
||||
execute_httpbin('cookies/set?foo=bar', method: :get, max_redirects: 0)
|
||||
}.to raise_error(RestClient::Found) { |ex|
|
||||
ex.http_code.should eq 302
|
||||
ex.response.cookies['foo'].should eq 'bar'
|
||||
expect(ex.http_code).to eq 302
|
||||
expect(ex.response.cookies['foo']).to eq 'bar'
|
||||
}
|
||||
end
|
||||
|
||||
it 'passes along cookies through 302' do
|
||||
data = execute_httpbin_json('cookies/set?foo=bar', method: :get)
|
||||
data.should have_key('cookies')
|
||||
data['cookies']['foo'].should eq 'bar'
|
||||
expect(data).to have_key('cookies')
|
||||
expect(data['cookies']['foo']).to eq 'bar'
|
||||
end
|
||||
|
||||
it 'handles quote wrapped cookies' do
|
||||
|
@ -64,8 +64,8 @@ describe RestClient::Request do
|
|||
execute_httpbin('cookies/set?foo=' + CGI.escape('"bar:baz"'),
|
||||
method: :get, max_redirects: 0)
|
||||
}.to raise_error(RestClient::Found) { |ex|
|
||||
ex.http_code.should eq 302
|
||||
ex.response.cookies['foo'].should eq '"bar:baz"'
|
||||
expect(ex.http_code).to eq 302
|
||||
expect(ex.response.cookies['foo']).to eq '"bar:baz"'
|
||||
}
|
||||
end
|
||||
end
|
||||
|
|
|
@ -8,15 +8,15 @@ describe RestClient do
|
|||
body = 'abc'
|
||||
stub_request(:get, "www.example.com").to_return(:body => body, :status => 200)
|
||||
response = RestClient.get "www.example.com"
|
||||
response.code.should eq 200
|
||||
response.body.should eq body
|
||||
expect(response.code).to eq 200
|
||||
expect(response.body).to eq body
|
||||
end
|
||||
|
||||
it "a simple request with gzipped content" do
|
||||
stub_request(:get, "www.example.com").with(:headers => { 'Accept-Encoding' => 'gzip, deflate' }).to_return(:body => "\037\213\b\b\006'\252H\000\003t\000\313T\317UH\257\312,HM\341\002\000G\242(\r\v\000\000\000", :status => 200, :headers => { 'Content-Encoding' => 'gzip' } )
|
||||
response = RestClient.get "www.example.com"
|
||||
response.code.should eq 200
|
||||
response.body.should eq "i'm gziped\n"
|
||||
expect(response.code).to eq 200
|
||||
expect(response.body).to eq "i'm gziped\n"
|
||||
end
|
||||
|
||||
it "a 404" do
|
||||
|
@ -26,10 +26,10 @@ describe RestClient do
|
|||
RestClient.get "www.example.com"
|
||||
raise
|
||||
rescue RestClient::ResourceNotFound => e
|
||||
e.http_code.should eq 404
|
||||
e.response.code.should eq 404
|
||||
e.response.body.should eq body
|
||||
e.http_body.should eq body
|
||||
expect(e.http_code).to eq 404
|
||||
expect(e.response.code).to eq 404
|
||||
expect(e.response.body).to eq body
|
||||
expect(e.http_body).to eq body
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -41,8 +41,8 @@ describe RestClient do
|
|||
'Content-Type' => 'text/plain; charset=UTF-8'
|
||||
})
|
||||
response = RestClient.get "www.example.com"
|
||||
response.encoding.should eq Encoding::UTF_8
|
||||
response.valid_encoding?.should eq true
|
||||
expect(response.encoding).to eq Encoding::UTF_8
|
||||
expect(response.valid_encoding?).to eq true
|
||||
end
|
||||
|
||||
it 'handles windows-1252' do
|
||||
|
@ -52,9 +52,9 @@ describe RestClient do
|
|||
'Content-Type' => 'text/plain; charset=windows-1252'
|
||||
})
|
||||
response = RestClient.get "www.example.com"
|
||||
response.encoding.should eq Encoding::WINDOWS_1252
|
||||
response.encode('utf-8').should eq "ÿ"
|
||||
response.valid_encoding?.should eq true
|
||||
expect(response.encoding).to eq Encoding::WINDOWS_1252
|
||||
expect(response.encode('utf-8')).to eq "ÿ"
|
||||
expect(response.valid_encoding?).to eq true
|
||||
end
|
||||
|
||||
it 'handles binary' do
|
||||
|
@ -64,28 +64,28 @@ describe RestClient do
|
|||
'Content-Type' => 'application/octet-stream; charset=binary'
|
||||
})
|
||||
response = RestClient.get "www.example.com"
|
||||
response.encoding.should eq Encoding::BINARY
|
||||
lambda {
|
||||
expect(response.encoding).to eq Encoding::BINARY
|
||||
expect {
|
||||
response.encode('utf-8')
|
||||
}.should raise_error(Encoding::UndefinedConversionError)
|
||||
response.valid_encoding?.should eq true
|
||||
}.to raise_error(Encoding::UndefinedConversionError)
|
||||
expect(response.valid_encoding?).to eq true
|
||||
end
|
||||
|
||||
it 'handles euc-jp' do
|
||||
body = "\xA4\xA2\xA4\xA4\xA4\xA6\xA4\xA8\xA4\xAA".
|
||||
force_encoding(Encoding::BINARY)
|
||||
body_utf8 = 'あいうえお'
|
||||
body_utf8.encoding.should eq Encoding::UTF_8
|
||||
expect(body_utf8.encoding).to eq Encoding::UTF_8
|
||||
|
||||
stub_request(:get, 'www.example.com').to_return(
|
||||
:body => body, :status => 200, :headers => {
|
||||
'Content-Type' => 'text/plain; charset=EUC-JP'
|
||||
})
|
||||
response = RestClient.get 'www.example.com'
|
||||
response.encoding.should eq Encoding::EUC_JP
|
||||
response.valid_encoding?.should eq true
|
||||
response.length.should eq 5
|
||||
response.encode('utf-8').should eq body_utf8
|
||||
expect(response.encoding).to eq Encoding::EUC_JP
|
||||
expect(response.valid_encoding?).to eq true
|
||||
expect(response.length).to eq 5
|
||||
expect(response.encode('utf-8')).to eq body_utf8
|
||||
end
|
||||
|
||||
it 'defaults to Encoding.default_external' do
|
||||
|
@ -95,7 +95,7 @@ describe RestClient do
|
|||
})
|
||||
|
||||
response = RestClient.get 'www.example.com'
|
||||
response.encoding.should eq Encoding.default_external
|
||||
expect(response.encoding).to eq Encoding.default_external
|
||||
end
|
||||
|
||||
it 'handles invalid encoding' do
|
||||
|
@ -105,7 +105,7 @@ describe RestClient do
|
|||
})
|
||||
|
||||
response = RestClient.get 'www.example.com'
|
||||
response.encoding.should eq Encoding.default_external
|
||||
expect(response.encoding).to eq Encoding.default_external
|
||||
end
|
||||
|
||||
it 'leaves images as binary' do
|
||||
|
@ -117,7 +117,7 @@ describe RestClient do
|
|||
})
|
||||
|
||||
response = RestClient.get 'www.example.com'
|
||||
response.encoding.should eq Encoding::BINARY
|
||||
expect(response.encoding).to eq Encoding::BINARY
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -75,7 +75,7 @@ describe RestClient::Request do
|
|||
},
|
||||
)
|
||||
expect {request.execute }.to_not raise_error
|
||||
ran_callback.should eq(true)
|
||||
expect(ran_callback).to eq(true)
|
||||
end
|
||||
|
||||
it "fails verification when the callback returns false",
|
||||
|
|
|
@ -22,124 +22,124 @@ describe RestClient::AbstractResponse, :include_helpers do
|
|||
end
|
||||
|
||||
it "fetches the numeric response code" do
|
||||
@net_http_res.should_receive(:code).and_return('200')
|
||||
@response.code.should eq 200
|
||||
expect(@net_http_res).to receive(:code).and_return('200')
|
||||
expect(@response.code).to eq 200
|
||||
end
|
||||
|
||||
it "has a nice description" do
|
||||
@net_http_res.should_receive(:to_hash).and_return({'Content-Type' => ['application/pdf']})
|
||||
@net_http_res.should_receive(:code).and_return('200')
|
||||
@response.description.should eq "200 OK | application/pdf bytes\n"
|
||||
expect(@net_http_res).to receive(:to_hash).and_return({'Content-Type' => ['application/pdf']})
|
||||
expect(@net_http_res).to receive(:code).and_return('200')
|
||||
expect(@response.description).to eq "200 OK | application/pdf bytes\n"
|
||||
end
|
||||
|
||||
describe '.beautify_headers' do
|
||||
it "beautifies the headers by turning the keys to symbols" do
|
||||
h = RestClient::AbstractResponse.beautify_headers('content-type' => [ 'x' ])
|
||||
h.keys.first.should eq :content_type
|
||||
expect(h.keys.first).to eq :content_type
|
||||
end
|
||||
|
||||
it "beautifies the headers by turning the values to strings instead of one-element arrays" do
|
||||
h = RestClient::AbstractResponse.beautify_headers('x' => [ 'text/html' ] )
|
||||
h.values.first.should eq 'text/html'
|
||||
expect(h.values.first).to eq 'text/html'
|
||||
end
|
||||
|
||||
it 'joins multiple header values by comma' do
|
||||
RestClient::AbstractResponse.beautify_headers(
|
||||
expect(RestClient::AbstractResponse.beautify_headers(
|
||||
{'My-Header' => ['one', 'two']}
|
||||
).should eq({:my_header => 'one, two'})
|
||||
)).to eq({:my_header => 'one, two'})
|
||||
end
|
||||
|
||||
it 'leaves set-cookie headers as array' do
|
||||
RestClient::AbstractResponse.beautify_headers(
|
||||
expect(RestClient::AbstractResponse.beautify_headers(
|
||||
{'Set-Cookie' => ['cookie1=foo', 'cookie2=bar']}
|
||||
).should eq({:set_cookie => ['cookie1=foo', 'cookie2=bar']})
|
||||
)).to eq({:set_cookie => ['cookie1=foo', 'cookie2=bar']})
|
||||
end
|
||||
end
|
||||
|
||||
it "fetches the headers" do
|
||||
@net_http_res.should_receive(:to_hash).and_return('content-type' => [ 'text/html' ])
|
||||
@response.headers.should eq({ :content_type => 'text/html' })
|
||||
expect(@net_http_res).to receive(:to_hash).and_return('content-type' => [ 'text/html' ])
|
||||
expect(@response.headers).to eq({ :content_type => 'text/html' })
|
||||
end
|
||||
|
||||
it "extracts cookies from response headers" do
|
||||
@net_http_res.should_receive(:to_hash).and_return('set-cookie' => ['session_id=1; path=/'])
|
||||
@response.cookies.should eq({ 'session_id' => '1' })
|
||||
expect(@net_http_res).to receive(:to_hash).and_return('set-cookie' => ['session_id=1; path=/'])
|
||||
expect(@response.cookies).to eq({ 'session_id' => '1' })
|
||||
end
|
||||
|
||||
it "extract strange cookies" do
|
||||
@net_http_res.should_receive(:to_hash).and_return('set-cookie' => ['session_id=ZJ/HQVH6YE+rVkTpn0zvTQ==; path=/'])
|
||||
@response.headers.should eq({:set_cookie => ['session_id=ZJ/HQVH6YE+rVkTpn0zvTQ==; path=/']})
|
||||
@response.cookies.should eq({ 'session_id' => 'ZJ/HQVH6YE+rVkTpn0zvTQ==' })
|
||||
expect(@net_http_res).to receive(:to_hash).and_return('set-cookie' => ['session_id=ZJ/HQVH6YE+rVkTpn0zvTQ==; path=/'])
|
||||
expect(@response.headers).to eq({:set_cookie => ['session_id=ZJ/HQVH6YE+rVkTpn0zvTQ==; path=/']})
|
||||
expect(@response.cookies).to eq({ 'session_id' => 'ZJ/HQVH6YE+rVkTpn0zvTQ==' })
|
||||
end
|
||||
|
||||
it "doesn't escape cookies" do
|
||||
@net_http_res.should_receive(:to_hash).and_return('set-cookie' => ['session_id=BAh7BzoNYXBwX25hbWUiEGFwcGxpY2F0aW9uOgpsb2dpbiIKYWRtaW4%3D%0A--08114ba654f17c04d20dcc5228ec672508f738ca; path=/'])
|
||||
@response.cookies.should eq({ 'session_id' => 'BAh7BzoNYXBwX25hbWUiEGFwcGxpY2F0aW9uOgpsb2dpbiIKYWRtaW4%3D%0A--08114ba654f17c04d20dcc5228ec672508f738ca' })
|
||||
expect(@net_http_res).to receive(:to_hash).and_return('set-cookie' => ['session_id=BAh7BzoNYXBwX25hbWUiEGFwcGxpY2F0aW9uOgpsb2dpbiIKYWRtaW4%3D%0A--08114ba654f17c04d20dcc5228ec672508f738ca; path=/'])
|
||||
expect(@response.cookies).to eq({ 'session_id' => 'BAh7BzoNYXBwX25hbWUiEGFwcGxpY2F0aW9uOgpsb2dpbiIKYWRtaW4%3D%0A--08114ba654f17c04d20dcc5228ec672508f738ca' })
|
||||
end
|
||||
|
||||
describe '.cookie_jar' do
|
||||
it 'extracts cookies into cookie jar' do
|
||||
@net_http_res.should_receive(:to_hash).and_return('set-cookie' => ['session_id=1; path=/'])
|
||||
@response.cookie_jar.should be_a HTTP::CookieJar
|
||||
expect(@net_http_res).to receive(:to_hash).and_return('set-cookie' => ['session_id=1; path=/'])
|
||||
expect(@response.cookie_jar).to be_a HTTP::CookieJar
|
||||
|
||||
cookie = @response.cookie_jar.cookies.first
|
||||
cookie.domain.should eq 'example.com'
|
||||
cookie.name.should eq 'session_id'
|
||||
cookie.value.should eq '1'
|
||||
cookie.path.should eq '/'
|
||||
expect(cookie.domain).to eq 'example.com'
|
||||
expect(cookie.name).to eq 'session_id'
|
||||
expect(cookie.value).to eq '1'
|
||||
expect(cookie.path).to eq '/'
|
||||
end
|
||||
|
||||
it 'handles cookies when URI scheme is implicit' do
|
||||
net_http_res = double('net http response')
|
||||
net_http_res.should_receive(:to_hash).and_return('set-cookie' => ['session_id=1; path=/'])
|
||||
expect(net_http_res).to receive(:to_hash).and_return('set-cookie' => ['session_id=1; path=/'])
|
||||
request = double(url: 'example.com', uri: URI.parse('http://example.com'),
|
||||
method: 'get', cookie_jar: HTTP::CookieJar.new)
|
||||
response = MyAbstractResponse.new(net_http_res, request)
|
||||
response.cookie_jar.should be_a HTTP::CookieJar
|
||||
expect(response.cookie_jar).to be_a HTTP::CookieJar
|
||||
|
||||
cookie = response.cookie_jar.cookies.first
|
||||
cookie.domain.should eq 'example.com'
|
||||
cookie.name.should eq 'session_id'
|
||||
cookie.value.should eq '1'
|
||||
cookie.path.should eq '/'
|
||||
expect(cookie.domain).to eq 'example.com'
|
||||
expect(cookie.name).to eq 'session_id'
|
||||
expect(cookie.value).to eq '1'
|
||||
expect(cookie.path).to eq '/'
|
||||
end
|
||||
end
|
||||
|
||||
it "can access the net http result directly" do
|
||||
@response.net_http_res.should eq @net_http_res
|
||||
expect(@response.net_http_res).to eq @net_http_res
|
||||
end
|
||||
|
||||
describe "#return!" do
|
||||
it "should return the response itself on 200-codes" do
|
||||
@net_http_res.should_receive(:code).and_return('200')
|
||||
@response.return!.should be_equal(@response)
|
||||
expect(@net_http_res).to receive(:code).and_return('200')
|
||||
expect(@response.return!).to be_equal(@response)
|
||||
end
|
||||
|
||||
it "should raise RequestFailed on unknown codes" do
|
||||
@net_http_res.should_receive(:code).and_return('1000')
|
||||
lambda { @response.return! }.should raise_error RestClient::RequestFailed
|
||||
expect(@net_http_res).to receive(:code).and_return('1000')
|
||||
expect { @response.return! }.to raise_error RestClient::RequestFailed
|
||||
end
|
||||
|
||||
it "should raise an error on a redirection after non-GET/HEAD requests" do
|
||||
@net_http_res.should_receive(:code).and_return('301')
|
||||
@request.should_receive(:method).and_return('put')
|
||||
@response.should_not_receive(:follow_redirection)
|
||||
lambda { @response.return! }.should raise_error RestClient::RequestFailed
|
||||
expect(@net_http_res).to receive(:code).and_return('301')
|
||||
expect(@request).to receive(:method).and_return('put')
|
||||
expect(@response).not_to receive(:follow_redirection)
|
||||
expect { @response.return! }.to raise_error RestClient::RequestFailed
|
||||
end
|
||||
|
||||
it "should follow 302 redirect" do
|
||||
@net_http_res.should_receive(:code).and_return('302')
|
||||
@response.should_receive(:check_max_redirects).and_return('fake-check')
|
||||
@response.should_receive(:follow_redirection).and_return('fake-redirection')
|
||||
@response.return!.should eq 'fake-redirection'
|
||||
expect(@net_http_res).to receive(:code).and_return('302')
|
||||
expect(@response).to receive(:check_max_redirects).and_return('fake-check')
|
||||
expect(@response).to receive(:follow_redirection).and_return('fake-redirection')
|
||||
expect(@response.return!).to eq 'fake-redirection'
|
||||
end
|
||||
|
||||
it "should gracefully handle 302 redirect with no location header" do
|
||||
@net_http_res = response_double(code: 302, location: nil)
|
||||
@request = request_double()
|
||||
@response = MyAbstractResponse.new(@net_http_res, @request)
|
||||
@response.should_receive(:check_max_redirects).and_return('fake-check')
|
||||
lambda { @response.return! }.should raise_error RestClient::Found
|
||||
expect(@response).to receive(:check_max_redirects).and_return('fake-check')
|
||||
expect { @response.return! }.to raise_error RestClient::Found
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -3,30 +3,30 @@ require_relative '_lib'
|
|||
describe RestClient::Exception do
|
||||
it "returns a 'message' equal to the class name if the message is not set, because 'message' should not be nil" do
|
||||
e = RestClient::Exception.new
|
||||
e.message.should eq "RestClient::Exception"
|
||||
expect(e.message).to eq "RestClient::Exception"
|
||||
end
|
||||
|
||||
it "returns the 'message' that was set" do
|
||||
e = RestClient::Exception.new
|
||||
message = "An explicitly set message"
|
||||
e.message = message
|
||||
e.message.should eq message
|
||||
expect(e.message).to eq message
|
||||
end
|
||||
|
||||
it "sets the exception message to ErrorMessage" do
|
||||
RestClient::ResourceNotFound.new.message.should eq 'Not Found'
|
||||
expect(RestClient::ResourceNotFound.new.message).to eq 'Not Found'
|
||||
end
|
||||
|
||||
it "contains exceptions in RestClient" do
|
||||
RestClient::Unauthorized.new.should be_a_kind_of(RestClient::Exception)
|
||||
RestClient::ServerBrokeConnection.new.should be_a_kind_of(RestClient::Exception)
|
||||
expect(RestClient::Unauthorized.new).to be_a_kind_of(RestClient::Exception)
|
||||
expect(RestClient::ServerBrokeConnection.new).to be_a_kind_of(RestClient::Exception)
|
||||
end
|
||||
end
|
||||
|
||||
describe RestClient::ServerBrokeConnection do
|
||||
it "should have a default message of 'Server broke connection'" do
|
||||
e = RestClient::ServerBrokeConnection.new
|
||||
e.message.should eq 'Server broke connection'
|
||||
expect(e.message).to eq 'Server broke connection'
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -40,21 +40,21 @@ describe RestClient::RequestFailed do
|
|||
begin
|
||||
raise RestClient::RequestFailed, response
|
||||
rescue RestClient::RequestFailed => e
|
||||
e.response.should eq response
|
||||
expect(e.response).to eq response
|
||||
end
|
||||
end
|
||||
|
||||
it "http_code convenience method for fetching the code as an integer" do
|
||||
RestClient::RequestFailed.new(@response).http_code.should eq 502
|
||||
expect(RestClient::RequestFailed.new(@response).http_code).to eq 502
|
||||
end
|
||||
|
||||
it "http_body convenience method for fetching the body (decoding when necessary)" do
|
||||
RestClient::RequestFailed.new(@response).http_code.should eq 502
|
||||
RestClient::RequestFailed.new(@response).message.should eq 'HTTP status code 502'
|
||||
expect(RestClient::RequestFailed.new(@response).http_code).to eq 502
|
||||
expect(RestClient::RequestFailed.new(@response).message).to eq 'HTTP status code 502'
|
||||
end
|
||||
|
||||
it "shows the status code in the message" do
|
||||
RestClient::RequestFailed.new(@response).to_s.should match(/502/)
|
||||
expect(RestClient::RequestFailed.new(@response).to_s).to match(/502/)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -64,7 +64,7 @@ describe RestClient::ResourceNotFound do
|
|||
begin
|
||||
raise RestClient::ResourceNotFound, response
|
||||
rescue RestClient::ResourceNotFound => e
|
||||
e.response.should eq response
|
||||
expect(e.response).to eq response
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -75,34 +75,34 @@ describe RestClient::ResourceNotFound do
|
|||
RestClient.get "www.example.com"
|
||||
raise
|
||||
rescue RestClient::ResourceNotFound => e
|
||||
e.response.body.should eq body
|
||||
expect(e.response.body).to eq body
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "backwards compatibility" do
|
||||
it 'aliases RestClient::NotFound as ResourceNotFound' do
|
||||
RestClient::ResourceNotFound.should eq RestClient::NotFound
|
||||
expect(RestClient::ResourceNotFound).to eq RestClient::NotFound
|
||||
end
|
||||
|
||||
it 'aliases old names for HTTP 413, 414, 416' do
|
||||
RestClient::RequestEntityTooLarge.should eq RestClient::PayloadTooLarge
|
||||
RestClient::RequestURITooLong.should eq RestClient::URITooLong
|
||||
RestClient::RequestedRangeNotSatisfiable.should eq RestClient::RangeNotSatisfiable
|
||||
expect(RestClient::RequestEntityTooLarge).to eq RestClient::PayloadTooLarge
|
||||
expect(RestClient::RequestURITooLong).to eq RestClient::URITooLong
|
||||
expect(RestClient::RequestedRangeNotSatisfiable).to eq RestClient::RangeNotSatisfiable
|
||||
end
|
||||
|
||||
it 'subclasses NotFound from RequestFailed, ExceptionWithResponse' do
|
||||
RestClient::NotFound.should be < RestClient::RequestFailed
|
||||
RestClient::NotFound.should be < RestClient::ExceptionWithResponse
|
||||
expect(RestClient::NotFound).to be < RestClient::RequestFailed
|
||||
expect(RestClient::NotFound).to be < RestClient::ExceptionWithResponse
|
||||
end
|
||||
|
||||
it 'subclasses timeout from RestClient::RequestTimeout, RequestFailed, EWR' do
|
||||
RestClient::Exceptions::OpenTimeout.should be < RestClient::Exceptions::Timeout
|
||||
RestClient::Exceptions::ReadTimeout.should be < RestClient::Exceptions::Timeout
|
||||
expect(RestClient::Exceptions::OpenTimeout).to be < RestClient::Exceptions::Timeout
|
||||
expect(RestClient::Exceptions::ReadTimeout).to be < RestClient::Exceptions::Timeout
|
||||
|
||||
RestClient::Exceptions::Timeout.should be < RestClient::RequestTimeout
|
||||
RestClient::Exceptions::Timeout.should be < RestClient::RequestFailed
|
||||
RestClient::Exceptions::Timeout.should be < RestClient::ExceptionWithResponse
|
||||
expect(RestClient::Exceptions::Timeout).to be < RestClient::RequestTimeout
|
||||
expect(RestClient::Exceptions::Timeout).to be < RestClient::RequestFailed
|
||||
expect(RestClient::Exceptions::Timeout).to be < RestClient::ExceptionWithResponse
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -12,11 +12,11 @@ describe RestClient::ParamsArray do
|
|||
[{foo: 123}, [:foo, 456], {bar: 789}, {empty: nil}],
|
||||
[{foo: 123}, [:foo, 456], {bar: 789}, [:empty]],
|
||||
].each do |input|
|
||||
RestClient::ParamsArray.new(input).to_a.should eq as_array
|
||||
expect(RestClient::ParamsArray.new(input).to_a).to eq as_array
|
||||
end
|
||||
|
||||
RestClient::ParamsArray.new([]).to_a.should eq []
|
||||
RestClient::ParamsArray.new([]).empty?.should eq true
|
||||
expect(RestClient::ParamsArray.new([]).to_a).to eq []
|
||||
expect(RestClient::ParamsArray.new([]).empty?).to eq true
|
||||
end
|
||||
|
||||
it 'rejects various invalid input' do
|
||||
|
|
|
@ -6,63 +6,63 @@ describe RestClient::Payload do
|
|||
context "Base Payload" do
|
||||
it "should reset stream after to_s" do
|
||||
payload = RestClient::Payload::Base.new('foobar')
|
||||
payload.to_s.should eq 'foobar'
|
||||
payload.to_s.should eq 'foobar'
|
||||
expect(payload.to_s).to eq 'foobar'
|
||||
expect(payload.to_s).to eq 'foobar'
|
||||
end
|
||||
end
|
||||
|
||||
context "A regular Payload" do
|
||||
it "should use standard enctype as default content-type" do
|
||||
RestClient::Payload::UrlEncoded.new({}).headers['Content-Type'].
|
||||
should eq 'application/x-www-form-urlencoded'
|
||||
expect(RestClient::Payload::UrlEncoded.new({}).headers['Content-Type']).
|
||||
to eq 'application/x-www-form-urlencoded'
|
||||
end
|
||||
|
||||
it "should form properly encoded params" do
|
||||
RestClient::Payload::UrlEncoded.new({:foo => 'bar'}).to_s.
|
||||
should eq "foo=bar"
|
||||
["foo=bar&baz=qux", "baz=qux&foo=bar"].should include(
|
||||
expect(RestClient::Payload::UrlEncoded.new({:foo => 'bar'}).to_s).
|
||||
to eq "foo=bar"
|
||||
expect(["foo=bar&baz=qux", "baz=qux&foo=bar"]).to include(
|
||||
RestClient::Payload::UrlEncoded.new({:foo => 'bar', :baz => 'qux'}).to_s)
|
||||
end
|
||||
|
||||
it "should escape parameters" do
|
||||
RestClient::Payload::UrlEncoded.new({'foo + bar' => 'baz'}).to_s.
|
||||
should eq "foo+%2B+bar=baz"
|
||||
expect(RestClient::Payload::UrlEncoded.new({'foo + bar' => 'baz'}).to_s).
|
||||
to eq "foo+%2B+bar=baz"
|
||||
end
|
||||
|
||||
it "should properly handle hashes as parameter" do
|
||||
RestClient::Payload::UrlEncoded.new({:foo => {:bar => 'baz'}}).to_s.
|
||||
should eq "foo[bar]=baz"
|
||||
RestClient::Payload::UrlEncoded.new({:foo => {:bar => {:baz => 'qux'}}}).to_s.
|
||||
should eq "foo[bar][baz]=qux"
|
||||
expect(RestClient::Payload::UrlEncoded.new({:foo => {:bar => 'baz'}}).to_s).
|
||||
to eq "foo[bar]=baz"
|
||||
expect(RestClient::Payload::UrlEncoded.new({:foo => {:bar => {:baz => 'qux'}}}).to_s).
|
||||
to eq "foo[bar][baz]=qux"
|
||||
end
|
||||
|
||||
it "should handle many attributes inside a hash" do
|
||||
parameters = RestClient::Payload::UrlEncoded.new({:foo => {:bar => 'baz', :baz => 'qux'}}).to_s
|
||||
parameters.should eq 'foo[bar]=baz&foo[baz]=qux'
|
||||
expect(parameters).to eq 'foo[bar]=baz&foo[baz]=qux'
|
||||
end
|
||||
|
||||
it "should handle attributes inside an array inside an hash" do
|
||||
parameters = RestClient::Payload::UrlEncoded.new({"foo" => [{"bar" => 'baz'}, {"bar" => 'qux'}]}).to_s
|
||||
parameters.should eq 'foo[][bar]=baz&foo[][bar]=qux'
|
||||
expect(parameters).to eq 'foo[][bar]=baz&foo[][bar]=qux'
|
||||
end
|
||||
|
||||
it "should handle arrays inside a hash inside a hash" do
|
||||
parameters = RestClient::Payload::UrlEncoded.new({"foo" => {'even' => [0, 2], 'odd' => [1, 3]}}).to_s
|
||||
parameters.should eq 'foo[even][]=0&foo[even][]=2&foo[odd][]=1&foo[odd][]=3'
|
||||
expect(parameters).to eq 'foo[even][]=0&foo[even][]=2&foo[odd][]=1&foo[odd][]=3'
|
||||
end
|
||||
|
||||
it "should form properly use symbols as parameters" do
|
||||
RestClient::Payload::UrlEncoded.new({:foo => :bar}).to_s.
|
||||
should eq "foo=bar"
|
||||
RestClient::Payload::UrlEncoded.new({:foo => {:bar => :baz}}).to_s.
|
||||
should eq "foo[bar]=baz"
|
||||
expect(RestClient::Payload::UrlEncoded.new({:foo => :bar}).to_s).
|
||||
to eq "foo=bar"
|
||||
expect(RestClient::Payload::UrlEncoded.new({:foo => {:bar => :baz}}).to_s).
|
||||
to eq "foo[bar]=baz"
|
||||
end
|
||||
|
||||
it "should properly handle arrays as repeated parameters" do
|
||||
RestClient::Payload::UrlEncoded.new({:foo => ['bar']}).to_s.
|
||||
should eq "foo[]=bar"
|
||||
RestClient::Payload::UrlEncoded.new({:foo => ['bar', 'baz']}).to_s.
|
||||
should eq "foo[]=bar&foo[]=baz"
|
||||
expect(RestClient::Payload::UrlEncoded.new({:foo => ['bar']}).to_s).
|
||||
to eq "foo[]=bar"
|
||||
expect(RestClient::Payload::UrlEncoded.new({:foo => ['bar', 'baz']}).to_s).
|
||||
to eq "foo[]=bar&foo[]=baz"
|
||||
end
|
||||
|
||||
it 'should not close if stream already closed' do
|
||||
|
@ -75,8 +75,8 @@ describe RestClient::Payload do
|
|||
context "A multipart Payload" do
|
||||
it "should use standard enctype as default content-type" do
|
||||
m = RestClient::Payload::Multipart.new({})
|
||||
m.stub(:boundary).and_return(123)
|
||||
m.headers['Content-Type'].should eq 'multipart/form-data; boundary=123'
|
||||
allow(m).to receive(:boundary).and_return(123)
|
||||
expect(m.headers['Content-Type']).to eq 'multipart/form-data; boundary=123'
|
||||
end
|
||||
|
||||
it 'should not error on close if stream already closed' do
|
||||
|
@ -86,7 +86,7 @@ describe RestClient::Payload do
|
|||
|
||||
it "should form properly separated multipart data" do
|
||||
m = RestClient::Payload::Multipart.new([[:bar, "baz"], [:foo, "bar"]])
|
||||
m.to_s.should eq <<-EOS
|
||||
expect(m.to_s).to eq <<-EOS
|
||||
--#{m.boundary}\r
|
||||
Content-Disposition: form-data; name="bar"\r
|
||||
\r
|
||||
|
@ -101,7 +101,7 @@ bar\r
|
|||
|
||||
it "should not escape parameters names" do
|
||||
m = RestClient::Payload::Multipart.new([["bar ", "baz"]])
|
||||
m.to_s.should eq <<-EOS
|
||||
expect(m.to_s).to eq <<-EOS
|
||||
--#{m.boundary}\r
|
||||
Content-Disposition: form-data; name="bar "\r
|
||||
\r
|
||||
|
@ -113,7 +113,7 @@ baz\r
|
|||
it "should form properly separated multipart data" do
|
||||
f = File.new(File.dirname(__FILE__) + "/master_shake.jpg")
|
||||
m = RestClient::Payload::Multipart.new({:foo => f})
|
||||
m.to_s.should eq <<-EOS
|
||||
expect(m.to_s).to eq <<-EOS
|
||||
--#{m.boundary}\r
|
||||
Content-Disposition: form-data; name="foo"; filename="master_shake.jpg"\r
|
||||
Content-Type: image/jpeg\r
|
||||
|
@ -126,7 +126,7 @@ Content-Type: image/jpeg\r
|
|||
it "should ignore the name attribute when it's not set" do
|
||||
f = File.new(File.dirname(__FILE__) + "/master_shake.jpg")
|
||||
m = RestClient::Payload::Multipart.new({nil => f})
|
||||
m.to_s.should eq <<-EOS
|
||||
expect(m.to_s).to eq <<-EOS
|
||||
--#{m.boundary}\r
|
||||
Content-Disposition: form-data; filename="master_shake.jpg"\r
|
||||
Content-Type: image/jpeg\r
|
||||
|
@ -141,7 +141,7 @@ Content-Type: image/jpeg\r
|
|||
f.instance_eval "def content_type; 'text/plain'; end"
|
||||
f.instance_eval "def original_filename; 'foo.txt'; end"
|
||||
m = RestClient::Payload::Multipart.new({:foo => f})
|
||||
m.to_s.should eq <<-EOS
|
||||
expect(m.to_s).to eq <<-EOS
|
||||
--#{m.boundary}\r
|
||||
Content-Disposition: form-data; name="foo"; filename="foo.txt"\r
|
||||
Content-Type: text/plain\r
|
||||
|
@ -153,7 +153,7 @@ Content-Type: text/plain\r
|
|||
|
||||
it "should handle hash in hash parameters" do
|
||||
m = RestClient::Payload::Multipart.new({:bar => {:baz => "foo"}})
|
||||
m.to_s.should eq <<-EOS
|
||||
expect(m.to_s).to eq <<-EOS
|
||||
--#{m.boundary}\r
|
||||
Content-Disposition: form-data; name="bar[baz]"\r
|
||||
\r
|
||||
|
@ -165,7 +165,7 @@ foo\r
|
|||
f.instance_eval "def content_type; 'text/plain'; end"
|
||||
f.instance_eval "def original_filename; 'foo.txt'; end"
|
||||
m = RestClient::Payload::Multipart.new({:foo => {:bar => f}})
|
||||
m.to_s.should eq <<-EOS
|
||||
expect(m.to_s).to eq <<-EOS
|
||||
--#{m.boundary}\r
|
||||
Content-Disposition: form-data; name="foo[bar]"; filename="foo.txt"\r
|
||||
Content-Type: text/plain\r
|
||||
|
@ -176,10 +176,10 @@ Content-Type: text/plain\r
|
|||
end
|
||||
|
||||
it 'should correctly format hex boundary' do
|
||||
SecureRandom.stub(:base64).with(12).and_return('TGs89+ttw/xna6TV')
|
||||
allow(SecureRandom).to receive(:base64).with(12).and_return('TGs89+ttw/xna6TV')
|
||||
f = File.new(File.dirname(__FILE__) + '/master_shake.jpg')
|
||||
m = RestClient::Payload::Multipart.new({:foo => f})
|
||||
m.boundary.should eq('-' * 4 + 'RubyFormBoundary' + 'TGs89AttwBxna6TV')
|
||||
expect(m.boundary).to eq('-' * 4 + 'RubyFormBoundary' + 'TGs89AttwBxna6TV')
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -188,23 +188,23 @@ Content-Type: text/plain\r
|
|||
it "should properly determine the size of file payloads" do
|
||||
f = File.new(File.dirname(__FILE__) + "/master_shake.jpg")
|
||||
payload = RestClient::Payload.generate(f)
|
||||
payload.size.should eq 76_988
|
||||
payload.length.should eq 76_988
|
||||
expect(payload.size).to eq 76_988
|
||||
expect(payload.length).to eq 76_988
|
||||
end
|
||||
|
||||
it "should properly determine the size of other kinds of streaming payloads" do
|
||||
s = StringIO.new 'foo'
|
||||
payload = RestClient::Payload.generate(s)
|
||||
payload.size.should eq 3
|
||||
payload.length.should eq 3
|
||||
expect(payload.size).to eq 3
|
||||
expect(payload.length).to eq 3
|
||||
|
||||
begin
|
||||
f = Tempfile.new "rest-client"
|
||||
f.write 'foo bar'
|
||||
|
||||
payload = RestClient::Payload.generate(f)
|
||||
payload.size.should eq 7
|
||||
payload.length.should eq 7
|
||||
expect(payload.size).to eq 7
|
||||
expect(payload.length).to eq 7
|
||||
ensure
|
||||
f.close
|
||||
end
|
||||
|
@ -213,51 +213,51 @@ Content-Type: text/plain\r
|
|||
|
||||
context "Payload generation" do
|
||||
it "should recognize standard urlencoded params" do
|
||||
RestClient::Payload.generate({"foo" => 'bar'}).should be_kind_of(RestClient::Payload::UrlEncoded)
|
||||
expect(RestClient::Payload.generate({"foo" => 'bar'})).to be_kind_of(RestClient::Payload::UrlEncoded)
|
||||
end
|
||||
|
||||
it "should recognize multipart params" do
|
||||
f = File.new(File.dirname(__FILE__) + "/master_shake.jpg")
|
||||
RestClient::Payload.generate({"foo" => f}).should be_kind_of(RestClient::Payload::Multipart)
|
||||
expect(RestClient::Payload.generate({"foo" => f})).to be_kind_of(RestClient::Payload::Multipart)
|
||||
end
|
||||
|
||||
it "should be multipart if forced" do
|
||||
RestClient::Payload.generate({"foo" => "bar", :multipart => true}).should be_kind_of(RestClient::Payload::Multipart)
|
||||
expect(RestClient::Payload.generate({"foo" => "bar", :multipart => true})).to be_kind_of(RestClient::Payload::Multipart)
|
||||
end
|
||||
|
||||
it "should handle deeply nested multipart" do
|
||||
f = File.new(File.dirname(__FILE__) + "/master_shake.jpg")
|
||||
params = {foo: RestClient::ParamsArray.new({nested: f})}
|
||||
RestClient::Payload.generate(params).should be_kind_of(RestClient::Payload::Multipart)
|
||||
expect(RestClient::Payload.generate(params)).to be_kind_of(RestClient::Payload::Multipart)
|
||||
end
|
||||
|
||||
|
||||
it "should return data if no of the above" do
|
||||
RestClient::Payload.generate("data").should be_kind_of(RestClient::Payload::Base)
|
||||
expect(RestClient::Payload.generate("data")).to be_kind_of(RestClient::Payload::Base)
|
||||
end
|
||||
|
||||
it "should recognize nested multipart payloads in hashes" do
|
||||
f = File.new(File.dirname(__FILE__) + "/master_shake.jpg")
|
||||
RestClient::Payload.generate({"foo" => {"file" => f}}).should be_kind_of(RestClient::Payload::Multipart)
|
||||
expect(RestClient::Payload.generate({"foo" => {"file" => f}})).to be_kind_of(RestClient::Payload::Multipart)
|
||||
end
|
||||
|
||||
it "should recognize nested multipart payloads in arrays" do
|
||||
f = File.new(File.dirname(__FILE__) + "/master_shake.jpg")
|
||||
RestClient::Payload.generate({"foo" => [f]}).should be_kind_of(RestClient::Payload::Multipart)
|
||||
expect(RestClient::Payload.generate({"foo" => [f]})).to be_kind_of(RestClient::Payload::Multipart)
|
||||
end
|
||||
|
||||
it "should recognize file payloads that can be streamed" do
|
||||
f = File.new(File.dirname(__FILE__) + "/master_shake.jpg")
|
||||
RestClient::Payload.generate(f).should be_kind_of(RestClient::Payload::Streamed)
|
||||
expect(RestClient::Payload.generate(f)).to be_kind_of(RestClient::Payload::Streamed)
|
||||
end
|
||||
|
||||
it "should recognize other payloads that can be streamed" do
|
||||
RestClient::Payload.generate(StringIO.new('foo')).should be_kind_of(RestClient::Payload::Streamed)
|
||||
expect(RestClient::Payload.generate(StringIO.new('foo'))).to be_kind_of(RestClient::Payload::Streamed)
|
||||
end
|
||||
|
||||
# hashery gem introduces Hash#read convenience method. Existence of #read method used to determine of content is streameable :/
|
||||
it "shouldn't treat hashes as streameable" do
|
||||
RestClient::Payload.generate({"foo" => 'bar'}).should be_kind_of(RestClient::Payload::UrlEncoded)
|
||||
expect(RestClient::Payload.generate({"foo" => 'bar'})).to be_kind_of(RestClient::Payload::UrlEncoded)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -9,10 +9,10 @@ describe RestClient::RawResponse do
|
|||
end
|
||||
|
||||
it "behaves like string" do
|
||||
@response.to_s.should eq 'the answer is 42'
|
||||
expect(@response.to_s).to eq 'the answer is 42'
|
||||
end
|
||||
|
||||
it "exposes a Tempfile" do
|
||||
@response.file.should eq @tf
|
||||
expect(@response.file).to eq @tf
|
||||
end
|
||||
end
|
||||
|
|
|
@ -5,20 +5,20 @@ describe RestClient::Request do
|
|||
context 'params for GET requests' do
|
||||
it "manage params for get requests" do
|
||||
stub_request(:get, 'http://some/resource?a=b&c=d').with(:headers => {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip, deflate', 'Foo'=>'bar'}).to_return(:body => 'foo', :status => 200)
|
||||
RestClient::Request.execute(:url => 'http://some/resource', :method => :get, :headers => {:foo => :bar, :params => {:a => :b, 'c' => 'd'}}).body.should eq 'foo'
|
||||
expect(RestClient::Request.execute(:url => 'http://some/resource', :method => :get, :headers => {:foo => :bar, :params => {:a => :b, 'c' => 'd'}}).body).to eq 'foo'
|
||||
|
||||
stub_request(:get, 'http://some/resource').with(:headers => {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip, deflate', 'Foo'=>'bar'}).to_return(:body => 'foo', :status => 200)
|
||||
RestClient::Request.execute(:url => 'http://some/resource', :method => :get, :headers => {:foo => :bar, :params => :a}).body.should eq 'foo'
|
||||
expect(RestClient::Request.execute(:url => 'http://some/resource', :method => :get, :headers => {:foo => :bar, :params => :a}).body).to eq 'foo'
|
||||
end
|
||||
|
||||
it 'adds GET params when params are present in URL' do
|
||||
stub_request(:get, 'http://some/resource?a=b&c=d').with(:headers => {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip, deflate', 'Foo'=>'bar'}).to_return(:body => 'foo', :status => 200)
|
||||
RestClient::Request.execute(:url => 'http://some/resource?a=b', :method => :get, :headers => {:foo => :bar, :params => {:c => 'd'}}).body.should eq 'foo'
|
||||
expect(RestClient::Request.execute(:url => 'http://some/resource?a=b', :method => :get, :headers => {:foo => :bar, :params => {:c => 'd'}}).body).to eq 'foo'
|
||||
end
|
||||
|
||||
it 'encodes nested GET params' do
|
||||
stub_request(:get, 'http://some/resource?a[foo][]=1&a[foo][]=2&a[bar]&b=foo+bar&math=2+%2B+2+%3D%3D+4').with(:headers => {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip, deflate'}).to_return(:body => 'foo', :status => 200)
|
||||
RestClient::Request.execute(url: 'http://some/resource', method: :get, headers: {
|
||||
expect(RestClient::Request.execute(url: 'http://some/resource', method: :get, headers: {
|
||||
params: {
|
||||
a: {
|
||||
foo: [1,2],
|
||||
|
@ -27,7 +27,7 @@ describe RestClient::Request do
|
|||
b: 'foo bar',
|
||||
math: '2 + 2 == 4',
|
||||
}
|
||||
}).body.should eq 'foo'
|
||||
}).body).to eq 'foo'
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -39,7 +39,7 @@ describe RestClient::Request do
|
|||
end
|
||||
stub_request(:get, 'http://some/resource?a=b&c=d').with(:headers => {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip, deflate', 'Foo'=>'bar'}).to_return(:body => 'foo', :status => 200)
|
||||
RestClient::Request.execute(:url => 'http://some/resource', :method => :get, :headers => {:foo => :bar, :params => {:a => :b, 'c' => 'd'}}, :block_response => block)
|
||||
response_value.should eq "foo"
|
||||
expect(response_value).to eq "foo"
|
||||
end
|
||||
|
||||
it 'closes payload if not nil' do
|
||||
|
@ -48,7 +48,7 @@ describe RestClient::Request do
|
|||
stub_request(:post, 'http://some/resource').with(:headers => {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip, deflate'}).to_return(:body => 'foo', :status => 200)
|
||||
RestClient::Request.execute(:url => 'http://some/resource', :method => :post, :payload => {:file => test_file})
|
||||
|
||||
test_file.closed?.should be true
|
||||
expect(test_file.closed?).to be true
|
||||
end
|
||||
|
||||
end
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -7,37 +7,37 @@ describe RestClient::Resource do
|
|||
|
||||
context "Resource delegation" do
|
||||
it "GET" do
|
||||
RestClient::Request.should_receive(:execute).with(:method => :get, :url => 'http://some/resource', :headers => {'X-Something' => '1'}, :user => 'jane', :password => 'mypass')
|
||||
expect(RestClient::Request).to receive(:execute).with(:method => :get, :url => 'http://some/resource', :headers => {'X-Something' => '1'}, :user => 'jane', :password => 'mypass')
|
||||
@resource.get
|
||||
end
|
||||
|
||||
it "HEAD" do
|
||||
RestClient::Request.should_receive(:execute).with(:method => :head, :url => 'http://some/resource', :headers => {'X-Something' => '1'}, :user => 'jane', :password => 'mypass')
|
||||
expect(RestClient::Request).to receive(:execute).with(:method => :head, :url => 'http://some/resource', :headers => {'X-Something' => '1'}, :user => 'jane', :password => 'mypass')
|
||||
@resource.head
|
||||
end
|
||||
|
||||
it "POST" do
|
||||
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')
|
||||
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')
|
||||
@resource.post 'abc', :content_type => 'image/jpg'
|
||||
end
|
||||
|
||||
it "PUT" do
|
||||
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')
|
||||
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')
|
||||
@resource.put 'abc', :content_type => 'image/jpg'
|
||||
end
|
||||
|
||||
it "PATCH" do
|
||||
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')
|
||||
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')
|
||||
@resource.patch 'abc', :content_type => 'image/jpg'
|
||||
end
|
||||
|
||||
it "DELETE" do
|
||||
RestClient::Request.should_receive(:execute).with(:method => :delete, :url => 'http://some/resource', :headers => {'X-Something' => '1'}, :user => 'jane', :password => 'mypass')
|
||||
expect(RestClient::Request).to receive(:execute).with(:method => :delete, :url => 'http://some/resource', :headers => {'X-Something' => '1'}, :user => 'jane', :password => 'mypass')
|
||||
@resource.delete
|
||||
end
|
||||
|
||||
it "overrides resource headers" do
|
||||
RestClient::Request.should_receive(:execute).with(:method => :get, :url => 'http://some/resource', :headers => {'X-Something' => '2'}, :user => 'jane', :password => 'mypass')
|
||||
expect(RestClient::Request).to receive(:execute).with(:method => :get, :url => 'http://some/resource', :headers => {'X-Something' => '2'}, :user => 'jane', :password => 'mypass')
|
||||
@resource.get 'X-Something' => '2'
|
||||
end
|
||||
end
|
||||
|
@ -48,41 +48,41 @@ describe RestClient::Resource do
|
|||
|
||||
it "is backwards compatible with previous constructor" do
|
||||
@resource = RestClient::Resource.new('http://some/resource', 'user', 'pass')
|
||||
@resource.user.should eq 'user'
|
||||
@resource.password.should eq 'pass'
|
||||
expect(@resource.user).to eq 'user'
|
||||
expect(@resource.password).to eq 'pass'
|
||||
end
|
||||
|
||||
it "concatenates urls, inserting a slash when it needs one" do
|
||||
@resource.concat_urls('http://example.com', 'resource').should eq 'http://example.com/resource'
|
||||
expect(@resource.concat_urls('http://example.com', 'resource')).to eq 'http://example.com/resource'
|
||||
end
|
||||
|
||||
it "concatenates urls, using no slash if the first url ends with a slash" do
|
||||
@resource.concat_urls('http://example.com/', 'resource').should eq 'http://example.com/resource'
|
||||
expect(@resource.concat_urls('http://example.com/', 'resource')).to eq 'http://example.com/resource'
|
||||
end
|
||||
|
||||
it "concatenates urls, using no slash if the second url starts with a slash" do
|
||||
@resource.concat_urls('http://example.com', '/resource').should eq 'http://example.com/resource'
|
||||
expect(@resource.concat_urls('http://example.com', '/resource')).to eq 'http://example.com/resource'
|
||||
end
|
||||
|
||||
it "concatenates even non-string urls, :posts + 1 => 'posts/1'" do
|
||||
@resource.concat_urls(:posts, 1).should eq 'posts/1'
|
||||
expect(@resource.concat_urls(:posts, 1)).to eq 'posts/1'
|
||||
end
|
||||
|
||||
it "offers subresources via []" do
|
||||
parent = RestClient::Resource.new('http://example.com')
|
||||
parent['posts'].url.should eq 'http://example.com/posts'
|
||||
expect(parent['posts'].url).to eq 'http://example.com/posts'
|
||||
end
|
||||
|
||||
it "transports options to subresources" do
|
||||
parent = RestClient::Resource.new('http://example.com', :user => 'user', :password => 'password')
|
||||
parent['posts'].user.should eq 'user'
|
||||
parent['posts'].password.should eq 'password'
|
||||
expect(parent['posts'].user).to eq 'user'
|
||||
expect(parent['posts'].password).to eq 'password'
|
||||
end
|
||||
|
||||
it "passes a given block to subresources" do
|
||||
block = proc {|r| r}
|
||||
parent = RestClient::Resource.new('http://example.com', &block)
|
||||
parent['posts'].block.should eq block
|
||||
expect(parent['posts'].block).to eq block
|
||||
end
|
||||
|
||||
it "the block should be overrideable" do
|
||||
|
@ -90,8 +90,8 @@ describe RestClient::Resource do
|
|||
block2 = proc {|r| }
|
||||
parent = RestClient::Resource.new('http://example.com', &block1)
|
||||
# parent['posts', &block2].block.should eq block2 # ruby 1.9 syntax
|
||||
parent.send(:[], 'posts', &block2).block.should eq block2
|
||||
parent.send(:[], 'posts', &block2).block.should_not eq block1
|
||||
expect(parent.send(:[], 'posts', &block2).block).to eq block2
|
||||
expect(parent.send(:[], 'posts', &block2).block).not_to eq block1
|
||||
end
|
||||
|
||||
it "the block should be overrideable in ruby 1.9 syntax" do
|
||||
|
@ -99,31 +99,31 @@ describe RestClient::Resource do
|
|||
block2 = ->(r) {}
|
||||
|
||||
parent = RestClient::Resource.new('http://example.com', &block1)
|
||||
parent['posts', &block2].block.should eq block2
|
||||
parent['posts', &block2].block.should_not eq block1
|
||||
expect(parent['posts', &block2].block).to eq block2
|
||||
expect(parent['posts', &block2].block).not_to eq block1
|
||||
end
|
||||
|
||||
it "prints its url with to_s" do
|
||||
RestClient::Resource.new('x').to_s.should eq 'x'
|
||||
expect(RestClient::Resource.new('x').to_s).to eq 'x'
|
||||
end
|
||||
|
||||
describe 'block' do
|
||||
it 'can use block when creating the resource' do
|
||||
stub_request(:get, 'www.example.com').to_return(:body => '', :status => 404)
|
||||
resource = RestClient::Resource.new('www.example.com') { |response, request| 'foo' }
|
||||
resource.get.should eq 'foo'
|
||||
expect(resource.get).to eq 'foo'
|
||||
end
|
||||
|
||||
it 'can use block when executing the resource' do
|
||||
stub_request(:get, 'www.example.com').to_return(:body => '', :status => 404)
|
||||
resource = RestClient::Resource.new('www.example.com')
|
||||
resource.get { |response, request| 'foo' }.should eq 'foo'
|
||||
expect(resource.get { |response, request| 'foo' }).to eq 'foo'
|
||||
end
|
||||
|
||||
it 'execution block override resource block' do
|
||||
stub_request(:get, 'www.example.com').to_return(:body => '', :status => 404)
|
||||
resource = RestClient::Resource.new('www.example.com') { |response, request| 'foo' }
|
||||
resource.get { |response, request| 'bar' }.should eq 'bar'
|
||||
expect(resource.get { |response, request| 'bar' }).to eq 'bar'
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -9,21 +9,21 @@ describe RestClient::Response, :include_helpers do
|
|||
end
|
||||
|
||||
it "behaves like string" do
|
||||
@response.to_s.should eq 'abc'
|
||||
@response.to_str.should eq 'abc'
|
||||
expect(@response.to_s).to eq 'abc'
|
||||
expect(@response.to_str).to eq 'abc'
|
||||
|
||||
@response.should_receive(:warn)
|
||||
@response.to_i.should eq 0
|
||||
expect(@response).to receive(:warn)
|
||||
expect(@response.to_i).to eq 0
|
||||
end
|
||||
|
||||
it "accepts nil strings and sets it to empty for the case of HEAD" do
|
||||
RestClient::Response.create(nil, @net_http_res, @request).to_s.should eq ""
|
||||
expect(RestClient::Response.create(nil, @net_http_res, @request).to_s).to eq ""
|
||||
end
|
||||
|
||||
describe 'header processing' do
|
||||
it "test headers and raw headers" do
|
||||
@response.raw_headers["Status"][0].should eq "200 OK"
|
||||
@response.headers[:status].should eq "200 OK"
|
||||
expect(@response.raw_headers["Status"][0]).to eq "200 OK"
|
||||
expect(@response.headers[:status]).to eq "200 OK"
|
||||
end
|
||||
|
||||
it 'handles multiple headers by joining with comma' do
|
||||
|
@ -32,8 +32,8 @@ describe RestClient::Response, :include_helpers do
|
|||
@request = request_double(url: @example_url, method: 'get')
|
||||
@response = RestClient::Response.create('abc', @net_http_res, @request)
|
||||
|
||||
@response.raw_headers['My-Header'].should eq ['foo', 'bar']
|
||||
@response.headers[:my_header].should eq 'foo, bar'
|
||||
expect(@response.raw_headers['My-Header']).to eq ['foo', 'bar']
|
||||
expect(@response.headers[:my_header]).to eq 'foo, bar'
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -43,15 +43,15 @@ describe RestClient::Response, :include_helpers do
|
|||
|
||||
net_http_res = double('net http response', :to_hash => {"etag" => ["\"e1ac1a2df945942ef4cac8116366baad\""], "set-cookie" => [header_val]})
|
||||
response = RestClient::Response.create('abc', net_http_res, @request)
|
||||
response.headers[:set_cookie].should eq [header_val]
|
||||
response.cookies.should eq({ "main_page" => "main_page_no_rewrite" })
|
||||
expect(response.headers[:set_cookie]).to eq [header_val]
|
||||
expect(response.cookies).to eq({ "main_page" => "main_page_no_rewrite" })
|
||||
end
|
||||
|
||||
it "should correctly deal with multiple cookies [multiple Set-Cookie headers]" do
|
||||
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"]})
|
||||
response = RestClient::Response.create('abc', net_http_res, @request)
|
||||
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"]
|
||||
response.cookies.should eq({
|
||||
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"]
|
||||
expect(response.cookies).to eq({
|
||||
"main_page" => "main_page_no_rewrite",
|
||||
"remember_me" => "",
|
||||
"user" => "somebody"
|
||||
|
@ -61,7 +61,7 @@ describe RestClient::Response, :include_helpers do
|
|||
it "should correctly deal with multiple cookies [one Set-Cookie header with multiple cookies]" do
|
||||
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"]})
|
||||
response = RestClient::Response.create('abc', net_http_res, @request)
|
||||
response.cookies.should eq({
|
||||
expect(response.cookies).to eq({
|
||||
"main_page" => "main_page_no_rewrite",
|
||||
"remember_me" => "",
|
||||
"user" => "somebody"
|
||||
|
@ -83,7 +83,7 @@ describe RestClient::Response, :include_helpers do
|
|||
unless (200..207).include? code
|
||||
net_http_res = response_double(:code => code.to_i)
|
||||
resp = RestClient::Response.create('abc', net_http_res, @request)
|
||||
lambda { resp.return! }.should raise_error
|
||||
expect { resp.return! }.to raise_error
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -95,29 +95,29 @@ describe RestClient::Response, :include_helpers do
|
|||
it "follows a redirection when the request is a get" do
|
||||
stub_request(:get, 'http://some/resource').to_return(:body => '', :status => 301, :headers => {'Location' => 'http://new/resource'})
|
||||
stub_request(:get, 'http://new/resource').to_return(:body => 'Foo')
|
||||
RestClient::Request.execute(:url => 'http://some/resource', :method => :get).body.should eq 'Foo'
|
||||
expect(RestClient::Request.execute(:url => 'http://some/resource', :method => :get).body).to eq 'Foo'
|
||||
end
|
||||
|
||||
it "keeps redirection history" do
|
||||
stub_request(:get, 'http://some/resource').to_return(:body => '', :status => 301, :headers => {'Location' => 'http://new/resource'})
|
||||
stub_request(:get, 'http://new/resource').to_return(:body => 'Foo')
|
||||
r = RestClient::Request.execute(url: 'http://some/resource', method: :get)
|
||||
r.body.should eq 'Foo'
|
||||
r.history.length.should eq 1
|
||||
r.history.fetch(0).should be_a(RestClient::Response)
|
||||
r.history.fetch(0).code.should be 301
|
||||
expect(r.body).to eq 'Foo'
|
||||
expect(r.history.length).to eq 1
|
||||
expect(r.history.fetch(0)).to be_a(RestClient::Response)
|
||||
expect(r.history.fetch(0).code).to be 301
|
||||
end
|
||||
|
||||
it "follows a redirection and keep the parameters" do
|
||||
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'})
|
||||
stub_request(:get, 'http://new/resource').with(:headers => {'Accept' => 'application/json'}, :basic_auth => ['foo', 'bar']).to_return(:body => 'Foo')
|
||||
RestClient::Request.execute(:url => 'http://some/resource', :method => :get, :user => 'foo', :password => 'bar', :headers => {:accept => :json}).body.should eq 'Foo'
|
||||
expect(RestClient::Request.execute(:url => 'http://some/resource', :method => :get, :user => 'foo', :password => 'bar', :headers => {:accept => :json}).body).to eq 'Foo'
|
||||
end
|
||||
|
||||
it "follows a redirection and keep the cookies" do
|
||||
stub_request(:get, 'http://some/resource').to_return(:body => '', :status => 301, :headers => {'Set-Cookie' => 'Foo=Bar', 'Location' => 'http://some/new_resource', })
|
||||
stub_request(:get, 'http://some/new_resource').with(:headers => {'Cookie' => 'Foo=Bar'}).to_return(:body => 'Qux')
|
||||
RestClient::Request.execute(:url => 'http://some/resource', :method => :get).body.should eq 'Qux'
|
||||
expect(RestClient::Request.execute(:url => 'http://some/resource', :method => :get).body).to eq 'Qux'
|
||||
end
|
||||
|
||||
it 'respects cookie domains on redirect' do
|
||||
|
@ -126,7 +126,7 @@ describe RestClient::Response, :include_helpers do
|
|||
stub_request(:get, 'http://new.example.com/').with(
|
||||
:headers => {'Cookie' => 'passedthrough=1'}).to_return(:body => 'Qux')
|
||||
|
||||
RestClient::Request.execute(:url => 'http://some.example.com/', :method => :get, cookies: [HTTP::Cookie.new('passedthrough', '1', domain: 'new.example.com', path: '/')]).body.should eq 'Qux'
|
||||
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'
|
||||
end
|
||||
|
||||
it "doesn't follow a 301 when the request is a post" do
|
||||
|
@ -134,90 +134,90 @@ describe RestClient::Response, :include_helpers do
|
|||
|
||||
response = RestClient::Response.create('abc', net_http_res,
|
||||
request_double(method: 'post'))
|
||||
lambda {
|
||||
expect {
|
||||
response.return!
|
||||
}.should raise_error(RestClient::MovedPermanently)
|
||||
}.to raise_error(RestClient::MovedPermanently)
|
||||
end
|
||||
|
||||
it "doesn't follow a 302 when the request is a post" do
|
||||
net_http_res = response_double(:code => 302)
|
||||
response = RestClient::Response.create('abc', net_http_res,
|
||||
request_double(method: 'post'))
|
||||
lambda {
|
||||
expect {
|
||||
response.return!
|
||||
}.should raise_error(RestClient::Found)
|
||||
}.to raise_error(RestClient::Found)
|
||||
end
|
||||
|
||||
it "doesn't follow a 307 when the request is a post" do
|
||||
net_http_res = response_double(:code => 307)
|
||||
response = RestClient::Response.create('abc', net_http_res,
|
||||
request_double(method: 'post'))
|
||||
response.should_not_receive(:follow_redirection)
|
||||
lambda {
|
||||
expect(response).not_to receive(:follow_redirection)
|
||||
expect {
|
||||
response.return!
|
||||
}.should raise_error(RestClient::TemporaryRedirect)
|
||||
}.to raise_error(RestClient::TemporaryRedirect)
|
||||
end
|
||||
|
||||
it "doesn't follow a redirection when the request is a put" do
|
||||
net_http_res = response_double(:code => 301)
|
||||
response = RestClient::Response.create('abc', net_http_res,
|
||||
request_double(method: 'put'))
|
||||
lambda {
|
||||
expect {
|
||||
response.return!
|
||||
}.should raise_error(RestClient::MovedPermanently)
|
||||
}.to raise_error(RestClient::MovedPermanently)
|
||||
end
|
||||
|
||||
it "follows a redirection when the request is a post and result is a 303" do
|
||||
stub_request(:put, 'http://some/resource').to_return(:body => '', :status => 303, :headers => {'Location' => 'http://new/resource'})
|
||||
stub_request(:get, 'http://new/resource').to_return(:body => 'Foo')
|
||||
RestClient::Request.execute(:url => 'http://some/resource', :method => :put).body.should eq 'Foo'
|
||||
expect(RestClient::Request.execute(:url => 'http://some/resource', :method => :put).body).to eq 'Foo'
|
||||
end
|
||||
|
||||
it "follows a redirection when the request is a head" do
|
||||
stub_request(:head, 'http://some/resource').to_return(:body => '', :status => 301, :headers => {'Location' => 'http://new/resource'})
|
||||
stub_request(:head, 'http://new/resource').to_return(:body => 'Foo')
|
||||
RestClient::Request.execute(:url => 'http://some/resource', :method => :head).body.should eq 'Foo'
|
||||
expect(RestClient::Request.execute(:url => 'http://some/resource', :method => :head).body).to eq 'Foo'
|
||||
end
|
||||
|
||||
it "handles redirects with relative paths" do
|
||||
stub_request(:get, 'http://some/resource').to_return(:body => '', :status => 301, :headers => {'Location' => 'index'})
|
||||
stub_request(:get, 'http://some/index').to_return(:body => 'Foo')
|
||||
RestClient::Request.execute(:url => 'http://some/resource', :method => :get).body.should eq 'Foo'
|
||||
expect(RestClient::Request.execute(:url => 'http://some/resource', :method => :get).body).to eq 'Foo'
|
||||
end
|
||||
|
||||
it "handles redirects with relative path and query string" do
|
||||
stub_request(:get, 'http://some/resource').to_return(:body => '', :status => 301, :headers => {'Location' => 'index?q=1'})
|
||||
stub_request(:get, 'http://some/index?q=1').to_return(:body => 'Foo')
|
||||
RestClient::Request.execute(:url => 'http://some/resource', :method => :get).body.should eq 'Foo'
|
||||
expect(RestClient::Request.execute(:url => 'http://some/resource', :method => :get).body).to eq 'Foo'
|
||||
end
|
||||
|
||||
it "follow a redirection when the request is a get and the response is in the 30x range" do
|
||||
stub_request(:get, 'http://some/resource').to_return(:body => '', :status => 301, :headers => {'Location' => 'http://new/resource'})
|
||||
stub_request(:get, 'http://new/resource').to_return(:body => 'Foo')
|
||||
RestClient::Request.execute(:url => 'http://some/resource', :method => :get).body.should eq 'Foo'
|
||||
expect(RestClient::Request.execute(:url => 'http://some/resource', :method => :get).body).to eq 'Foo'
|
||||
end
|
||||
|
||||
it "follows no more than 10 redirections before raising error" do
|
||||
stub_request(:get, 'http://some/redirect-1').to_return(:body => '', :status => 301, :headers => {'Location' => 'http://some/redirect-2'})
|
||||
stub_request(:get, 'http://some/redirect-2').to_return(:body => '', :status => 301, :headers => {'Location' => 'http://some/redirect-2'})
|
||||
lambda {
|
||||
expect {
|
||||
RestClient::Request.execute(url: 'http://some/redirect-1', method: :get)
|
||||
}.should raise_error(RestClient::MovedPermanently) { |ex|
|
||||
ex.response.history.each {|r| r.should be_a(RestClient::Response) }
|
||||
ex.response.history.length.should eq 10
|
||||
}.to raise_error(RestClient::MovedPermanently) { |ex|
|
||||
ex.response.history.each {|r| expect(r).to be_a(RestClient::Response) }
|
||||
expect(ex.response.history.length).to eq 10
|
||||
}
|
||||
WebMock.should have_requested(:get, 'http://some/redirect-2').times(10)
|
||||
expect(WebMock).to have_requested(:get, 'http://some/redirect-2').times(10)
|
||||
end
|
||||
|
||||
it "follows no more than max_redirects redirections, if specified" do
|
||||
stub_request(:get, 'http://some/redirect-1').to_return(:body => '', :status => 301, :headers => {'Location' => 'http://some/redirect-2'})
|
||||
stub_request(:get, 'http://some/redirect-2').to_return(:body => '', :status => 301, :headers => {'Location' => 'http://some/redirect-2'})
|
||||
lambda {
|
||||
expect {
|
||||
RestClient::Request.execute(url: 'http://some/redirect-1', method: :get, max_redirects: 5)
|
||||
}.should raise_error(RestClient::MovedPermanently) { |ex|
|
||||
ex.response.history.length.should eq 5
|
||||
}.to raise_error(RestClient::MovedPermanently) { |ex|
|
||||
expect(ex.response.history.length).to eq 5
|
||||
}
|
||||
WebMock.should have_requested(:get, 'http://some/redirect-2').times(5)
|
||||
expect(WebMock).to have_requested(:get, 'http://some/redirect-2').times(5)
|
||||
end
|
||||
|
||||
it "allows for manual following of redirects" do
|
||||
|
@ -232,8 +232,8 @@ describe RestClient::Response, :include_helpers do
|
|||
raise 'notreached'
|
||||
end
|
||||
|
||||
resp.code.should eq 200
|
||||
resp.body.should eq 'Qux'
|
||||
expect(resp.code).to eq 200
|
||||
expect(resp.body).to eq 'Qux'
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -3,37 +3,37 @@ require_relative '_lib'
|
|||
describe RestClient do
|
||||
describe "API" do
|
||||
it "GET" do
|
||||
RestClient::Request.should_receive(:execute).with(:method => :get, :url => 'http://some/resource', :headers => {})
|
||||
expect(RestClient::Request).to receive(:execute).with(:method => :get, :url => 'http://some/resource', :headers => {})
|
||||
RestClient.get('http://some/resource')
|
||||
end
|
||||
|
||||
it "POST" do
|
||||
RestClient::Request.should_receive(:execute).with(:method => :post, :url => 'http://some/resource', :payload => 'payload', :headers => {})
|
||||
expect(RestClient::Request).to receive(:execute).with(:method => :post, :url => 'http://some/resource', :payload => 'payload', :headers => {})
|
||||
RestClient.post('http://some/resource', 'payload')
|
||||
end
|
||||
|
||||
it "PUT" do
|
||||
RestClient::Request.should_receive(:execute).with(:method => :put, :url => 'http://some/resource', :payload => 'payload', :headers => {})
|
||||
expect(RestClient::Request).to receive(:execute).with(:method => :put, :url => 'http://some/resource', :payload => 'payload', :headers => {})
|
||||
RestClient.put('http://some/resource', 'payload')
|
||||
end
|
||||
|
||||
it "PATCH" do
|
||||
RestClient::Request.should_receive(:execute).with(:method => :patch, :url => 'http://some/resource', :payload => 'payload', :headers => {})
|
||||
expect(RestClient::Request).to receive(:execute).with(:method => :patch, :url => 'http://some/resource', :payload => 'payload', :headers => {})
|
||||
RestClient.patch('http://some/resource', 'payload')
|
||||
end
|
||||
|
||||
it "DELETE" do
|
||||
RestClient::Request.should_receive(:execute).with(:method => :delete, :url => 'http://some/resource', :headers => {})
|
||||
expect(RestClient::Request).to receive(:execute).with(:method => :delete, :url => 'http://some/resource', :headers => {})
|
||||
RestClient.delete('http://some/resource')
|
||||
end
|
||||
|
||||
it "HEAD" do
|
||||
RestClient::Request.should_receive(:execute).with(:method => :head, :url => 'http://some/resource', :headers => {})
|
||||
expect(RestClient::Request).to receive(:execute).with(:method => :head, :url => 'http://some/resource', :headers => {})
|
||||
RestClient.head('http://some/resource')
|
||||
end
|
||||
|
||||
it "OPTIONS" do
|
||||
RestClient::Request.should_receive(:execute).with(:method => :options, :url => 'http://some/resource', :headers => {})
|
||||
expect(RestClient::Request).to receive(:execute).with(:method => :options, :url => 'http://some/resource', :headers => {})
|
||||
RestClient.options('http://some/resource')
|
||||
end
|
||||
end
|
||||
|
@ -45,27 +45,27 @@ describe RestClient do
|
|||
|
||||
it "uses << if the log is not a string" do
|
||||
log = RestClient.log = []
|
||||
log.should_receive(:<<).with('xyz')
|
||||
expect(log).to receive(:<<).with('xyz')
|
||||
RestClient.log << 'xyz'
|
||||
end
|
||||
|
||||
it "displays the log to stdout" do
|
||||
RestClient.log = 'stdout'
|
||||
STDOUT.should_receive(:puts).with('xyz')
|
||||
expect(STDOUT).to receive(:puts).with('xyz')
|
||||
RestClient.log << 'xyz'
|
||||
end
|
||||
|
||||
it "displays the log to stderr" do
|
||||
RestClient.log = 'stderr'
|
||||
STDERR.should_receive(:puts).with('xyz')
|
||||
expect(STDERR).to receive(:puts).with('xyz')
|
||||
RestClient.log << 'xyz'
|
||||
end
|
||||
|
||||
it "append the log to the requested filename" do
|
||||
RestClient.log = '/tmp/restclient.log'
|
||||
f = double('file handle')
|
||||
File.should_receive(:open).with('/tmp/restclient.log', 'a').and_yield(f)
|
||||
f.should_receive(:puts).with('xyz')
|
||||
expect(File).to receive(:open).with('/tmp/restclient.log', 'a').and_yield(f)
|
||||
expect(f).to receive(:puts).with('xyz')
|
||||
RestClient.log << 'xyz'
|
||||
end
|
||||
end
|
||||
|
@ -73,7 +73,7 @@ describe RestClient do
|
|||
describe 'version' do
|
||||
it 'has a version ~> 2.0.0.alpha' do
|
||||
ver = Gem::Version.new(RestClient.version)
|
||||
Gem::Requirement.new('~> 2.0.0.alpha').should be_satisfied_by(ver)
|
||||
expect(Gem::Requirement.new('~> 2.0.0.alpha')).to be_satisfied_by(ver)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -4,67 +4,67 @@ describe RestClient::Utils do
|
|||
describe '.get_encoding_from_headers' do
|
||||
it 'assumes no encoding by default for text' do
|
||||
headers = {:content_type => 'text/plain'}
|
||||
RestClient::Utils.get_encoding_from_headers(headers).
|
||||
should eq nil
|
||||
expect(RestClient::Utils.get_encoding_from_headers(headers)).
|
||||
to eq nil
|
||||
end
|
||||
|
||||
it 'returns nil on failures' do
|
||||
RestClient::Utils.get_encoding_from_headers(
|
||||
{:content_type => 'blah'}).should eq nil
|
||||
RestClient::Utils.get_encoding_from_headers(
|
||||
{}).should eq nil
|
||||
RestClient::Utils.get_encoding_from_headers(
|
||||
{:content_type => 'foo; bar=baz'}).should eq nil
|
||||
expect(RestClient::Utils.get_encoding_from_headers(
|
||||
{:content_type => 'blah'})).to eq nil
|
||||
expect(RestClient::Utils.get_encoding_from_headers(
|
||||
{})).to eq nil
|
||||
expect(RestClient::Utils.get_encoding_from_headers(
|
||||
{:content_type => 'foo; bar=baz'})).to eq nil
|
||||
end
|
||||
|
||||
it 'handles various charsets' do
|
||||
RestClient::Utils.get_encoding_from_headers(
|
||||
{:content_type => 'text/plain; charset=UTF-8'}).should eq 'UTF-8'
|
||||
RestClient::Utils.get_encoding_from_headers(
|
||||
{:content_type => 'application/json; charset=ISO-8859-1'}).
|
||||
should eq 'ISO-8859-1'
|
||||
RestClient::Utils.get_encoding_from_headers(
|
||||
{:content_type => 'text/html; charset=windows-1251'}).
|
||||
should eq 'windows-1251'
|
||||
expect(RestClient::Utils.get_encoding_from_headers(
|
||||
{:content_type => 'text/plain; charset=UTF-8'})).to eq 'UTF-8'
|
||||
expect(RestClient::Utils.get_encoding_from_headers(
|
||||
{:content_type => 'application/json; charset=ISO-8859-1'})).
|
||||
to eq 'ISO-8859-1'
|
||||
expect(RestClient::Utils.get_encoding_from_headers(
|
||||
{:content_type => 'text/html; charset=windows-1251'})).
|
||||
to eq 'windows-1251'
|
||||
|
||||
RestClient::Utils.get_encoding_from_headers(
|
||||
{:content_type => 'text/html; charset="UTF-16"'}).
|
||||
should eq 'UTF-16'
|
||||
expect(RestClient::Utils.get_encoding_from_headers(
|
||||
{:content_type => 'text/html; charset="UTF-16"'})).
|
||||
to eq 'UTF-16'
|
||||
end
|
||||
end
|
||||
|
||||
describe '.cgi_parse_header' do
|
||||
it 'parses headers' do
|
||||
RestClient::Utils.cgi_parse_header('text/plain').
|
||||
should eq ['text/plain', {}]
|
||||
expect(RestClient::Utils.cgi_parse_header('text/plain')).
|
||||
to eq ['text/plain', {}]
|
||||
|
||||
RestClient::Utils.cgi_parse_header('text/vnd.just.made.this.up ; ').
|
||||
should eq ['text/vnd.just.made.this.up', {}]
|
||||
expect(RestClient::Utils.cgi_parse_header('text/vnd.just.made.this.up ; ')).
|
||||
to eq ['text/vnd.just.made.this.up', {}]
|
||||
|
||||
RestClient::Utils.cgi_parse_header('text/plain;charset=us-ascii').
|
||||
should eq ['text/plain', {'charset' => 'us-ascii'}]
|
||||
expect(RestClient::Utils.cgi_parse_header('text/plain;charset=us-ascii')).
|
||||
to eq ['text/plain', {'charset' => 'us-ascii'}]
|
||||
|
||||
RestClient::Utils.cgi_parse_header('text/plain ; charset="us-ascii"').
|
||||
should eq ['text/plain', {'charset' => 'us-ascii'}]
|
||||
expect(RestClient::Utils.cgi_parse_header('text/plain ; charset="us-ascii"')).
|
||||
to eq ['text/plain', {'charset' => 'us-ascii'}]
|
||||
|
||||
RestClient::Utils.cgi_parse_header(
|
||||
'text/plain ; charset="us-ascii"; another=opt').
|
||||
should eq ['text/plain', {'charset' => 'us-ascii', 'another' => 'opt'}]
|
||||
expect(RestClient::Utils.cgi_parse_header(
|
||||
'text/plain ; charset="us-ascii"; another=opt')).
|
||||
to eq ['text/plain', {'charset' => 'us-ascii', 'another' => 'opt'}]
|
||||
|
||||
RestClient::Utils.cgi_parse_header(
|
||||
'attachment; filename="silly.txt"').
|
||||
should eq ['attachment', {'filename' => 'silly.txt'}]
|
||||
expect(RestClient::Utils.cgi_parse_header(
|
||||
'attachment; filename="silly.txt"')).
|
||||
to eq ['attachment', {'filename' => 'silly.txt'}]
|
||||
|
||||
RestClient::Utils.cgi_parse_header(
|
||||
'attachment; filename="strange;name"').
|
||||
should eq ['attachment', {'filename' => 'strange;name'}]
|
||||
expect(RestClient::Utils.cgi_parse_header(
|
||||
'attachment; filename="strange;name"')).
|
||||
to eq ['attachment', {'filename' => 'strange;name'}]
|
||||
|
||||
RestClient::Utils.cgi_parse_header(
|
||||
'attachment; filename="strange;name";size=123;').should eq \
|
||||
expect(RestClient::Utils.cgi_parse_header(
|
||||
'attachment; filename="strange;name";size=123;')).to eq \
|
||||
['attachment', {'filename' => 'strange;name', 'size' => '123'}]
|
||||
|
||||
RestClient::Utils.cgi_parse_header(
|
||||
'form-data; name="files"; filename="fo\\"o;bar"').should eq \
|
||||
expect(RestClient::Utils.cgi_parse_header(
|
||||
'form-data; name="files"; filename="fo\\"o;bar"')).to eq \
|
||||
['form-data', {'name' => 'files', 'filename' => 'fo"o;bar'}]
|
||||
end
|
||||
end
|
||||
|
@ -78,7 +78,7 @@ describe RestClient::Utils do
|
|||
{escaped: '1+2=3'} => 'escaped=1%2B2%3D3',
|
||||
{'escaped + key' => 'foo'} => 'escaped+%2B+key=foo',
|
||||
}.each_pair do |input, expected|
|
||||
RestClient::Utils.encode_query_string(input).should eq expected
|
||||
expect(RestClient::Utils.encode_query_string(input)).to eq expected
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -89,7 +89,7 @@ describe RestClient::Utils do
|
|||
{foo: ['one two', 3]} => 'foo[]=one+two&foo[]=3',
|
||||
{'a+b' => [1,2,3]} => 'a%2Bb[]=1&a%2Bb[]=2&a%2Bb[]=3',
|
||||
}.each_pair do |input, expected|
|
||||
RestClient::Utils.encode_query_string(input).should eq expected
|
||||
expect(RestClient::Utils.encode_query_string(input)).to eq expected
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -98,7 +98,7 @@ describe RestClient::Utils do
|
|||
{outer: {foo: 123, bar: 456}} => 'outer[foo]=123&outer[bar]=456',
|
||||
{outer: {foo: [1, 2, 3], bar: 'baz'}} => 'outer[foo][]=1&outer[foo][]=2&outer[foo][]=3&outer[bar]=baz',
|
||||
}.each_pair do |input, expected|
|
||||
RestClient::Utils.encode_query_string(input).should eq expected
|
||||
expect(RestClient::Utils.encode_query_string(input)).to eq expected
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -107,7 +107,7 @@ describe RestClient::Utils do
|
|||
{string: '', empty: nil, list: [], hash: {}, falsey: false } =>
|
||||
'string=&empty&list&hash&falsey=false',
|
||||
}.each_pair do |input, expected|
|
||||
RestClient::Utils.encode_query_string(input).should eq expected
|
||||
expect(RestClient::Utils.encode_query_string(input)).to eq expected
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -115,7 +115,7 @@ describe RestClient::Utils do
|
|||
{
|
||||
{foo: {string: '', empty: nil}} => 'foo[string]=&foo[empty]',
|
||||
}.each_pair do |input, expected|
|
||||
RestClient::Utils.encode_query_string(input).should eq expected
|
||||
expect(RestClient::Utils.encode_query_string(input)).to eq expected
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -123,7 +123,7 @@ describe RestClient::Utils do
|
|||
{
|
||||
{coords: [{x: 1, y: 0}, {x: 2}, {x: 3}]} => 'coords[][x]=1&coords[][y]=0&coords[][x]=2&coords[][x]=3',
|
||||
}.each_pair do |input, expected|
|
||||
RestClient::Utils.encode_query_string(input).should eq expected
|
||||
expect(RestClient::Utils.encode_query_string(input)).to eq expected
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -131,7 +131,7 @@ describe RestClient::Utils do
|
|||
{
|
||||
RestClient::ParamsArray.new([[:foo, 1], [:foo, 2], [:foo, 3]]) => 'foo=1&foo=2&foo=3',
|
||||
}.each_pair do |input, expected|
|
||||
RestClient::Utils.encode_query_string(input).should eq expected
|
||||
expect(RestClient::Utils.encode_query_string(input)).to eq expected
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -140,7 +140,7 @@ describe RestClient::Utils do
|
|||
{foo: RestClient::ParamsArray.new([[:a, 1], [:a, 2]])} => 'foo[a]=1&foo[a]=2',
|
||||
RestClient::ParamsArray.new([[:foo, {a: 1}], [:foo, {a: 2}]]) => 'foo[a]=1&foo[a]=2',
|
||||
}.each_pair do |input, expected|
|
||||
RestClient::Utils.encode_query_string(input).should eq expected
|
||||
expect(RestClient::Utils.encode_query_string(input)).to eq expected
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -5,7 +5,7 @@ describe 'RestClient::Windows::RootCerts',
|
|||
let(:x509_store) { RestClient::Windows::RootCerts.instance.to_a }
|
||||
|
||||
it 'should return at least one X509 certificate' do
|
||||
expect(x509_store.to_a).to have_at_least(1).items
|
||||
expect(x509_store.to_a.size).to be >= 1
|
||||
end
|
||||
|
||||
it 'should return an X509 certificate with a subject' do
|
||||
|
@ -16,7 +16,7 @@ describe 'RestClient::Windows::RootCerts',
|
|||
|
||||
it 'should return X509 certificate objects' do
|
||||
x509_store.each do |cert|
|
||||
cert.should be_a(OpenSSL::X509::Certificate)
|
||||
expect(cert).to be_a(OpenSSL::X509::Certificate)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue