Module: Outpost::Expectations::ResponseBody

Included in:
Scouts::Http
Defined in:
lib/outpost/expectations/response_body.rb

Overview

Module containing response_body matching expectations. Extend your Scout with ResponseBody and it will gain response_body evaluation powers!

It respond to the following rules:

  • match => If the response body matches the associated regular expression

  • not_match => If the response body does not match the associated regular expression

  • equals => If the response body matches exactly the associated string

  • differs => If the response body differs in any way the associated string.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.extended(base) ⇒ Object

Installs the response body expectation


15
16
17
# File 'lib/outpost/expectations/response_body.rb', line 15

def self.extended(base)
  base.expect :response_body, base.method(:evaluate_response_body)
end

Instance Method Details

#evaluate_response_body(scout, rules) ⇒ Object

Method that will be used as an expectation to evaluate response body


20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/outpost/expectations/response_body.rb', line 20

def evaluate_response_body(scout, rules)
  rules.all? do |rule, comparison|
    case rule
    when :match
      scout.response_body =~ comparison
    when :not_match
      scout.response_body !~ comparison
    when :equals
      scout.response_body == comparison
    when :differs
      scout.response_body != comparison
    end
  end
end