Sha256: 2c07f37ed333f6fc8c11a9bf34dc1c238b1588bd9e30af309c45ccf44ea67cc8

Contents?: true

Size: 1.24 KB

Versions: 1

Compression:

Stored size: 1.24 KB

Contents

class ExpectationMatcher
  require 'result'
  require 'nokogiri'
  require 'JSON'
  require 'checker'
  require 'json_syntax_checker'
  require 'header_checker'
  require 'response_code_checker'
  require 'body_checker'

  def initialize(excludes=nil)
    @test_types = [:response_code, :response_body_format, :response_headers, :response_body]
    @excludes = excludes || []
  end

  # returns the available test types if this matcher class
  def test_types
    return @test_types
  end

  # dispatches incoming matching requests
  def check(method, response, testcase)
    self.send(method, response, testcase)
  end

  protected

  # matches the given response code
  def response_code(response, testcase)
    ResponseCodeChecker.new(testcase, response).check
  end

  # checks the format of the given data of JSON conformity
  def response_body_format(response, testcase)
    JsonSyntaxChecker.new(testcase, response).check
  end

  # matches the given response header
  def response_headers(response, testcase)
    HeaderChecker.new(testcase, response, @excludes).check
  end

  # matches the given attributes and values against the ones from the response body
  def response_body(response, testcase)
    BodyChecker.new(testcase, response, @excludes).check
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
apirunner-0.2.5 lib/expectation_matcher.rb