diff options
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) |