Skip to content
Browse files

Make ActiveResource::InvalidRequestError more user friendly

Signed-off-by: Xavier Noria <fxn@hashref.com>
  • Loading branch information...
1 parent 11361a9 commit 0fcb4302e1a1193b2a59dd76abb436b24c93e3ac @mikel mikel committed with fxn Aug 25, 2010
Showing with 6 additions and 2 deletions.
  1. +6 −2 activeresource/lib/active_resource/http_mock.rb
View
8 activeresource/lib/active_resource/http_mock.rb
@@ -123,13 +123,13 @@ def reset!
# def post(path, body, headers)
# request = ActiveResource::Request.new(:post, path, body, headers)
# self.class.requests << request
- # self.class.responses.assoc(request).try(:second) || raise(InvalidRequestError.new("No response recorded for #{request}"))
+ # self.class.responses.assoc(request).try(:second) || raise(InvalidRequestError.new("Could not find a response recorded for #{request.to_s} - Responses recorded are: - #{inspect_responses}"))
# end
module_eval <<-EOE, __FILE__, __LINE__ + 1
def #{method}(path, #{'body, ' if has_body}headers)
request = ActiveResource::Request.new(:#{method}, path, #{has_body ? 'body, ' : 'nil, '}headers)
self.class.requests << request
- self.class.responses.assoc(request).try(:second) || raise(InvalidRequestError.new("No response recorded for \#{request}"))
+ self.class.responses.assoc(request).try(:second) || raise(InvalidRequestError.new("Could not find a response recorded for \#{request.to_s} - Responses recorded are: - \#{inspect_responses}"))
end
EOE
end
@@ -138,6 +138,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

0 comments on commit 0fcb430

Please sign in to comment.
Something went wrong with that request. Please try again.