Class: Webspicy::Tester::Result::ResponseHeaderMet
- Defined in:
- lib/webspicy/tester/result/response_header_met.rb
Instance Attribute Summary collapse
-
#expected ⇒ Object
readonly
Returns the value of attribute expected.
-
#header ⇒ Object
readonly
Returns the value of attribute header.
-
#strategy ⇒ Object
readonly
Returns the value of attribute strategy.
Attributes inherited from Check
Instance Method Summary collapse
- #behavior ⇒ Object
- #call ⇒ Object
-
#initialize(result, header, expected, strategy = :eq) ⇒ ResponseHeaderMet
constructor
A new instance of ResponseHeaderMet.
- #must? ⇒ Boolean
Methods inherited from Check
Constructor Details
#initialize(result, header, expected, strategy = :eq) ⇒ ResponseHeaderMet
Returns a new instance of ResponseHeaderMet.
6 7 8 9 10 11 12 13 14 |
# File 'lib/webspicy/tester/result/response_header_met.rb', line 6 def initialize(result, header, expected, strategy = :eq) unless [:eq, :start_with].include?(strategy) raise ArgumentError, "Invalid strategy `#{strategy.inspect}`" end super(result) @header = header @expected = expected @strategy = strategy end |
Instance Attribute Details
#expected ⇒ Object (readonly)
Returns the value of attribute expected.
15 16 17 |
# File 'lib/webspicy/tester/result/response_header_met.rb', line 15 def expected @expected end |
#header ⇒ Object (readonly)
Returns the value of attribute header.
15 16 17 |
# File 'lib/webspicy/tester/result/response_header_met.rb', line 15 def header @header end |
#strategy ⇒ Object (readonly)
Returns the value of attribute strategy.
15 16 17 |
# File 'lib/webspicy/tester/result/response_header_met.rb', line 15 def strategy @strategy end |
Instance Method Details
#behavior ⇒ Object
17 18 19 |
# File 'lib/webspicy/tester/result/response_header_met.rb', line 17 def behavior "It has a `#{header}: #{expected}` response header" end |
#call ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/webspicy/tester/result/response_header_met.rb', line 25 def call got = response.headers[header] if got.nil? _! "Expected response header `#{header}` to be set" else msg = "Expected response header `#{header}` to be `#{expected}`, got `#{got}`" case strategy when :eq _!(msg) unless expected == got when :start_with _!(msg) unless got.start_with?(expected) end end end |
#must? ⇒ Boolean
21 22 23 |
# File 'lib/webspicy/tester/result/response_header_met.rb', line 21 def must? true end |