Class: RSpec::Httpd::Client
- Inherits:
-
Object
- Object
- RSpec::Httpd::Client
- Defined in:
- lib/rspec/httpd/client.rb
Defined Under Namespace
Modules: ResponseParser
Instance Attribute Summary collapse
-
#host ⇒ Object
readonly
host and port.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
-
#request ⇒ Object
readonly
request, response, and status, set during a request/response cycle.
-
#response ⇒ Object
readonly
Returns the value of attribute response.
Instance Method Summary collapse
-
#delete(url, headers: {}) ⇒ Object
A DELETE request.
-
#get(url, headers: {}) ⇒ Object
A GET request.
-
#head(url, headers: {}) ⇒ Object
A HEAD request.
-
#initialize(host:, port:) ⇒ Client
constructor
A new instance of Client.
-
#post(url, body, headers: {}) ⇒ Object
A POST request.
-
#put(url, body, headers: {}) ⇒ Object
A PUT request.
-
#result ⇒ Object
returns the parsed response of the latest request.
- #status ⇒ Object
Constructor Details
#initialize(host:, port:) ⇒ Client
Returns a new instance of Client.
38 39 40 |
# File 'lib/rspec/httpd/client.rb', line 38 def initialize(host:, port:) @host, @port = host, port end |
Instance Attribute Details
#host ⇒ Object (readonly)
host and port. Set at initialization
35 36 37 |
# File 'lib/rspec/httpd/client.rb', line 35 def host @host end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
36 37 38 |
# File 'lib/rspec/httpd/client.rb', line 36 def port @port end |
#request ⇒ Object (readonly)
request, response, and status, set during a request/response cycle
43 44 45 |
# File 'lib/rspec/httpd/client.rb', line 43 def request @request end |
#response ⇒ Object (readonly)
Returns the value of attribute response.
44 45 46 |
# File 'lib/rspec/httpd/client.rb', line 44 def response @response end |
Instance Method Details
#delete(url, headers: {}) ⇒ Object
A DELETE request
76 77 78 |
# File 'lib/rspec/httpd/client.rb', line 76 def delete(url, headers: {}) run_request(::Net::HTTP::Delete, url, body: nil, headers: headers) end |
#get(url, headers: {}) ⇒ Object
A GET request
56 57 58 |
# File 'lib/rspec/httpd/client.rb', line 56 def get(url, headers: {}) run_request(::Net::HTTP::Get, url, body: nil, headers: headers) end |
#head(url, headers: {}) ⇒ Object
A HEAD request
61 62 63 |
# File 'lib/rspec/httpd/client.rb', line 61 def head(url, headers: {}) run_request(::Net::HTTP::Head, url, body: nil, headers: headers) end |
#post(url, body, headers: {}) ⇒ Object
A POST request
66 67 68 |
# File 'lib/rspec/httpd/client.rb', line 66 def post(url, body, headers: {}) run_request(::Net::HTTP::Post, url, body: body, headers: headers) end |
#put(url, body, headers: {}) ⇒ Object
A PUT request
71 72 73 |
# File 'lib/rspec/httpd/client.rb', line 71 def put(url, body, headers: {}) run_request(::Net::HTTP::Put, url, body: body || {}, headers: headers) end |
#result ⇒ Object
returns the parsed response of the latest request
51 52 53 |
# File 'lib/rspec/httpd/client.rb', line 51 def result @result ||= ResponseParser.parse(response) end |
#status ⇒ Object
46 47 48 |
# File 'lib/rspec/httpd/client.rb', line 46 def status Integer(response.code) end |