xmatch 0.2.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -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
+ @generated_xml_dir = File.join(@report_dir, "generated_xml")
14
15
  @prefix = args[:prefix]
15
16
  end
16
17
 
@@ -21,15 +22,17 @@ module Matcher
21
22
  match_data << match_info_for(elem)
22
23
  elem.attributes.values.each { | attr | match_data << match_info_for(attr) }
23
24
  end
24
- match_data.sort! {|a, b| a.line <=> b.line}
25
-
26
- FileUtils.mkdir_p(@report_dir)
27
- filename = @prefix ? "#{@prefix}-xmatch.html" : "xmatch.html"
28
- File.open(File.join(@report_dir, filename), 'w') { |f| f.write(generate_html(match_data)) }
25
+ create_report(match_data.sort {|a, b| a.line <=> b.line})
29
26
  end
30
27
 
31
28
  private
32
29
 
30
+ def create_report(match_data)
31
+ FileUtils.mkdir_p(@generated_xml_dir)
32
+ html = generate_html(match_data, create_expected_file, create_actual_file)
33
+ File.open(File.join(@report_dir, prefixed("xmatch.html")), 'w') { |f| f.write(html) }
34
+ end
35
+
33
36
  def match_info_for(elem)
34
37
  info = @matcher.results[elem.path]
35
38
  result = @matcher.result_for(elem.path)
@@ -41,12 +44,9 @@ module Matcher
41
44
  :custom_matched => info ? info.was_custom_matched : false)
42
45
  end
43
46
 
44
- def generate_html(data)
45
- actual_filename = create_actual_file
46
- expected_filename = create_expected_file
47
+ def generate_html(match_info, expected_filename, actual_filename)
47
48
  xml = @matcher
48
49
  completedness = compute_completedness
49
- match_info = data
50
50
  html = ERB.new(File.read(TEMPLATE))
51
51
  html.result(binding)
52
52
  end
@@ -64,10 +64,13 @@ module Matcher
64
64
  end
65
65
 
66
66
  def write_xml(name, xml)
67
- file_name = "#{name}-#{Time.now.to_i}.xml"
68
- file_name = "#{@prefix}-#{file_name}" if @prefix
69
- File.open(File.join(@report_dir, file_name), 'w') { |f| f.write(xml)}
70
- file_name
67
+ path = File.join(@generated_xml_dir, prefixed("#{name}-#{Time.now.to_i}.xml"))
68
+ File.open(path, 'w') { |f| f.write(xml)}
69
+ path
70
+ end
71
+
72
+ def prefixed(name)
73
+ @prefix ? "#{@prefix}-#{name}" : name
71
74
  end
72
75
 
73
76
  end
@@ -1,3 +1,3 @@
1
1
  module Representative
2
- VERSION = "0.2.1".freeze
2
+ VERSION = "0.3.0".freeze
3
3
  end
@@ -1,56 +1,195 @@
1
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
2
- "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3
-
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
2
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
4
3
  <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
5
- <head>
6
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
4
+ <head>
5
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
6
+ <title>
7
+ XMatch Report
8
+ </title>
9
+ <style type="text/css">
10
+ /***************STRUCTURE***************************/
11
+ /*Reset*/
12
+ * {
13
+ margin:0;
14
+ }
15
+
16
+ body {
17
+ min-width:640px;
18
+ }
19
+ /* Absolute positioned header for all browsers*/
20
+ #header-wrapper {
21
+ position:absolute;
22
+ top:0;
23
+ left:0;
24
+ width:100%;
25
+ height:6em;
26
+ }
27
+ /* Reset header position to fixed for real browsers such as Firefox*/
28
+ body>#header-wrapper {
29
+ position:fixed;
30
+ }
31
+
32
+ #header {
33
+ height:8em;
34
+ margin:0 auto;
35
+ }
36
+
37
+ #content-wrapper {
38
+ padding:6em 0 0 0;
39
+ margin-left:0;
40
+ margin-top: 30px;
41
+ voice-family: "\"}\"";
42
+ voice-family:inherit;
43
+ margin-left:16px;
44
+ padding-bottom:60px;
45
+ }
46
+
47
+ body>#content-wrapper {
48
+ margin-left:0;
49
+ }
50
+
51
+ #content {
52
+ margin:0 auto;
53
+ }
54
+
55
+ #footer-wrapper {
56
+ width:100%;
57
+ position:absolute;
58
+ bottom:0;
59
+ left:0;
60
+ height:30px;
61
+ }
62
+
63
+ body>#footer-wrapper {
64
+ position:fixed;
65
+ }
66
+
67
+ #footer {
68
+ height:40px;
69
+ margin:0 auto;
70
+ font-size: 12px;
71
+ }
7
72
 
8
- <title>XMatch Report</title>
9
-
10
- <style type="text/css">
11
- body { background-color: #fff; color: #333; }
73
+ /***************STYLE***************************/
74
+ body,
75
+ html{
76
+ font-family:"Lucida Grande", Geneva, Verdana, Arial, Helvetica, sans-serif;
77
+ color:#000;font-family:"Trebuchet MS", Georgia, Verdana, Arial, Helvetica, sans-serif;
78
+ background:#ddd;
79
+ font-size:14px;
80
+ }
81
+
82
+ #header,
83
+ #footer {
84
+ background:gray;
85
+ color:#fff;
86
+ }
87
+
88
+ #content {
89
+ background:#fff;
90
+ color:#000;
91
+ }
92
+
93
+ h1,
94
+ h2 {
95
+ padding:0;
96
+ margin:0 0 0 10px;
97
+ }
98
+
99
+ h1 {
100
+ font-size:1.3em;
101
+ text-align:left;
102
+ padding-top:0.5em;
103
+ }
104
+
105
+ h2 {
106
+ font-size:1.1em;
107
+ padding-top:1em;
108
+ margin-top:0;
109
+ }
110
+
111
+ #footer p {
112
+ margin:0 0 0 5px;
113
+ padding:0;
114
+ }
115
+
116
+ #footer a {
117
+ color:#fff;
118
+ }
12
119
 
13
- body, p, ol, ul, td {
14
- font-family: verdana, arial, helvetica, sans-serif;
15
- font-size: 12px;
16
- line-height: 18px;
120
+ ul, p {
121
+ line-height:1.45em;
17
122
  }
18
-
19
- .matched { background-color: #DBFFB4 }
123
+
124
+ p {
125
+ margin:0 10% 0 10px;
126
+ padding-bottom:10px;
127
+ }
128
+
129
+ table { width: 100%; }
130
+
131
+ .matched { background-color: #DBFFB4 }
20
132
  .mismatched { background-color: #FA5858 }
21
133
  .unmatched { background-color: #FFFBD3 }
22
- </style>
23
-
24
- </head>
25
-
26
- <body>
27
-
28
- <h2>XMatch Report</h2>
29
- <p><%= xml.mismatches.size %> mismatches found from <%= xml.results.size %> elements.<br/>
30
- Expected xml document is <b><%= completedness %>%</b> 'matched'.
31
- </p>
32
- <p><a href='<%=expected_filename%>'>Expected xml</a> | <a href='<%=actual_filename%>'>Actual xml</a></p>
33
-
34
- <table border="0" cellspacing="2" cellpadding="5">
35
- <tr>
36
- <th>Line</th>
37
- <th>Path</th>
38
- <th>Expected</th>
39
- <th>Actual</th>
40
- </tr>
41
- <% match_info.each do | match | %>
42
- <tr class=<%= match.result %> >
43
- <td><%= match.line %></td>
44
- <td><%= match.path %></td>
45
- <% if match.custom_matched == true%>
46
- <td><i>(something like) <%= match.expected %></i></td>
47
- <% else %>
48
- <td><%= match.expected %></td>
49
- <% end %>
50
- <td><%= match.actual %></td>
51
- </tr>
52
- <% end %>
53
- </table>
54
-
55
- </body>
134
+
135
+ </style>
136
+ </head>
137
+ <body>
138
+ <div id="content-wrapper">
139
+ <div id="content">
140
+ <table border="0" cellspacing="2" cellpadding="5">
141
+ <tr>
142
+ <th>
143
+ Line
144
+ </th>
145
+ <th>
146
+ Path
147
+ </th>
148
+ <th>
149
+ Expected
150
+ </th>
151
+ <th>
152
+ Actual
153
+ </th>
154
+ </tr><% match_info.each do | match | %>
155
+ <tr class="<%= match.result %>">
156
+ <td>
157
+ <%= match.line %>
158
+ </td>
159
+ <td>
160
+ <%= match.path %>
161
+ </td><% if match.custom_matched == true%>
162
+ <td>
163
+ <i>(something like) <%= match.expected %></i>
164
+ </td><% else %>
165
+ <td>
166
+ <%= match.expected %>
167
+ </td><% end %>
168
+ <td>
169
+ <%= match.actual %>
170
+ </td>
171
+ </tr><% end %>
172
+ </table>
173
+ </div>
174
+ </div>
175
+ <div id="header-wrapper">
176
+ <div id="header">
177
+ <h2>
178
+ XMatch Report
179
+ </h2>
180
+ <p>
181
+ <%= xml.mismatches.size %> mismatches found from <%= xml.results.size %> elements.<br />
182
+ Expected xml document is <b><%= completedness %>%</b> 'matched'.
183
+ </p>
184
+ <p>
185
+ <a href='<%=expected_filename%>' target='_blank'>Expected xml</a> | <a href='<%=actual_filename%>' target='_blank'>Actual xml</a>
186
+ </p>
187
+ </div>
188
+ </div>
189
+ <div id="footer-wrapper">
190
+ <div id="footer">
191
+ <p><a href='https://github.com/pmoran/xmatch'>XMatch</a> &copy 2010 Peter Moran</p>
192
+ </div>
193
+ </div>
194
+ </body>
56
195
  </html>
@@ -0,0 +1,39 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe Matcher::HtmlFormatter do
4
+
5
+ context "when configured" do
6
+
7
+ before(:each) do
8
+ xml = "<foo></foo>"
9
+ @matcher = Matcher::Xml.new("<foo></foo>")
10
+ @matcher.match(xml)
11
+ end
12
+
13
+ it "should create an html report in the default report directory" do
14
+ Matcher::HtmlFormatter.new(@matcher).format
15
+ File.exists?("/tmp/xmatch/xmatch.html").should be_true
16
+ end
17
+
18
+ %w[expected actual].each do |file|
19
+ it "should create generated #{file} file" do
20
+ now = Time.now
21
+ Time.stub!(:now).and_return(now)
22
+ Matcher::HtmlFormatter.new(@matcher).format
23
+ File.exists?("/tmp/xmatch/generated_xml/#{file}-#{now.to_i}.xml").should be_true
24
+ end
25
+ end
26
+
27
+ it "should create an html file in a configured directory" do
28
+ Matcher::HtmlFormatter.new(@matcher, :report_dir => "/tmp/xmatch/mydir").format
29
+ File.exists?("/tmp/xmatch/mydir/xmatch.html").should be_true
30
+ end
31
+
32
+ it "should create an html file with a configured prefix" do
33
+ Matcher::HtmlFormatter.new(@matcher, :prefix => "myprefix").format
34
+ File.exists?("/tmp/xmatch/myprefix-xmatch.html").should be_true
35
+ end
36
+
37
+ end
38
+
39
+ end
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: 21
4
+ hash: 19
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 2
9
- - 1
10
- version: 0.2.1
8
+ - 3
9
+ - 0
10
+ version: 0.3.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Peter Moran
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-12-07 00:00:00 +11:00
18
+ date: 2010-12-15 00:00:00 +11:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -93,6 +93,7 @@ files:
93
93
  - spec/fixtures/books7.xml
94
94
  - spec/fixtures/books8.xml
95
95
  - spec/fixtures/books9.xml
96
+ - spec/matcher/html_formatter_spec.rb
96
97
  - spec/matcher/smoke_spec.rb
97
98
  - spec/matcher/xml_spec.rb
98
99
  - spec/spec_helper.rb
@@ -142,6 +143,7 @@ test_files:
142
143
  - spec/fixtures/books7.xml
143
144
  - spec/fixtures/books8.xml
144
145
  - spec/fixtures/books9.xml
146
+ - spec/matcher/html_formatter_spec.rb
145
147
  - spec/matcher/smoke_spec.rb
146
148
  - spec/matcher/xml_spec.rb
147
149
  - spec/spec_helper.rb