Class: Matcher::Xml
- Inherits:
-
Object
- Object
- Matcher::Xml
- Defined in:
- lib/matcher/xml.rb
Constant Summary collapse
- NOT_FOUND =
"[Not found]"
- EXISTENCE =
"[Existence]"
- UNMATCHED =
"[Unmatched]"
Instance Attribute Summary collapse
-
#custom_matchers ⇒ Object
readonly
Returns the value of attribute custom_matchers.
-
#lhs ⇒ Object
readonly
Returns the value of attribute lhs.
-
#results ⇒ Object
readonly
Returns the value of attribute results.
-
#rhs ⇒ Object
readonly
Returns the value of attribute rhs.
Instance Method Summary collapse
- #evaluate(path, expected, actual) ⇒ Object
-
#initialize(lhs, custom_matchers = {}) ⇒ Xml
constructor
A new instance of Xml.
- #match(actual) ⇒ Object
- #match_on(path, options = {}, &blk) ⇒ Object (also: #on)
- #matches ⇒ Object
- #mismatches ⇒ Object
- #record(path, result, expected, actual) ⇒ Object
- #result_for(path) ⇒ Object
Constructor Details
#initialize(lhs, custom_matchers = {}) ⇒ Xml
Returns a new instance of Xml.
17 18 19 20 21 |
# File 'lib/matcher/xml.rb', line 17 def initialize(lhs, custom_matchers = {}) @lhs = parse(lhs) @custom_matchers = custom_matchers @results = {} end |
Instance Attribute Details
#custom_matchers ⇒ Object (readonly)
Returns the value of attribute custom_matchers.
15 16 17 |
# File 'lib/matcher/xml.rb', line 15 def custom_matchers @custom_matchers end |
#lhs ⇒ Object (readonly)
Returns the value of attribute lhs.
15 16 17 |
# File 'lib/matcher/xml.rb', line 15 def lhs @lhs end |
#results ⇒ Object (readonly)
Returns the value of attribute results.
15 16 17 |
# File 'lib/matcher/xml.rb', line 15 def results @results end |
#rhs ⇒ Object (readonly)
Returns the value of attribute rhs.
15 16 17 |
# File 'lib/matcher/xml.rb', line 15 def rhs @rhs end |
Instance Method Details
#evaluate(path, expected, actual) ⇒ Object
59 60 61 62 63 64 |
# File 'lib/matcher/xml.rb', line 59 def evaluate(path, expected, actual) custom_matcher = custom_matchers[path] match = custom_matcher ? evaluate_custom_matcher(custom_matcher, expected, actual) : expected == actual record(path, match, expected, actual) match end |
#match(actual) ⇒ Object
32 33 34 35 36 |
# File 'lib/matcher/xml.rb', line 32 def match(actual) @results.clear @rhs = parse(actual) compare(@lhs, @rhs) end |
#match_on(path, options = {}, &blk) ⇒ Object Also known as: on
23 24 25 26 27 28 |
# File 'lib/matcher/xml.rb', line 23 def match_on(path, = {}, &blk) raise ArgumentError.new("Using block AND options is not supported for custom matching") if blk && !.empty? excluding = [:excluding] raise ArgumentError.new "'excluding' option must be a regular expression" if excluding && !excluding.kind_of?(Regexp) @custom_matchers[path] = blk || end |
#matches ⇒ Object
51 52 53 |
# File 'lib/matcher/xml.rb', line 51 def matches results_that_are(true) end |
#mismatches ⇒ Object
55 56 57 |
# File 'lib/matcher/xml.rb', line 55 def mismatches results_that_are(false) end |
#record(path, result, expected, actual) ⇒ Object
38 39 40 41 42 43 |
# File 'lib/matcher/xml.rb', line 38 def record(path, result, expected, actual) # support 0 as true (for regex matches) r = (!result || result.nil?) ? false : true was_custom_matched = @custom_matchers[path] ? true : false @results[path] = OpenStruct.new(:result => r, :expected => expected, :actual => actual, :was_custom_matched => was_custom_matched) end |
#result_for(path) ⇒ Object
45 46 47 48 49 |
# File 'lib/matcher/xml.rb', line 45 def result_for(path) return "matched" if matches[path] return "mismatched" if mismatches[path] "unmatched" end |