Class: FakeWeb::Responder
- Inherits:
-
Object
- Object
- FakeWeb::Responder
- Defined in:
- lib/fake_web/responder.rb
Overview
:nodoc:
Constant Summary collapse
- KNOWN_OPTIONS =
[:body, :exception, :response, :status].freeze
Instance Attribute Summary collapse
-
#method ⇒ Object
Returns the value of attribute method.
-
#options ⇒ Object
Returns the value of attribute options.
-
#times ⇒ Object
Returns the value of attribute times.
-
#uri ⇒ Object
Returns the value of attribute uri.
Instance Method Summary collapse
-
#initialize(method, uri, options, times) ⇒ Responder
constructor
A new instance of Responder.
- #response {|response| ... } ⇒ Object
Constructor Details
#initialize(method, uri, options, times) ⇒ Responder
Returns a new instance of Responder.
7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/fake_web/responder.rb', line 7 def initialize(method, uri, , times) self.method = method self.uri = uri self. = self.times = times ? times : 1 if .has_key?(:file) || .has_key?(:string) [:body] = .delete(:file) || .delete(:string) end end |
Instance Attribute Details
#method ⇒ Object
Returns the value of attribute method.
4 5 6 |
# File 'lib/fake_web/responder.rb', line 4 def method @method end |
#options ⇒ Object
Returns the value of attribute options.
4 5 6 |
# File 'lib/fake_web/responder.rb', line 4 def @options end |
#times ⇒ Object
Returns the value of attribute times.
4 5 6 |
# File 'lib/fake_web/responder.rb', line 4 def times @times end |
#uri ⇒ Object
Returns the value of attribute uri.
4 5 6 |
# File 'lib/fake_web/responder.rb', line 4 def uri @uri end |
Instance Method Details
#response {|response| ... } ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/fake_web/responder.rb', line 19 def response(&block) if has_baked_response? response = baked_response else code, msg = response = Net::HTTPResponse.send(:response_class, code.to_s).new("1.0", code.to_s, msg) response.instance_variable_set(:@body, body) .each do |name, value| if value.respond_to?(:each) value.each { |v| response.add_field(name, v) } else response[name] = value end end end response.instance_variable_set(:@read, true) response.extend FakeWeb::Response optionally_raise(response) yield response if block_given? response end |