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
23 24 25 |
# File 'lib/rc_rest/net_http_stub.rb', line 23 def params @params end |
.paths ⇒ Object
Records POST paths
28 29 30 |
# File 'lib/rc_rest/net_http_stub.rb', line 28 def paths @paths end |
.responses ⇒ Object
Holds POST body responses
33 34 35 |
# File 'lib/rc_rest/net_http_stub.rb', line 33 def responses @responses end |
Class Method Details
.start(host, port) {|Net::HTTP.new(host)| ... } ⇒ Object
Override Net::HTTP::start to not connect
42 43 44 |
# File 'lib/rc_rest/net_http_stub.rb', line 42 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
51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/rc_rest/net_http_stub.rb', line 51 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 |