xmatch 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +1 -1
- data/lib/matcher/html_formatter.rb +16 -8
- data/lib/matcher/version.rb +1 -1
- data/lib/matcher/xmatch.html.erb +3 -1
- data/lib/matcher/xml.rb +2 -2
- data/spec/matcher/xml_spec.rb +4 -0
- metadata +3 -3
data/Rakefile
CHANGED
@@ -27,5 +27,5 @@ task :match, :lhs, :rhs do |t, args|
|
|
27
27
|
puts "** Matching #{args[:lhs]} with #{args[:rhs]}"
|
28
28
|
xml = Matcher::Xml.new(File.read(args[:lhs]))
|
29
29
|
xml.match(File.read(args[:rhs]))
|
30
|
-
Matcher::HtmlFormatter.new(xml).format
|
30
|
+
Matcher::HtmlFormatter.new(xml, :prefix => "test").format
|
31
31
|
end
|
@@ -11,6 +11,7 @@ module Matcher
|
|
11
11
|
def initialize(matcher, args = {})
|
12
12
|
@matcher = matcher
|
13
13
|
@report_dir = args[:report_dir] || '/tmp/xmatch'
|
14
|
+
@prefix = args[:prefix]
|
14
15
|
end
|
15
16
|
|
16
17
|
def format
|
@@ -23,7 +24,9 @@ module Matcher
|
|
23
24
|
match_data.sort! {|a, b| a.line <=> b.line}
|
24
25
|
|
25
26
|
FileUtils.mkdir_p(@report_dir)
|
26
|
-
|
27
|
+
filename = "xmatch.html"
|
28
|
+
filename = "#{@prefix}-xmatch.html" if @prefix
|
29
|
+
File.open(File.join(@report_dir, filename), 'w') { |f| f.write(generate_html(match_data)) }
|
27
30
|
end
|
28
31
|
|
29
32
|
private
|
@@ -37,26 +40,31 @@ module Matcher
|
|
37
40
|
def generate_html(data)
|
38
41
|
actual_filename = create_actual_file
|
39
42
|
expected_filename = create_expected_file
|
40
|
-
xml = @matcher
|
43
|
+
xml = @matcher
|
44
|
+
completedness = compute_completedness
|
41
45
|
match_info = data
|
42
46
|
html = ERB.new(File.read(TEMPLATE))
|
43
47
|
html.result(binding)
|
44
48
|
end
|
45
49
|
|
50
|
+
def compute_completedness
|
51
|
+
(@matcher.matches.size.to_f / @matcher.results.size.to_f * 100).to_i
|
52
|
+
end
|
53
|
+
|
46
54
|
def create_expected_file
|
47
|
-
write_xml("expected
|
55
|
+
write_xml("expected", @matcher.lhs)
|
48
56
|
end
|
49
57
|
|
50
58
|
def create_actual_file
|
51
|
-
write_xml("actual
|
59
|
+
write_xml("actual", @matcher.rhs)
|
52
60
|
end
|
53
61
|
|
54
62
|
def write_xml(name, xml)
|
55
|
-
|
56
|
-
|
63
|
+
file_name = "#{name}-#{Time.now.to_i}.xml"
|
64
|
+
file_name = "#{@prefix}-#{file_name}" if @prefix
|
65
|
+
File.open(File.join(@report_dir, file_name), 'w') { |f| f.write(xml)}
|
66
|
+
file_name
|
57
67
|
end
|
58
|
-
|
59
|
-
|
60
68
|
|
61
69
|
end
|
62
70
|
|
data/lib/matcher/version.rb
CHANGED
data/lib/matcher/xmatch.html.erb
CHANGED
@@ -26,7 +26,9 @@
|
|
26
26
|
<body>
|
27
27
|
|
28
28
|
<h2>XMatch Report</h2>
|
29
|
-
<p><%= xml.mismatches.size %> mismatches found
|
29
|
+
<p><%= xml.mismatches.size %> mismatches found from <%= xml.results.size %> elements.<br/>
|
30
|
+
Expected xml document is <b><%= completedness %>%</b> 'matched'.
|
31
|
+
</p>
|
30
32
|
<p><a href='<%=expected_filename%>'>Expected xml</a> | <a href='<%=actual_filename%>'>Actual xml</a></p>
|
31
33
|
|
32
34
|
<table border="0" cellspacing="2" cellpadding="5">
|
data/lib/matcher/xml.rb
CHANGED
@@ -5,9 +5,9 @@ module Matcher
|
|
5
5
|
|
6
6
|
class Xml
|
7
7
|
|
8
|
-
NOT_FOUND = "Not found compared document"
|
8
|
+
NOT_FOUND = "Not found in compared document"
|
9
9
|
|
10
|
-
attr_reader :lhs, :rhs, :custom_matchers
|
10
|
+
attr_reader :lhs, :rhs, :custom_matchers, :results
|
11
11
|
|
12
12
|
def initialize(lhs, custom_matchers = {})
|
13
13
|
@lhs = parse(lhs)
|
data/spec/matcher/xml_spec.rb
CHANGED
@@ -203,6 +203,10 @@ describe Matcher::Xml do
|
|
203
203
|
Matcher::Xml.new(@lhs).mismatches.should be_empty
|
204
204
|
end
|
205
205
|
|
206
|
+
it "provides all results" do
|
207
|
+
Matcher::Xml.new(@lhs).results.should be_empty
|
208
|
+
end
|
209
|
+
|
206
210
|
it "should be reset when rematching" do
|
207
211
|
rhs = <<-eos
|
208
212
|
<bookstore>
|
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: 19
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 4
|
10
|
+
version: 0.1.4
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Peter Moran
|