BuildMaster 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,58 @@
1
+ $:.unshift File.join(File.dirname(__FILE__), "..", "..", "lib")
2
+
3
+ require 'test/unit'
4
+ require 'buildmaster'
5
+
6
+ module BuildMaster
7
+
8
+ class SiteTest < Test::Unit::TestCase
9
+ protected
10
+ def setup
11
+ super
12
+ @temp = File.join(File.dirname(__FILE__), '..', '..', 'tmp')
13
+
14
+ if (File.exist? @temp)
15
+ delete_all(@temp)
16
+ end
17
+ end
18
+
19
+ private
20
+ def delete_all(directory)
21
+ Dir.foreach(directory) do |name|
22
+ if (name != '.' && name != '..')
23
+ file = File.join(directory, name)
24
+ if (File.directory? file)
25
+ delete_all(file)
26
+ else
27
+ File.delete(file)
28
+ end
29
+ end
30
+ end
31
+ Dir.rmdir(directory)
32
+ end
33
+
34
+ public
35
+ def test_should_build_based_on_content
36
+ spec = SiteSpec.new
37
+ spec.output_dir = File.join(@temp, 'output')
38
+ spec.content_dir = File.join(File.dirname(__FILE__), 'content')
39
+ spec.template =<<TEMPLATE
40
+ <html xmlns="http://www.w3.org/1999/xhtml"
41
+ xmlns:template="http://buildmaster.rubyforge.org/xtemplate/1.0">
42
+ <head>
43
+ <title>Title</title>
44
+ </head>
45
+ <body>
46
+ </body>
47
+ </html>
48
+ TEMPLATE
49
+ site = Site.new(spec)
50
+ site.build
51
+ output_index = File.join(@temp, 'output', 'index.html')
52
+ assert_equal(true, File.exist?(@temp), "#{@temp}")
53
+ assert_equal(true, File.exist?(output_index), "#{output_index} exists")
54
+ end
55
+
56
+ end
57
+
58
+ end
@@ -0,0 +1,74 @@
1
+ $:.unshift File.join(File.dirname(__FILE__), "..", "..", "lib")
2
+
3
+ require 'test/unit'
4
+ require 'buildmaster'
5
+
6
+ module BuildMaster
7
+ class SvnDriverTest < Test::Unit::TestCase
8
+ protected
9
+ def setup
10
+ super
11
+ @path = File.join(File.dirname(__FILE__), "..", "..")
12
+ @info = SvnInfo.new @path
13
+ end
14
+
15
+ public
16
+ def test_load_info
17
+ info = SvnInfo.new(@path)
18
+ assert_equal(@path, info.path)
19
+ assert_equal('svn+ssh://wolfdancer@rubyforge.org/var/svn/buildmaster', info.repository_root)
20
+ end
21
+
22
+ def test_load_driver
23
+ svn = SvnDriver.from_path(@path)
24
+ svn.command('info')
25
+ end
26
+
27
+ def test_status
28
+ log = ''
29
+ svn = SvnDriver.new(@info){|command| log = command}
30
+ svn.status
31
+ assert_equal("svn status #{@path}", log)
32
+ end
33
+
34
+ def test_update
35
+ log = ''
36
+ svn = SvnDriver.new(@info) {|command| log = command}
37
+ svn.update
38
+ assert_equal("svn update #{@path}", log)
39
+ end
40
+
41
+ def test_commit
42
+ log = ''
43
+ svn = SvnDriver.new(@info) {|command| log = command}
44
+ svn.commit('message')
45
+ assert_equal("svn commit #{@path} -m \"message\"", log)
46
+ end
47
+
48
+ def test_checkout
49
+ log = ''
50
+ svn = SvnDriver.new(@info) {|command| log = command}
51
+ svn.checkout('output')
52
+ assert_equal("svn checkout #{@info.repository_root}/trunk output", log)
53
+ end
54
+
55
+ def test_command
56
+ log = ''
57
+ svn = SvnDriver.new(@info) {|command| log = command}
58
+ svn.command('info')
59
+ assert_equal("svn info #{@path}", log)
60
+ end
61
+
62
+ def test_tag
63
+ log = ''
64
+ svn = SvnDriver.new(@info) {|command| log = command}
65
+ tag = 'build_0.0.5_b3'
66
+ svn.tag(tag)
67
+ assert_equal(
68
+ "svn copy #{@info.repository_root}/trunk #{@info.repository_root}/tags/#{tag} -m \"ruby buildmaster\"",
69
+ log)
70
+ end
71
+
72
+ end
73
+
74
+ end
@@ -0,0 +1,48 @@
1
+ $:.unshift File.join(File.dirname(__FILE__), "..", "..", "lib")
2
+
3
+ require 'rexml/xpath'
4
+ require 'rexml/document'
5
+ require 'test/unit'
6
+ require 'buildmaster/template_runner'
7
+
8
+ module BuildMaster
9
+ class TemplateRunnerTest < Test::Unit::TestCase
10
+ def test_process_element_in_document
11
+ target_content = <<END
12
+ <html>
13
+ <h1/>
14
+ </html>
15
+ END
16
+ template_content = <<END
17
+ <html xmlns="http://www.w3.org/1999/xhtml"
18
+ xmlns:template="http://buildmaster.rubyforge.org/xtemplate/1.0">
19
+ <p>
20
+ <template:include elements="./name/text()"/>
21
+ </p>
22
+ </html>
23
+ END
24
+ source_content = <<END
25
+ <persons>
26
+ <person id="1"><name>Name One</name></person>
27
+ <person id="2"><name>Name Two</name></person>
28
+ </persons>
29
+ END
30
+ target_xml = REXML::Document.new(target_content)
31
+ target_element = REXML::XPath.first(target_xml, '/html/h1')
32
+ template_element = REXML::XPath.first(REXML::Document.new(template_content), "/html/p")
33
+ source_xml = REXML::Document.new(source_content)
34
+ source_element = REXML::XPath.first(source_xml, '/persons/person[@id="1"]')
35
+ # puts "========= TARGET ========="
36
+ # puts target_element
37
+ # puts "========== TEMPLATE =========="
38
+ # puts template_element
39
+ # puts "========== SOURCE ==========="
40
+ # puts source_element
41
+ # puts '=========== Source Match ============'
42
+ # puts REXML::XPath.first(source_element, './name')
43
+ runner = TemplateRunner.new(target_element, template_element, source_element)
44
+ runner.process
45
+ assert_equal('Name One', REXML::XPath.first(REXML::Document.new(target_xml.to_s), '/html/h1/text()').value.strip)
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,256 @@
1
+ $:.unshift File.join(File.dirname(__FILE__), "..", "..", "lib")
2
+
3
+ require 'rexml/xpath'
4
+ require 'test/unit'
5
+ require 'buildmaster'
6
+
7
+ module BuildMaster
8
+ class XTemplateTest < Test::Unit::TestCase
9
+ protected
10
+ def setup
11
+ super
12
+ end
13
+
14
+ public
15
+ def test_should_initialize_with_io
16
+ template = BuildMaster::XTemplate.new(File.open(File.join(File.dirname(__FILE__), "template.xhtml")))
17
+ end
18
+
19
+ def test_should_initialize_with_content
20
+ template_content = <<CONTENT
21
+ <html xmlns="http://www.w3.org/1999/xhtml"
22
+ xmlns:template="http://buildmaster.rubyforge.org/xtemplate/1.0">
23
+ <head>
24
+ <title>BuildMaster</title>
25
+ </head>
26
+ <body>Body</body>
27
+ </html>
28
+ CONTENT
29
+ template = XTemplate.new(template_content)
30
+ xml_output = template.process('')
31
+ assert_equal('Body', REXML::XPath.first(xml_output, '/html/body').text)
32
+ end
33
+
34
+ def test_should_process_include_with_elements_attribute
35
+ template_content = <<INCLUDE_CONTENT
36
+ <html xmlns="http://www.w3.org/1999/xhtml"
37
+ xmlns:template="http://buildmaster.rubyforge.org/xtemplate/1.0">
38
+ <head>
39
+ <title>BuildMaster - <template:include elements="/html/head/title/text()"/></title>
40
+ </head>
41
+ <body>
42
+ </body>
43
+ </html>
44
+ INCLUDE_CONTENT
45
+ source_content = <<INCLUDE_SOURCE
46
+ <!DOCTYPE html
47
+ PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
48
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
49
+ <html xmlns="http://www.w3.org/1999/xhtml">
50
+ <head><title>Page Title</title></head>
51
+ <body></body>
52
+ </html>
53
+ INCLUDE_SOURCE
54
+ template = XTemplate.new(template_content)
55
+ xml_output = REXML::Document.new(template.process(source_content).to_s)
56
+ assert_equal('BuildMaster - Page Title', REXML::XPath.first(xml_output, '/html/head/title').text)
57
+ end
58
+
59
+ def test_should_process_when_with_select_value_attribute
60
+ template_content = <<INCLUDE_CONTENT
61
+ <html xmlns="http://www.w3.org/1999/xhtml"
62
+ xmlns:template="http://buildmaster.rubyforge.org/xtemplate/1.0">
63
+ <head>
64
+ <title>BuildMaster - <template:when test="index_file?">Index</template:when></title>
65
+ </head>
66
+ <body>
67
+ <template:when test="what?">
68
+ <ul>
69
+ <li>one</li>
70
+ </ul>
71
+ </template:when>
72
+ </body>
73
+ </html>
74
+ INCLUDE_CONTENT
75
+ source_content = <<INCLUDE_SOURCE
76
+ <!DOCTYPE html
77
+ PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
78
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
79
+ <html xmlns="http://www.w3.org/1999/xhtml">
80
+ <head><title>Page Title</title></head>
81
+ <body></body>
82
+ </html>
83
+ INCLUDE_SOURCE
84
+ template = XTemplate.new(template_content)
85
+ xml_document = template.process(source_content) {|expression| return true}
86
+ xml_output = REXML::Document.new(xml_document.to_s())
87
+ assert_equal('BuildMaster - Index', REXML::XPath.first(xml_output, '/html/head/title').text)
88
+ assert_equal('one', REXML::XPath.first(xml_output, '/html/body/ul/li').text)
89
+ end
90
+
91
+ def test_should_not_process_when_if_select_false
92
+ template_content = <<INCLUDE_CONTENT
93
+ <html xmlns="http://www.w3.org/1999/xhtml"
94
+ xmlns:template="http://buildmaster.rubyforge.org/xtemplate/1.0">
95
+ <head>
96
+ <title>BuildMaster<template:when test="index_file?"> - Index</template:when></title>
97
+ </head>
98
+ <body>
99
+ </body>
100
+ </html>
101
+ INCLUDE_CONTENT
102
+ source_content = <<INCLUDE_SOURCE
103
+ <!DOCTYPE html
104
+ PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
105
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
106
+ <html xmlns="http://www.w3.org/1999/xhtml">
107
+ <head><title>Page Title</title></head>
108
+ <body></body>
109
+ </html>
110
+ INCLUDE_SOURCE
111
+ template = XTemplate.new(template_content)
112
+ xml_document = template.process(source_content) {|expression| return false}
113
+ xml_output = REXML::Document.new(xml_document.to_s())
114
+ assert_equal('BuildMaster', REXML::XPath.first(xml_output, '/html/head/title').text)
115
+ end
116
+
117
+ def test_should_process_attr_with_eval_attribute
118
+ template_content = <<INCLUDE_CONTENT
119
+ <html xmlns="http://www.w3.org/1999/xhtml"
120
+ xmlns:template="http://buildmaster.rubyforge.org/xtemplate/1.0">
121
+ <head>
122
+ <title>BuildMaster</title>
123
+ </head>
124
+ <body>
125
+ <a><template:attribute name="href" eval="document_link"/></a>
126
+ </body>
127
+ </html>
128
+ INCLUDE_CONTENT
129
+ source_content = <<INCLUDE_SOURCE
130
+ <!DOCTYPE html
131
+ PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
132
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
133
+ <html xmlns="http://www.w3.org/1999/xhtml">
134
+ <head><title>Page Title</title></head>
135
+ <body></body>
136
+ </html>
137
+ INCLUDE_SOURCE
138
+ template = XTemplate.new(template_content)
139
+ xml_document = template.process(source_content) {|expression| return 'http://svn.buildmaster/'}
140
+ xml_output = REXML::Document.new(xml_document.to_s())
141
+ assert_equal('http://svn.buildmaster', REXML::XPath.first(xml_output, '/html/body/a/@href').text)
142
+ end
143
+
144
+ def test_should_process_text_with_eval_attribute
145
+ template_content = <<INCLUDE_CONTENT
146
+ <html xmlns="http://www.w3.org/1999/xhtml"
147
+ xmlns:template="http://buildmaster.rubyforge.org/xtemplate/1.0">
148
+ <head>
149
+ <title>BuildMaster</title>
150
+ </head>
151
+ <body>
152
+ <h1><template:text eval="release_info"/></h1>
153
+ </body>
154
+ </html>
155
+ INCLUDE_CONTENT
156
+ source_content = <<INCLUDE_SOURCE
157
+ <!DOCTYPE html
158
+ PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
159
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
160
+ <html xmlns="http://www.w3.org/1999/xhtml">
161
+ <head><title>Page Title</title></head>
162
+ <body></body>
163
+ </html>
164
+ INCLUDE_SOURCE
165
+ template = XTemplate.new(template_content)
166
+ xml_document = template.process(source_content) {|expression| return 'release 0.0.1 (build 235)'}
167
+ xml_output = REXML::Document.new(xml_document.to_s())
168
+ assert_equal('release 0.0.1 (build 235)', REXML::XPath.first(xml_output, '/html/body/h1').text)
169
+ end
170
+
171
+ def test_should_process_each_with_children
172
+ template_content = <<INCLUDE_CONTENT
173
+ <html xmlns="http://www.w3.org/1999/xhtml"
174
+ xmlns:template="http://buildmaster.rubyforge.org/xtemplate/1.0">
175
+ <head>
176
+ <title>BuildMaster</title>
177
+ </head>
178
+ <body>
179
+ <div class="NewsGroup">
180
+ <h1>Recent News</h1>
181
+ <template:each source="rss" select="/rss/channel/item" count="3">
182
+ <div class="NewsItem">
183
+ <p class="NewsTitle"><template:include elements="./title/text()"/></p>
184
+ <p class="NewsDate"><template:include elements="./pubDate/text()"/></p>
185
+ <p class="NewsText"><template:include elements="./xhtml:div/node()"/></p>
186
+ </div>
187
+ </template:each>
188
+ </div>
189
+ </body>
190
+ </html>
191
+ INCLUDE_CONTENT
192
+ source_content = <<INCLUDE_SOURCE
193
+ <!DOCTYPE html
194
+ PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
195
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
196
+ <html xmlns="http://www.w3.org/1999/xhtml">
197
+ <head><title>Page Title</title></head>
198
+ <body></body>
199
+ </html>
200
+ INCLUDE_SOURCE
201
+ template = XTemplate.new(template_content)
202
+ xml_document = template.process(source_content) do |expression| <<NEWS
203
+ <?xml version="1.0" encoding="UTF-8"?>
204
+ <rss version="2.0">
205
+ <channel>
206
+ <title>BuildMaster News</title>
207
+ <link>http://buildmaster.rubyforge.org/</link>
208
+ <description>BuildMaster is a set of classes in Ruby to help easy the task of project building, releasing
209
+ and website building</description>
210
+ <language>en-us</language>
211
+ <lastBuildDate>Tue, 09 May 2006 17:12:46 GMT</lastBuildDate>
212
+ <image>
213
+ <url>http://buildmaster.rubyforge.org/logo.gif</url>
214
+ <title>BuildMaster</title>
215
+ <link>http://buildmaster.rubyforge.org/</link>
216
+ </image>
217
+ <item>
218
+ <title>BuildMaster website created</title>
219
+ <link>http://buildmaster.rubyforge.org/</link>
220
+ <description>BuildMaster website has been created by its own script</description>
221
+ <category>Documentation</category>
222
+ <pubDate>Sat, 27 May 2006 16:00:00 GMT</pubDate>
223
+ </item>
224
+ <item>
225
+ <title>XTemplate script created</title>
226
+ <link>http://buildmaster.rubyforge.org</link>
227
+ <description>XTemplate script has been created, following the ones that is currently being used for jBehave and jMock</description>
228
+ <category>Development</category>
229
+ <pubDate>Wed, 05 Apr 2006 16:00:00 GMT</pubDate>
230
+ </item>
231
+ <item>
232
+ <title>BuildMaster code structure created</title>
233
+ <link>http://buildmaster.rubyforge.org</link>
234
+ <description>BuildMaster project structure has been created with according files so that a gem can be created
235
+ and released onto rubyforge</description>
236
+ <category>Development</category>
237
+ <pubDate>Sat, 08 Apr 2006 16:00:00 GMT</pubDate>
238
+ </item>
239
+ <item>
240
+ <title>BuildMaster moved from RubyBuilder</title>
241
+ <description>RubyBuilder project has been deleted and renamed to BuildMaster to easy any confusion</description>
242
+ <category>Development</category>
243
+ <pubDate>Sat, 01 Apr 2006 16:00:00 GMT</pubDate>
244
+ </item>
245
+ </channel>
246
+ </rss>
247
+ NEWS
248
+ end
249
+ xml_output = REXML::Document.new(xml_document.to_s())
250
+ # puts xml_output
251
+ assert_equal(3, REXML::XPath.match(xml_output, '/html/body/div/div').size)
252
+ assert_equal('BuildMaster website created',
253
+ REXML::XPath.first(xml_output, '/html/body/div/div[1]/p').text())
254
+ end
255
+ end
256
+ end
@@ -0,0 +1,10 @@
1
+ <html xmlns="http://www.w3.org/1999/xhtml"
2
+ xmlns:template="http://buildmaster.rubyforge.org/xemplate/1.0">
3
+ <head>
4
+ <title>JBehave - <template:include elements="/html/head/title/text()"/></title>
5
+ <template:include elements="/html/head/*[not(name()='title')]"/>
6
+ </head>
7
+
8
+ <body>
9
+ </body>
10
+ </html>