Class: Net::HTTP
- Inherits:
-
Object
- Object
- Net::HTTP
- Defined in:
- lib/rc_rest/net_http_stub.rb
Class Attribute Summary collapse
-
.params ⇒ Object
Records submitted POST params.
-
.paths ⇒ Object
Records POST paths.
-
.responses ⇒ Object
Holds POST body responses.
Class Method Summary collapse
-
.start(host, port) {|Net::HTTP.new(host)| ... } ⇒ Object
Override Net::HTTP::start to not connect.
Instance Method Summary collapse
-
#request(req) ⇒ Object
Override Net::HTTP#request to fake its results.
Class Attribute Details
.params ⇒ Object
Records submitted POST params
26 27 28 |
# File 'lib/rc_rest/net_http_stub.rb', line 26 def params @params end |
.paths ⇒ Object
Records POST paths
31 32 33 |
# File 'lib/rc_rest/net_http_stub.rb', line 31 def paths @paths end |
.responses ⇒ Object
Holds POST body responses
36 37 38 |
# File 'lib/rc_rest/net_http_stub.rb', line 36 def responses @responses end |
Class Method Details
.start(host, port) {|Net::HTTP.new(host)| ... } ⇒ Object
Override Net::HTTP::start to not connect
45 46 47 |
# File 'lib/rc_rest/net_http_stub.rb', line 45 def self.start(host, port) yield Net::HTTP.new(host) end |
Instance Method Details
#request(req) ⇒ Object
Override Net::HTTP#request to fake its results
54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/rc_rest/net_http_stub.rb', line 54 def request(req) self.class.paths << req.path self.class.params << req.body response = self.class.responses.shift if response.respond_to? :call then response.call req else res = Net::HTTPResponse.new '1.0', 200, 'OK' res.body = response res end end |