Class: Webspicy::Tester::Result::ResponseHeaderMet

Inherits:
Check
  • Object
show all
Defined in:
lib/webspicy/tester/result/response_header_met.rb

Instance Attribute Summary collapse

Attributes inherited from Check

#result

Instance Method Summary collapse

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

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

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

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

#behaviorObject



17
18
19
# File 'lib/webspicy/tester/result/response_header_met.rb', line 17

def behavior
  "It has a `#{header}: #{expected}` response header"
end

#callObject



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

Returns:

  • (Boolean)


21
22
23
# File 'lib/webspicy/tester/result/response_header_met.rb', line 21

def must?
  true
end