Class: Net::HTTP

Inherits:
Object
  • Object
show all
Defined in:
lib/rc_rest/net_http_stub.rb

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Class Attribute Details

.paramsObject

Records submitted POST params



26
27
28
# File 'lib/rc_rest/net_http_stub.rb', line 26

def params
  @params
end

.pathsObject

Records POST paths



31
32
33
# File 'lib/rc_rest/net_http_stub.rb', line 31

def paths
  @paths
end

.responsesObject

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

Yields:



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