xmatch 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +3 -3
- data/lib/matcher/html_formatter.rb +3 -1
- data/lib/matcher/nokogiri_extensions.rb +2 -2
- data/lib/matcher/version.rb +1 -1
- data/lib/matcher/xml.rb +2 -0
- data/spec/matcher/xml_spec.rb +4 -4
- metadata +3 -3
data/README.markdown
CHANGED
@@ -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
|
30
|
-
to provide a good guess at a match in advance of the match being run. Custom matchers are Ruby
|
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
|
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
|
-
|
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,
|
11
|
+
matcher.record(self, false, Matcher::Xml::NOT_FOUND) unless other_elem
|
12
12
|
other_elem
|
13
13
|
end
|
14
14
|
end
|
data/lib/matcher/version.rb
CHANGED
data/lib/matcher/xml.rb
CHANGED
data/spec/matcher/xml_spec.rb
CHANGED
@@ -101,7 +101,7 @@ describe Matcher::Xml do
|
|
101
101
|
</book>
|
102
102
|
</bookstore>
|
103
103
|
eos
|
104
|
-
verify_mismatch("/bookstore/book/title",
|
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",
|
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",
|
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",
|
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:
|
4
|
+
hash: 29
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 3
|
10
|
+
version: 0.1.3
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Peter Moran
|