1
0
Fork 0
mirror of https://github.com/rest-client/rest-client.git synced 2022-11-09 13:49:40 -05:00

Start adding functional tests using httpbin.org.

These tests are a work in progress.
This commit is contained in:
Andy Brody 2015-04-15 15:37:29 -07:00
parent ad9552ebc0
commit 1affca3412

View file

@ -0,0 +1,62 @@
require_relative '_lib'
require 'json'
describe RestClient::Request do
before(:all) do
WebMock.disable!
end
after(:all) do
WebMock.enable!
end
def httpbin(suffix='')
url = ENV.fetch('HTTPBIN_URL', 'https://httpbin.org/')
unless url.end_with?('/')
url += '/'
end
url + suffix
end
def execute_httpbin(suffix, opts={})
opts = {url: httpbin(suffix)}.merge(opts)
RestClient::Request.execute(opts)
end
def execute_httpbin_json(suffix, opts={})
JSON.parse(execute_httpbin(suffix, opts))
end
describe '.execute' do
it 'sends a user agent' do
data = execute_httpbin_json('user-agent', method: :get)
data['user-agent'].should 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'
}
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'
end
it 'handles quote wrapped cookies' do
expect {
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"'
}
end
end
end