Class: ActiveResource::HttpMock
- Inherits:
-
Object
- Object
- ActiveResource::HttpMock
- Defined in:
- lib/active_resource/persistent_http_mock.rb,
lib/active_resource/persistent_http_mock.rb
Defined Under Namespace
Classes: Responder
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.enabled=(bool) ⇒ Object
25 26 27 |
# File 'lib/active_resource/persistent_http_mock.rb', line 25 def self.enabled=(bool) @enabled = bool end |
.enabled? ⇒ Boolean
28 29 30 |
# File 'lib/active_resource/persistent_http_mock.rb', line 28 def self.enabled? @enabled end |
.patch(path, body, headers) ⇒ Object
57 58 59 60 61 62 63 64 65 |
# File 'lib/active_resource/persistent_http_mock.rb', line 57 def patch(path, body, headers) request = ActiveResource::Request.new(:patch, path, body, headers) self.class.requests << request if response = self.class.responses.assoc(request) response[1] else raise InvalidRequestError.new("Could not find a response recorded for \#{request.to_s} - Responses recorded are: \#{inspect_responses}") end end |
Instance Method Details
#request(uri, req) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/active_resource/persistent_http_mock.rb', line 31 def request(uri, req) headers = {} req.each_capitalized{ |k,v| headers[k] = v unless k == 'Accept' && v == '*/*' } request = ActiveResource::Request.new(req.method.downcase.to_sym, req.path, req.request_body_permitted? ? req.body : nil, headers) self.class.requests << request if response = self.class.responses.assoc(request) response[1] else raise ActiveResource::InvalidRequestError.new("Could not find a response recorded for\n #{request.inspect}\n - Responses recorded are:\n #{self.class.responses.map{|r| r.inspect}.join("\n ")}") end end |