Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Make ActiveResource::InvalidRequestError more user friendly

Signed-off-by: Xavier Noria <fxn@hashref.com>
  • Loading branch information...
commit d887dbc2d6620cb41d669df759ed582f4fbe82d5 1 parent 37467bf
@mikel mikel authored fxn committed
View
8 activeresource/lib/active_resource/http_mock.rb
@@ -126,7 +126,7 @@ def reset!
# 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 @@ def #{method}(path, #{'body, ' if has_body}headers)
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 @@ def #{method}(path, #{'body, ' if has_body}headers)
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
View
11 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)
Please sign in to comment.
Something went wrong with that request. Please try again.