diff --git a/lib/restclient/abstract_response.rb b/lib/restclient/abstract_response.rb index dda0477..3915909 100644 --- a/lib/restclient/abstract_response.rb +++ b/lib/restclient/abstract_response.rb @@ -4,6 +4,10 @@ module RestClient attr_reader :net_http_res + def initialize net_http_res + @net_http_res = net_http_res + end + # HTTP status code def code @code ||= @net_http_res.code.to_i diff --git a/lib/restclient/raw_response.rb b/lib/restclient/raw_response.rb index 8f4274c..7890b36 100644 --- a/lib/restclient/raw_response.rb +++ b/lib/restclient/raw_response.rb @@ -13,8 +13,8 @@ module RestClient attr_reader :file - def initialize(tempfile, net_http_res) - @net_http_res = net_http_res + def initialize tempfile, net_http_res + super net_http_res @file = tempfile end diff --git a/lib/restclient/response.rb b/lib/restclient/response.rb index 12cba9b..0d77127 100644 --- a/lib/restclient/response.rb +++ b/lib/restclient/response.rb @@ -6,8 +6,8 @@ module RestClient attr_reader :body - def initialize(body, net_http_res) - @net_http_res = net_http_res + def initialize body, net_http_res + super net_http_res @body = body || "" end diff --git a/spec/abstract_response_spec.rb b/spec/abstract_response_spec.rb index 9d7ace0..1dddf38 100644 --- a/spec/abstract_response_spec.rb +++ b/spec/abstract_response_spec.rb @@ -3,7 +3,7 @@ require File.dirname(__FILE__) + '/base' describe RestClient::AbstractResponse do before do @net_http_res = mock('net http response') - @response = AbstractResponse.new('abc', @net_http_res) + @response = RestClient::AbstractResponse.new(@net_http_res) end it "fetches the numeric response code" do diff --git a/spec/response_spec.rb b/spec/response_spec.rb index 269f584..b5e971a 100644 --- a/spec/response_spec.rb +++ b/spec/response_spec.rb @@ -60,9 +60,11 @@ describe RestClient::Response do it "should throw an exception for other codes" do RestClient::Exceptions::EXCEPTIONS_MAP.each_key do |code| - net_http_res = mock('net http response', :code => code.to_i) - response = RestClient::Response.new('abc', net_http_res) - lambda { response.return!}.should raise_error + unless (200..206).include? code + net_http_res = mock('net http response', :code => code.to_i) + response = RestClient::Response.new('abc', net_http_res) + lambda { response.return!}.should raise_error + end end end