Class: RSpec::Httpd::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/rspec/httpd/client.rb

Defined Under Namespace

Modules: ResponseParser

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#hostObject (readonly)

host and port. Set at initialization



35
36
37
# File 'lib/rspec/httpd/client.rb', line 35

def host
  @host
end

#portObject (readonly)

Returns the value of attribute port.



36
37
38
# File 'lib/rspec/httpd/client.rb', line 36

def port
  @port
end

#requestObject (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

#responseObject (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

#resultObject

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

#statusObject



46
47
48
# File 'lib/rspec/httpd/client.rb', line 46

def status
  Integer(response.code)
end