diff options
author | Mikel Lindsaar <raasdnil@gmail.com> | 2010-08-25 12:05:23 +1000 |
---|---|---|
committer | Xavier Noria <fxn@hashref.com> | 2010-08-25 10:00:37 +0200 |
commit | c1b49f1e18e08580196f5acfaacebcf4c3aa17d3 (patch) | |
tree | 1098ba22e0169cf2a48762b6226f9d054a8e15e5 /activeresource | |
parent | 1847d33b4bc776fbd4746c06db41965744377ed6 (diff) | |
download | rails-c1b49f1e18e08580196f5acfaacebcf4c3aa17d3.tar.gz rails-c1b49f1e18e08580196f5acfaacebcf4c3aa17d3.tar.bz2 rails-c1b49f1e18e08580196f5acfaacebcf4c3aa17d3.zip |
Make ActiveResource::InvalidRequestError more user friendly
Signed-off-by: Xavier Noria <fxn@hashref.com>
Diffstat (limited to 'activeresource')
-rw-r--r-- | activeresource/lib/active_resource/http_mock.rb | 8 | ||||
-rw-r--r-- | activeresource/test/cases/http_mock_test.rb | 11 |
2 files changed, 17 insertions, 2 deletions
diff --git a/activeresource/lib/active_resource/http_mock.rb b/activeresource/lib/active_resource/http_mock.rb index a98af88a37..8753a21835 100644 --- a/activeresource/lib/active_resource/http_mock.rb +++ b/activeresource/lib/active_resource/http_mock.rb @@ -126,7 +126,7 @@ module ActiveResource # if response = self.class.responses.assoc(request) # response[1] # else - # raise InvalidRequestError.new("No response recorded for #{request}") + # raise InvalidRequestError.new("Could not find a response recorded for #{request.to_s} - Responses recorded are: - #{inspect_responses}") # end # end module_eval <<-EOE, __FILE__, __LINE__ + 1 @@ -136,7 +136,7 @@ module ActiveResource if response = self.class.responses.assoc(request) response[1] else - raise InvalidRequestError.new("No response recorded for \#{request}") + raise InvalidRequestError.new("Could not find a response recorded for \#{request.to_s} - Responses recorded are: \#{inspect_responses}") end end EOE @@ -146,6 +146,10 @@ module ActiveResource def initialize(site) #:nodoc: @site = site end + + def inspect_responses #:nodoc: + self.class.responses.map { |r| r[0].to_s }.inspect + end end class Request diff --git a/activeresource/test/cases/http_mock_test.rb b/activeresource/test/cases/http_mock_test.rb index 5e032d03f1..a387cd20b1 100644 --- a/activeresource/test/cases/http_mock_test.rb +++ b/activeresource/test/cases/http_mock_test.rb @@ -59,6 +59,17 @@ class HttpMockTest < ActiveSupport::TestCase assert_equal "XML", request(method, "/people/1", FORMAT_HEADER[method] => "application/xml").body assert_equal "Json", request(method, "/people/1", FORMAT_HEADER[method] => "application/json").body end + + test "raises InvalidRequestError if no response found for the #{method} request" do + ActiveResource::HttpMock.respond_to do |mock| + mock.send(method, "/people/1", {FORMAT_HEADER[method] => "application/xml"}, "XML") + end + + assert_raise(::ActiveResource::InvalidRequestError) do + request(method, "/people/1", FORMAT_HEADER[method] => "application/json") + end + end + end def request(method, path, headers = {}, body = nil) |