Class: RSpec::Httpd::Client
- Inherits:
-
Object
- Object
- RSpec::Httpd::Client
- Defined in:
- lib/rspec/httpd/client.rb
Defined Under Namespace
Modules: ResponseParser Classes: HeadersHash
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.
-
#headers ⇒ Object
returns the headers of the latest response.
-
#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.
10 11 12 |
# File 'lib/rspec/httpd/client.rb', line 10 def initialize(host:, port:) @host, @port = host, port end |
Instance Attribute Details
#host ⇒ Object (readonly)
host and port. Set at initialization
7 8 9 |
# File 'lib/rspec/httpd/client.rb', line 7 def host @host end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
8 9 10 |
# File 'lib/rspec/httpd/client.rb', line 8 def port @port end |
#request ⇒ Object (readonly)
request, response, and status, set during a request/response cycle
15 16 17 |
# File 'lib/rspec/httpd/client.rb', line 15 def request @request end |
#response ⇒ Object (readonly)
Returns the value of attribute response.
16 17 18 |
# File 'lib/rspec/httpd/client.rb', line 16 def response @response end |
Instance Method Details
#delete(url, headers: {}) ⇒ Object
A DELETE request
48 49 50 |
# File 'lib/rspec/httpd/client.rb', line 48 def delete(url, headers: {}) run_request(::Net::HTTP::Delete, url, body: nil, headers: headers) end |
#get(url, headers: {}) ⇒ Object
A GET request
33 34 35 |
# File 'lib/rspec/httpd/client.rb', line 33 def get(url, headers: {}) run_request(::Net::HTTP::Get, url, body: nil, headers: headers) end |
#headers ⇒ Object
returns the headers of the latest response
23 24 25 |
# File 'lib/rspec/httpd/client.rb', line 23 def headers @headers ||= HeadersHash.new(response) end |
#post(url, body, headers: {}) ⇒ Object
A POST request
38 39 40 |
# File 'lib/rspec/httpd/client.rb', line 38 def post(url, body, headers: {}) run_request(::Net::HTTP::Post, url, body: body, headers: headers) end |
#put(url, body, headers: {}) ⇒ Object
A PUT request
43 44 45 |
# File 'lib/rspec/httpd/client.rb', line 43 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
28 29 30 |
# File 'lib/rspec/httpd/client.rb', line 28 def result @result ||= ResponseParser.parse(response) end |
#status ⇒ Object
18 19 20 |
# File 'lib/rspec/httpd/client.rb', line 18 def status Integer(response.code) end |