Class: Hyperion::Kim::Matcher
- Inherits:
-
Object
- Object
- Hyperion::Kim::Matcher
- Defined in:
- lib/hyperion_test/kim/matcher.rb
Instance Attribute Summary collapse
-
#func ⇒ Object
readonly
Fancy predicates for HTTP requests.
Class Method Summary collapse
Instance Method Summary collapse
- #and(other) ⇒ Object
- #call(req) ⇒ Object
-
#initialize(func = nil, &block) ⇒ Matcher
constructor
A new instance of Matcher.
- #not ⇒ Object
- #or(other) ⇒ Object
Constructor Details
Instance Attribute Details
#func ⇒ Object (readonly)
Fancy predicates for HTTP requests. Features:
-
and/or/not combinators
-
If a predicate raises an error, it is caught and treated as falsey. simplifies predicates. For example: headers.starts_with?(‘application/’) will raise if no Allow header was sent, however we really just want to treat that as a non-match.
-
Parameter extraction. A matcher can return an augmented Request as the truthy value.
13 14 15 |
# File 'lib/hyperion_test/kim/matcher.rb', line 13 def func @func end |
Class Method Details
.and(*ms) ⇒ Object
41 42 43 44 45 46 47 48 |
# File 'lib/hyperion_test/kim/matcher.rb', line 41 def self.and(*ms) m, *rest = ms if rest.empty? m else m.and(Matcher.and(*rest)) end end |
Instance Method Details
#and(other) ⇒ Object
23 24 25 26 27 |
# File 'lib/hyperion_test/kim/matcher.rb', line 23 def and(other) Matcher.new do |req| (req2 = @func.call(req)) && other.call(req2) end end |
#call(req) ⇒ Object
19 20 21 |
# File 'lib/hyperion_test/kim/matcher.rb', line 19 def call(req) @func.call(req) end |