module Hyperion::Kim::Matchers
Public Instance Methods
req_headers(required_headers)
click to toggle source
# File lib/hyperion_test/kim/matchers.rb, line 23 def req_headers(required_headers) Matcher.new do |req| required_headers.each_pair.all? do |(k, v)| hash_includes?(req.headers.to_h, k, v) end end end
req_params(required_params)
click to toggle source
# File lib/hyperion_test/kim/matchers.rb, line 31 def req_params(required_params) Matcher.new do |req| required_params.each_pair.all? do |(k, v)| hash_includes?(req.params.to_h, k, v) end end end
res(resource_pattern)
click to toggle source
Some useful matchers to include in your code
# File lib/hyperion_test/kim/matchers.rb, line 9 def res(resource_pattern) regex = resource_pattern.gsub(/:([^\/]+)/, "(?<\\1>[^\\/]+)") Matcher.new do |req| m = req.path.match(regex) m && req.merge_params(m.names.zip(m.captures).to_h) end end
verb(verb_to_match)
click to toggle source
# File lib/hyperion_test/kim/matchers.rb, line 17 def verb(verb_to_match) Matcher.new do |req| req.verb.to_s.upcase == verb_to_match.to_s.upcase end end
Private Instance Methods
hash_includes?(h, k, v)
click to toggle source
# File lib/hyperion_test/kim/matchers.rb, line 41 def hash_includes?(h, k, v) (h.keys.include?(k.to_s) || h.keys.include?(k.to_sym)) && (v.nil? || (h[k.to_s] || h[k.to_sym]) == v) end