Sha256: 14ff2d79dcb6975d446e251e7abb627663e0979d15480c81a695ba1dca955904

Contents?: true

Size: 1.32 KB

Versions: 29

Compression:

Stored size: 1.32 KB

Contents

require File.dirname(__FILE__) + '/../base'

class MockResponse
	include RestClient::Mixin::Response

	def initialize(body, res)
		@net_http_res = res
		@body = @body
	end
end

describe RestClient::Mixin::Response do
	before do
		@net_http_res = mock('net http response')
		@response = MockResponse.new('abc', @net_http_res)
	end

	it "fetches the numeric response code" do
		@net_http_res.should_receive(:code).and_return('200')
		@response.code.should == 200
	end

	it "beautifies the headers by turning the keys to symbols" do
		h = RestClient::Response.beautify_headers('content-type' => [ 'x' ])
		h.keys.first.should == :content_type
	end

	it "beautifies the headers by turning the values to strings instead of one-element arrays" do
		h = RestClient::Response.beautify_headers('x' => [ 'text/html' ] )
		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
end

Version data entries

29 entries across 29 versions & 9 rubygems

Version Path
adamwiggins-rest-client-1.0.2 spec/mixin/response_spec.rb
adamwiggins-rest-client-1.0.3 spec/mixin/response_spec.rb
adamwiggins-rest-client-1.0.4 spec/mixin/response_spec.rb
auser-poolparty-1.2.10 vendor/gems/rest-client/spec/mixin/response_spec.rb
auser-poolparty-1.2.3 vendor/gems/rest-client/spec/mixin/response_spec.rb
auser-poolparty-1.2.4 vendor/gems/rest-client/spec/mixin/response_spec.rb
auser-poolparty-1.2.7 vendor/gems/rest-client/spec/mixin/response_spec.rb
auser-poolparty-1.2.8 vendor/gems/rest-client/spec/mixin/response_spec.rb
auser-poolparty-1.2.9 vendor/gems/rest-client/spec/mixin/response_spec.rb
benschwarz-smoke-0.5.0 vendor/rest-client/spec/mixin/response_spec.rb
benschwarz-smoke-0.5.1 vendor/rest-client/spec/mixin/response_spec.rb
benschwarz-smoke-0.5.2 vendor/rest-client-1.0.1/spec/mixin/response_spec.rb
benschwarz-smoke-0.5.3 vendor/rest-client-1.0.1/spec/mixin/response_spec.rb
benschwarz-smoke-0.5.4 vendor/rest-client-1.0.1/spec/mixin/response_spec.rb
benschwarz-smoke-0.5.5 vendor/rest-client-1.0.1/spec/mixin/response_spec.rb
benschwarz-smoke-0.5.6 vendor/rest-client-1.0.1/spec/mixin/response_spec.rb
benschwarz-smoke-0.5.7 vendor/gems/gems/rest-client-1.0.1/spec/mixin/response_spec.rb
francois-rest-client-1.1.5 spec/mixin/response_spec.rb
francois-rest-client-1.1.6 spec/mixin/response_spec.rb
sml-rest-client-1.1.7 spec/mixin/response_spec.rb