Sha256: f575606216af664a36b7f3db66e31c5d1273051b54925f2d4d6c3754fb91797f
Contents?: true
Size: 1.86 KB
Versions: 4
Compression:
Stored size: 1.86 KB
Contents
class Checker @@children = [] def initialize(testcase, response, excludes=nil) @testcase = testcase @response = response @excludes = excludes end # executes the checking routine and returns a result object # to be overwritten in child classes def check result = Result.new(@testcase, @response) end # returns a list of symbolized plugin names def self.available_plugins return @@children.map{ |child| child.to_s } end private # tracks all children of this class # this way plugins can be loaded automagically def self.inherited(child) @@children << child end # returns true if given attributes is an excluded item that does not have to be evaluated in this environment def excluded?(item) @excludes.include?(item) end def is_number_comparison?(string) return false unless string string.match(/^[><]\s*\d+\s*$/) || string.match(/^[<>=]=\s*\d+\s*$/) end def compare_number(expectation, value) return false unless value && value.match(/[\d\.]+/) eval "#{value}#{expectation}" end # returns true if given string seems to be a regular expression def is_regex?(string) string.to_s.match(/^\/.+\/$/) end # returns true if the given regular expression matches the given value def regex_matches?(regex, value) regex = Regexp.compile( regex.gsub(/^\//, '').gsub(/\/$/,'') ) !!value.to_s.match(regex) end # returns true if the given string exactly matches the given value def string_matches?(string, value) string.to_s == value.to_s end # parses output into JSON object def valid_json?(response_body) # responses may be nil, return true then return true if response_body.nil? or response_body == {} or response_body == "" or response_body == " " # returns true if given response is valid json, else false JSON.parse(response_body.to_s) rescue false end end
Version data entries
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
apirunner-0.4.10 | lib/checker.rb |
apirunner-0.4.9 | lib/checker.rb |
apirunner-0.4.8 | lib/checker.rb |
apirunner-0.4.7 | lib/checker.rb |