1
require File.join( File.dirname(File.expand_path(__FILE__)), 'base')
3
describe RestClient::AbstractResponse do
5
class MyAbstractResponse
7
include RestClient::AbstractResponse
11
def initialize net_http_res, args
12
@net_http_res = net_http_res
19
@net_http_res = mock('net http response')
20
@response = MyAbstractResponse.new(@net_http_res, {})
23
it "fetches the numeric response code" do
24
@net_http_res.should_receive(:code).and_return('200')
25
@response.code.should == 200
28
it "has a nice description" do
29
@net_http_res.should_receive(:to_hash).and_return({'Content-Type' => ['application/pdf']})
30
@net_http_res.should_receive(:code).and_return('200')
31
@response.description == '200 OK | application/pdf bytes\n'
34
it "beautifies the headers by turning the keys to symbols" do
35
h = RestClient::AbstractResponse.beautify_headers('content-type' => [ 'x' ])
36
h.keys.first.should == :content_type
39
it "beautifies the headers by turning the values to strings instead of one-element arrays" do
40
h = RestClient::AbstractResponse.beautify_headers('x' => [ 'text/html' ] )
41
h.values.first.should == 'text/html'
44
it "fetches the headers" do
45
@net_http_res.should_receive(:to_hash).and_return('content-type' => [ 'text/html' ])
46
@response.headers.should == { :content_type => 'text/html' }
49
it "extracts cookies from response headers" do
50
@net_http_res.should_receive(:to_hash).and_return('set-cookie' => ['session_id=1; path=/'])
51
@response.cookies.should == { 'session_id' => '1' }
54
it "extract strange cookies" do
55
@net_http_res.should_receive(:to_hash).and_return('set-cookie' => ['session_id=ZJ/HQVH6YE+rVkTpn0zvTQ==; path=/'])
56
@response.cookies.should == { 'session_id' => 'ZJ%2FHQVH6YE+rVkTpn0zvTQ%3D%3D' }
59
it "doesn't escape cookies" do
60
@net_http_res.should_receive(:to_hash).and_return('set-cookie' => ['session_id=BAh7BzoNYXBwX25hbWUiEGFwcGxpY2F0aW9uOgpsb2dpbiIKYWRtaW4%3D%0A--08114ba654f17c04d20dcc5228ec672508f738ca; path=/'])
61
@response.cookies.should == { 'session_id' => 'BAh7BzoNYXBwX25hbWUiEGFwcGxpY2F0aW9uOgpsb2dpbiIKYWRtaW4%3D%0A--08114ba654f17c04d20dcc5228ec672508f738ca' }
64
it "can access the net http result directly" do
65
@response.net_http_res.should == @net_http_res