2010-01-25 16:04:59 -05:00
|
|
|
require File.dirname(__FILE__) + '/base'
|
2009-03-16 18:28:20 -04:00
|
|
|
|
2010-01-25 16:04:59 -05:00
|
|
|
describe RestClient::AbstractResponse do
|
2010-03-29 13:38:23 -04:00
|
|
|
|
|
|
|
class MyAbstractResponse
|
|
|
|
|
|
|
|
include RestClient::AbstractResponse
|
|
|
|
|
2010-04-23 13:40:49 -04:00
|
|
|
attr_accessor :size
|
|
|
|
|
2010-03-29 13:38:23 -04:00
|
|
|
def initialize net_http_res, args
|
|
|
|
@net_http_res = net_http_res
|
|
|
|
@args = args
|
|
|
|
end
|
2010-04-23 13:40:49 -04:00
|
|
|
|
|
|
|
|
2010-03-29 13:38:23 -04:00
|
|
|
end
|
|
|
|
|
2009-12-29 12:27:39 -05:00
|
|
|
before do
|
|
|
|
@net_http_res = mock('net http response')
|
2010-03-29 13:38:23 -04:00
|
|
|
@response = MyAbstractResponse.new(@net_http_res, {})
|
2009-12-29 12:27:39 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it "fetches the numeric response code" do
|
|
|
|
@net_http_res.should_receive(:code).and_return('200')
|
|
|
|
@response.code.should == 200
|
|
|
|
end
|
|
|
|
|
2010-04-23 13:40:49 -04:00
|
|
|
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 == '200 OK | application/pdf bytes\n'
|
|
|
|
end
|
|
|
|
|
2009-12-29 12:27:39 -05:00
|
|
|
it "beautifies the headers by turning the keys to symbols" do
|
2010-03-29 13:38:23 -04:00
|
|
|
h = RestClient::AbstractResponse.beautify_headers('content-type' => [ 'x' ])
|
2009-12-29 12:27:39 -05:00
|
|
|
h.keys.first.should == :content_type
|
|
|
|
end
|
|
|
|
|
|
|
|
it "beautifies the headers by turning the values to strings instead of one-element arrays" do
|
2010-03-29 13:38:23 -04:00
|
|
|
h = RestClient::AbstractResponse.beautify_headers('x' => [ 'text/html' ] )
|
2009-12-29 12:27:39 -05:00
|
|
|
h.values.first.should == 'text/html'
|
|
|
|
end
|
|
|
|
|
|
|
|
it "fetches the headers" do
|
|
|
|
@net_http_res.should_receive(:to_hash).and_return('content-type' => [ 'text/html' ])
|
|
|
|
@response.headers.should == { :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 == { 'session_id' => '1' }
|
|
|
|
end
|
|
|
|
|
|
|
|
it "can access the net http result directly" do
|
|
|
|
@response.net_http_res.should == @net_http_res
|
|
|
|
end
|
2009-03-16 18:28:20 -04:00
|
|
|
end
|