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

40 lines
1.9 KiB
Ruby
Raw Normal View History

2009-01-24 17:55:18 -05:00
require File.dirname(__FILE__) + '/base'
describe RestClient::Response do
2009-12-29 12:27:39 -05:00
before do
@net_http_res = mock('net http response', :to_hash => {"Status" => ["200 OK"]})
@response = RestClient::Response.new('abc', @net_http_res)
end
2009-01-24 17:55:18 -05:00
2009-12-29 12:27:39 -05:00
it "behaves like string" do
@response.should == 'abc'
end
2009-01-24 17:55:18 -05:00
2009-12-29 12:27:39 -05:00
it "accepts nil strings and sets it to empty for the case of HEAD" do
RestClient::Response.new(nil, @net_http_res).should == ""
end
it "test headers and raw headers" do
@response.raw_headers["Status"][0].should == "200 OK"
@response.headers[:status].should == "200 OK"
end
it "should correctly deal with one cookie" do
net_http_res = mock('net http response', :to_hash => {"etag" => ["\"e1ac1a2df945942ef4cac8116366baad\""], "set-cookie" => ["main_page=main_page_no_rewrite; path=/; expires=Tue, 20-Jan-2015 15:03:14 GMT"]})
response = RestClient::Response.new('abc', net_http_res)
response.headers[:set_cookie].should == ["main_page=main_page_no_rewrite; path=/; expires=Tue, 20-Jan-2015 15:03:14 GMT"]
response.cookies.should == { "main_page" => "main_page_no_rewrite" }
end
it "should correctly deal with multiple cookies" do
net_http_res = mock('net http response', :to_hash => {"etag" => ["\"e1ac1a2df945942ef4cac8116366baad\""], "set-cookie" => ["main_page=main_page_no_rewrite; path=/; expires=Tue, 20-Jan-2015 15:03:14 GMT", "remember_me=; path=/; expires=Thu, 01-Jan-1970 00:00:00 GMT", "user=somebody; path=/; expires=Thu, 01-Jan-1970 00:00:00 GMT"]})
response = RestClient::Response.new('abc', net_http_res)
response.headers[:set_cookie].should == ["main_page=main_page_no_rewrite; path=/; expires=Tue, 20-Jan-2015 15:03:14 GMT", "remember_me=; path=/; expires=Thu, 01-Jan-1970 00:00:00 GMT", "user=somebody; path=/; expires=Thu, 01-Jan-1970 00:00:00 GMT"]
response.cookies.should == {
"main_page" => "main_page_no_rewrite",
"remember_me" => "",
"user" => "somebody"
}
end
2009-01-24 17:55:18 -05:00
end