Sha256: 45d68317c2582470fbc81e95b9a9cb845b69bd93a3d51faf63f08c5995bae1bf

Contents?: true

Size: 1.26 KB

Versions: 6

Compression:

Stored size: 1.26 KB

Contents

module Outpost
  module Expectations
    # 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.
    module ResponseBody
      # Installs the response body expectation
      def self.extended(base)
        base.expect :response_body, base.method(:evaluate_response_body)
      end

      # Method that will be used as an expectation to evaluate response body
      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
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
outpost-0.2.5 lib/outpost/expectations/response_body.rb
outpost-0.2.4 lib/outpost/expectations/response_body.rb
outpost-0.2.3 lib/outpost/expectations/response_body.rb
outpost-0.2.2 lib/outpost/expectations/response_body.rb
outpost-0.2.1 lib/outpost/expectations/response_body.rb
outpost-0.2.0 lib/outpost/expectations/response_body.rb