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
-
#initialize(lhs, custom_matchers = {}) ⇒ Xml
constructor
A new instance of Xml.
- #match(actual) ⇒ Object
- #match_on(path, &blk) ⇒ Object
- #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.
14 15 16 17 18 |
# File 'lib/matcher/xml.rb', line 14 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.
12 13 14 |
# File 'lib/matcher/xml.rb', line 12 def custom_matchers @custom_matchers end |
#lhs ⇒ Object (readonly)
Returns the value of attribute lhs.
12 13 14 |
# File 'lib/matcher/xml.rb', line 12 def lhs @lhs end |
#results ⇒ Object (readonly)
Returns the value of attribute results.
12 13 14 |
# File 'lib/matcher/xml.rb', line 12 def results @results end |
#rhs ⇒ Object (readonly)
Returns the value of attribute rhs.
12 13 14 |
# File 'lib/matcher/xml.rb', line 12 def rhs @rhs end |
Instance Method Details
#match(actual) ⇒ Object
24 25 26 27 28 |
# File 'lib/matcher/xml.rb', line 24 def match(actual) @results.clear @rhs = parse(actual) compare(@lhs, @rhs) end |
#match_on(path, &blk) ⇒ Object
20 21 22 |
# File 'lib/matcher/xml.rb', line 20 def match_on(path, &blk) @custom_matchers[path] = blk end |
#matches ⇒ Object
43 44 45 |
# File 'lib/matcher/xml.rb', line 43 def matches results_that_are(true) end |
#mismatches ⇒ Object
47 48 49 |
# File 'lib/matcher/xml.rb', line 47 def mismatches results_that_are(false) end |
#record(path, result, expected, actual) ⇒ Object
30 31 32 33 34 35 |
# File 'lib/matcher/xml.rb', line 30 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
37 38 39 40 41 |
# File 'lib/matcher/xml.rb', line 37 def result_for(path) return "matched" if matches[path] return "mismatched" if mismatches[path] "unmatched" end |