xmatch 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -26,10 +26,10 @@ A matcher provides access to the match information by xpath values:
26
26
 
27
27
  Custom matchers
28
28
  ---------------
29
- The actual value of some xml elements are hard to know in advance, timestamps and ids being typical examples. XMatch allows custom matches to be applied
30
- to provide a good guess at a match in advance of the match being run. Custom matchers are Ruby procs.
29
+ The actual values of some xml elements are hard to know in advance (timestamps and ids being typical examples). XMatch allows custom matchers to be applied
30
+ to provide a good guess at a match in advance of the match being run. Custom matchers are Ruby Procs that take the element to match as an argument. They are identified by the xpath of the element they should be applied to.
31
31
 
32
- custom_matchers = "/bookstore/@id" => lambda {|elem| elem.value == '2'}
32
+ custom_matchers = { "/bookstore/@id" => lambda {|elem| elem.value =~ /\d+/} }
33
33
  xml = Matcher::Xml.new("<bookstore id='1'></bookstore>", custom_matchers)
34
34
  xml.match("<bookstore id='2'></bookstore>") # ==> true
35
35
 
@@ -20,6 +20,7 @@ module Matcher
20
20
  match_data << match_info_for(elem)
21
21
  elem.attributes.values.each { | attr | match_data << match_info_for(attr) }
22
22
  end
23
+ match_data.sort! {|a, b| a.line <=> b.line}
23
24
 
24
25
  FileUtils.mkdir_p(@report_dir)
25
26
  File.open(File.join(@report_dir, "xmatch.html"), 'w') { |f| f.write(generate_html(match_data)) }
@@ -29,7 +30,8 @@ module Matcher
29
30
 
30
31
  def match_info_for(elem)
31
32
  result = @matcher.result_for(elem.path)
32
- OpenStruct.new(:result => result, :line => elem.line, :path => elem.path, :message => @matcher.mismatches[elem.path])
33
+ message = result == "unmatched" ? "Unmatched" : @matcher.mismatches[elem.path]
34
+ OpenStruct.new(:result => result, :line => elem.line, :path => elem.path, :message => message)
33
35
  end
34
36
 
35
37
  def generate_html(data)
@@ -5,10 +5,10 @@ module Nokogiri
5
5
  module XML
6
6
 
7
7
  class Node
8
-
8
+
9
9
  def matching(other, matcher)
10
10
  other_elem = other.at_xpath(path)
11
- matcher.record(self, false, "not found") unless other_elem
11
+ matcher.record(self, false, Matcher::Xml::NOT_FOUND) unless other_elem
12
12
  other_elem
13
13
  end
14
14
  end
@@ -1,3 +1,3 @@
1
1
  module Representative
2
- VERSION = "0.1.2".freeze
2
+ VERSION = "0.1.3".freeze
3
3
  end
@@ -4,6 +4,8 @@ require 'ostruct'
4
4
  module Matcher
5
5
 
6
6
  class Xml
7
+
8
+ NOT_FOUND = "Not found compared document"
7
9
 
8
10
  attr_reader :lhs, :rhs, :custom_matchers
9
11
 
@@ -101,7 +101,7 @@ describe Matcher::Xml do
101
101
  </book>
102
102
  </bookstore>
103
103
  eos
104
- verify_mismatch("/bookstore/book/title", "not found", 2)
104
+ verify_mismatch("/bookstore/book/title", Matcher::Xml::NOT_FOUND, 2)
105
105
  end
106
106
 
107
107
  end
@@ -116,7 +116,7 @@ describe Matcher::Xml do
116
116
  </bookx>
117
117
  </bookstore>
118
118
  eos
119
- verify_mismatch("/bookstore/book", "not found", 3)
119
+ verify_mismatch("/bookstore/book", Matcher::Xml::NOT_FOUND, 3)
120
120
  end
121
121
 
122
122
  end
@@ -131,7 +131,7 @@ describe Matcher::Xml do
131
131
  </book>
132
132
  </bookstore>
133
133
  eos
134
- verify_mismatch("/bookstore/book/@category", "not found")
134
+ verify_mismatch("/bookstore/book/@category", Matcher::Xml::NOT_FOUND)
135
135
  end
136
136
 
137
137
  it "should not match when an attribute value doesn't match" do
@@ -253,7 +253,7 @@ describe Matcher::Xml do
253
253
  eos
254
254
 
255
255
  @xml = Matcher::Xml.new(lhs)
256
- verify_mismatch("/bookstore/book[2]/@category", "not found")
256
+ verify_mismatch("/bookstore/book[2]/@category", Matcher::Xml::NOT_FOUND)
257
257
  end
258
258
 
259
259
  context 'matches' do
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: xmatch
3
3
  version: !ruby/object:Gem::Version
4
- hash: 31
4
+ hash: 29
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 2
10
- version: 0.1.2
9
+ - 3
10
+ version: 0.1.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Peter Moran