Class: Rectory::Expectation
- Inherits:
-
Object
- Object
- Rectory::Expectation
- Defined in:
- lib/rectory/expectation.rb
Overview
The expectations for an HTTP request.
Instance Attribute Summary collapse
-
#code ⇒ Object
The expected HTTP status code.
-
#location ⇒ Object
The expected HTTP ‘Location` header, or the end location of a redirect.
-
#result ⇒ Object
A Rectory::Result instance which contains HTTP repsonse details.
-
#url ⇒ Object
The URL to test.
Instance Method Summary collapse
-
#initialize(url, args = {}) ⇒ Expectation
constructor
A new instance of Expectation.
-
#pass? ⇒ Boolean
Determines whether the HTTP result satifies the expectations.
Constructor Details
#initialize(url, args = {}) ⇒ Expectation
Returns a new instance of Expectation.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/rectory/expectation.rb', line 15 def initialize(url, args = {}) raise ArgumentError, "You must provide a URL to test!" if url.nil? defaults = { :code => 200, :result => {} } args = defaults.merge args self.url = url self.code = args[:code].to_i self.result = args[:result] self.location = args[:location] end |
Instance Attribute Details
#code ⇒ Object
The expected HTTP status code. (200, 302, 304, 404, 400, etc)
9 10 11 |
# File 'lib/rectory/expectation.rb', line 9 def code @code end |
#location ⇒ Object
The expected HTTP ‘Location` header, or the end location of a redirect. Should be `nil` if the expectation is not a redirect (200, 304, 404, etc)
9 10 11 |
# File 'lib/rectory/expectation.rb', line 9 def location @location end |
#result ⇒ Object
A Rectory::Result instance which contains HTTP repsonse details
9 10 11 |
# File 'lib/rectory/expectation.rb', line 9 def result @result end |
#url ⇒ Object
The URL to test
9 10 11 |
# File 'lib/rectory/expectation.rb', line 9 def url @url end |
Instance Method Details
#pass? ⇒ Boolean
Determines whether the HTTP result satifies the expectations
Verifies that both status code and location match
35 36 37 38 39 40 41 |
# File 'lib/rectory/expectation.rb', line 35 def pass? perform if result.empty? truths = [] truths << (result[:location].to_s.gsub(/\/$/, "") == location.to_s.gsub(/\/$/, "")) truths << (result[:code] == code.to_i) unless code.nil? truths.all? end |