assaf-buildr 1.3.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (163) hide show
  1. data/CHANGELOG +887 -0
  2. data/DISCLAIMER +7 -0
  3. data/LICENSE +176 -0
  4. data/NOTICE +26 -0
  5. data/README.rdoc +146 -0
  6. data/Rakefile +62 -0
  7. data/_buildr +38 -0
  8. data/addon/buildr/antlr.rb +65 -0
  9. data/addon/buildr/cobertura.rb +236 -0
  10. data/addon/buildr/emma.rb +238 -0
  11. data/addon/buildr/hibernate.rb +142 -0
  12. data/addon/buildr/javacc.rb +85 -0
  13. data/addon/buildr/jdepend.rb +60 -0
  14. data/addon/buildr/jetty.rb +248 -0
  15. data/addon/buildr/jibx.rb +86 -0
  16. data/addon/buildr/nailgun.rb +817 -0
  17. data/addon/buildr/openjpa.rb +90 -0
  18. data/addon/buildr/org/apache/buildr/BuildrNail$Main.class +0 -0
  19. data/addon/buildr/org/apache/buildr/BuildrNail.class +0 -0
  20. data/addon/buildr/org/apache/buildr/BuildrNail.java +41 -0
  21. data/addon/buildr/org/apache/buildr/JettyWrapper$1.class +0 -0
  22. data/addon/buildr/org/apache/buildr/JettyWrapper$BuildrHandler.class +0 -0
  23. data/addon/buildr/org/apache/buildr/JettyWrapper.class +0 -0
  24. data/addon/buildr/org/apache/buildr/JettyWrapper.java +144 -0
  25. data/addon/buildr/xmlbeans.rb +93 -0
  26. data/bin/buildr +28 -0
  27. data/buildr.buildfile +53 -0
  28. data/buildr.gemspec +58 -0
  29. data/doc/css/default.css +228 -0
  30. data/doc/css/print.css +100 -0
  31. data/doc/css/syntax.css +52 -0
  32. data/doc/images/apache-incubator-logo.png +0 -0
  33. data/doc/images/buildr-hires.png +0 -0
  34. data/doc/images/buildr.png +0 -0
  35. data/doc/images/favicon.png +0 -0
  36. data/doc/images/growl-icon.tiff +0 -0
  37. data/doc/images/note.png +0 -0
  38. data/doc/images/project-structure.png +0 -0
  39. data/doc/images/tip.png +0 -0
  40. data/doc/images/zbuildr.tif +0 -0
  41. data/doc/pages/artifacts.textile +207 -0
  42. data/doc/pages/building.textile +240 -0
  43. data/doc/pages/contributing.textile +208 -0
  44. data/doc/pages/download.textile +62 -0
  45. data/doc/pages/extending.textile +175 -0
  46. data/doc/pages/getting_started.textile +273 -0
  47. data/doc/pages/index.textile +42 -0
  48. data/doc/pages/languages.textile +407 -0
  49. data/doc/pages/mailing_lists.textile +17 -0
  50. data/doc/pages/more_stuff.textile +286 -0
  51. data/doc/pages/packaging.textile +427 -0
  52. data/doc/pages/projects.textile +274 -0
  53. data/doc/pages/recipes.textile +103 -0
  54. data/doc/pages/settings_profiles.textile +274 -0
  55. data/doc/pages/testing.textile +212 -0
  56. data/doc/pages/troubleshooting.textile +103 -0
  57. data/doc/pages/whats_new.textile +323 -0
  58. data/doc/print.haml +51 -0
  59. data/doc/print.toc.yaml +29 -0
  60. data/doc/scripts/buildr-git.rb +412 -0
  61. data/doc/scripts/install-jruby.sh +44 -0
  62. data/doc/scripts/install-linux.sh +64 -0
  63. data/doc/scripts/install-osx.sh +52 -0
  64. data/doc/site.haml +56 -0
  65. data/doc/site.toc.yaml +47 -0
  66. data/etc/KEYS +151 -0
  67. data/etc/git-svn-authors +16 -0
  68. data/lib/buildr.rb +35 -0
  69. data/lib/buildr/core.rb +27 -0
  70. data/lib/buildr/core/application.rb +489 -0
  71. data/lib/buildr/core/application_cli.rb +139 -0
  72. data/lib/buildr/core/build.rb +311 -0
  73. data/lib/buildr/core/checks.rb +382 -0
  74. data/lib/buildr/core/common.rb +154 -0
  75. data/lib/buildr/core/compile.rb +596 -0
  76. data/lib/buildr/core/environment.rb +120 -0
  77. data/lib/buildr/core/filter.rb +362 -0
  78. data/lib/buildr/core/generate.rb +195 -0
  79. data/lib/buildr/core/help.rb +118 -0
  80. data/lib/buildr/core/progressbar.rb +156 -0
  81. data/lib/buildr/core/project.rb +892 -0
  82. data/lib/buildr/core/test.rb +715 -0
  83. data/lib/buildr/core/transports.rb +558 -0
  84. data/lib/buildr/core/util.rb +289 -0
  85. data/lib/buildr/groovy.rb +18 -0
  86. data/lib/buildr/groovy/bdd.rb +105 -0
  87. data/lib/buildr/groovy/compiler.rb +138 -0
  88. data/lib/buildr/ide.rb +19 -0
  89. data/lib/buildr/ide/eclipse.rb +212 -0
  90. data/lib/buildr/ide/idea.ipr.template +300 -0
  91. data/lib/buildr/ide/idea.rb +189 -0
  92. data/lib/buildr/ide/idea7x.ipr.template +290 -0
  93. data/lib/buildr/ide/idea7x.rb +210 -0
  94. data/lib/buildr/java.rb +23 -0
  95. data/lib/buildr/java/ant.rb +92 -0
  96. data/lib/buildr/java/bdd.rb +449 -0
  97. data/lib/buildr/java/commands.rb +211 -0
  98. data/lib/buildr/java/compiler.rb +348 -0
  99. data/lib/buildr/java/deprecated.rb +141 -0
  100. data/lib/buildr/java/jruby.rb +117 -0
  101. data/lib/buildr/java/jtestr_runner.rb.erb +116 -0
  102. data/lib/buildr/java/org/apache/buildr/JavaTestFilter.class +0 -0
  103. data/lib/buildr/java/org/apache/buildr/JavaTestFilter.java +119 -0
  104. data/lib/buildr/java/packaging.rb +713 -0
  105. data/lib/buildr/java/pom.rb +178 -0
  106. data/lib/buildr/java/rjb.rb +155 -0
  107. data/lib/buildr/java/test_result.rb +308 -0
  108. data/lib/buildr/java/tests.rb +324 -0
  109. data/lib/buildr/java/version_requirement.rb +172 -0
  110. data/lib/buildr/packaging.rb +21 -0
  111. data/lib/buildr/packaging/artifact.rb +730 -0
  112. data/lib/buildr/packaging/artifact_namespace.rb +972 -0
  113. data/lib/buildr/packaging/artifact_search.rb +140 -0
  114. data/lib/buildr/packaging/gems.rb +102 -0
  115. data/lib/buildr/packaging/package.rb +233 -0
  116. data/lib/buildr/packaging/tar.rb +104 -0
  117. data/lib/buildr/packaging/zip.rb +722 -0
  118. data/lib/buildr/resources/buildr.icns +0 -0
  119. data/lib/buildr/scala.rb +19 -0
  120. data/lib/buildr/scala/compiler.rb +109 -0
  121. data/lib/buildr/scala/tests.rb +203 -0
  122. data/rakelib/apache.rake +191 -0
  123. data/rakelib/changelog.rake +57 -0
  124. data/rakelib/doc.rake +103 -0
  125. data/rakelib/package.rake +73 -0
  126. data/rakelib/release.rake +65 -0
  127. data/rakelib/rspec.rake +83 -0
  128. data/rakelib/rubyforge.rake +53 -0
  129. data/rakelib/scm.rake +49 -0
  130. data/rakelib/setup.rake +86 -0
  131. data/rakelib/stage.rake +48 -0
  132. data/spec/addon/cobertura_spec.rb +77 -0
  133. data/spec/addon/emma_spec.rb +120 -0
  134. data/spec/addon/test_coverage_spec.rb +255 -0
  135. data/spec/core/application_spec.rb +412 -0
  136. data/spec/core/artifact_namespace_spec.rb +646 -0
  137. data/spec/core/build_spec.rb +415 -0
  138. data/spec/core/checks_spec.rb +537 -0
  139. data/spec/core/common_spec.rb +664 -0
  140. data/spec/core/compile_spec.rb +566 -0
  141. data/spec/core/generate_spec.rb +33 -0
  142. data/spec/core/project_spec.rb +754 -0
  143. data/spec/core/test_spec.rb +1091 -0
  144. data/spec/core/transport_spec.rb +500 -0
  145. data/spec/groovy/bdd_spec.rb +80 -0
  146. data/spec/groovy/compiler_spec.rb +239 -0
  147. data/spec/ide/eclipse_spec.rb +243 -0
  148. data/spec/java/ant.rb +28 -0
  149. data/spec/java/bdd_spec.rb +358 -0
  150. data/spec/java/compiler_spec.rb +446 -0
  151. data/spec/java/java_spec.rb +88 -0
  152. data/spec/java/packaging_spec.rb +1103 -0
  153. data/spec/java/tests_spec.rb +466 -0
  154. data/spec/packaging/archive_spec.rb +503 -0
  155. data/spec/packaging/artifact_spec.rb +754 -0
  156. data/spec/packaging/packaging_helper.rb +63 -0
  157. data/spec/packaging/packaging_spec.rb +589 -0
  158. data/spec/sandbox.rb +137 -0
  159. data/spec/scala/compiler_spec.rb +228 -0
  160. data/spec/scala/tests_spec.rb +215 -0
  161. data/spec/spec_helpers.rb +304 -0
  162. data/spec/version_requirement_spec.rb +123 -0
  163. metadata +369 -0
@@ -0,0 +1,1091 @@
1
+ # Licensed to the Apache Software Foundation (ASF) under one or more
2
+ # contributor license agreements. See the NOTICE file distributed with this
3
+ # work for additional information regarding copyright ownership. The ASF
4
+ # licenses this file to you under the Apache License, Version 2.0 (the
5
+ # "License"); you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12
+ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13
+ # License for the specific language governing permissions and limitations under
14
+ # the License.
15
+
16
+
17
+ require File.join(File.dirname(__FILE__), '../spec_helpers')
18
+
19
+
20
+ module TestHelper
21
+ def touch_last_successful_test_run(test_task, timestamp = Time.now)
22
+ test_task.instance_eval do
23
+ record_successful_run
24
+ File.utime(timestamp, timestamp, last_successful_run_file)
25
+ end
26
+ end
27
+ end
28
+
29
+
30
+ describe Buildr::TestTask do
31
+ def test_task
32
+ @test_task ||= define('foo').test
33
+ end
34
+
35
+ it 'should respond to :compile and return compile task' do
36
+ test_task.compile.should be_kind_of(Buildr::CompileTask)
37
+ end
38
+
39
+ it 'should respond to :compile and add sources to compile' do
40
+ test_task.compile 'sources'
41
+ test_task.compile.sources.should include('sources')
42
+ end
43
+
44
+ it 'should respond to :compile and add action for test:compile' do
45
+ write 'src/test/java/Test.java', 'class Test {}'
46
+ test_task.compile { task('action').invoke }
47
+ lambda { test_task.compile.invoke }.should run_tasks('action')
48
+ end
49
+
50
+ it 'should execute compile tasks first' do
51
+ write 'src/main/java/Nothing.java', 'class Nothing {}'
52
+ write 'src/test/java/Test.java', 'class Test {}'
53
+ define 'foo'
54
+ lambda { project('foo').test.compile.invoke }.should run_tasks(['foo:compile', 'foo:test:compile'])
55
+ end
56
+
57
+ it 'should respond to :resources and return resources task' do
58
+ test_task.resources.should be_kind_of(Buildr::ResourcesTask)
59
+ end
60
+
61
+ it 'should respond to :resources and add prerequisites to test:resources' do
62
+ file('prereq').should_receive :invoke_prerequisites
63
+ test_task.resources 'prereq'
64
+ test_task.compile.invoke
65
+ end
66
+
67
+ it 'should respond to :resources and add action for test:resources' do
68
+ task 'action'
69
+ test_task.resources { task('action').invoke }
70
+ lambda { test_task.resources.invoke }.should run_tasks('action')
71
+ end
72
+
73
+ it 'should respond to :setup and return setup task' do
74
+ test_task.setup.name.should =~ /test:setup$/
75
+ end
76
+
77
+ it 'should respond to :setup and add prerequisites to test:setup' do
78
+ test_task.setup 'prereq'
79
+ test_task.setup.prerequisites.should include('prereq')
80
+ end
81
+
82
+ it 'should respond to :setup and add action for test:setup' do
83
+ task 'action'
84
+ test_task.setup { task('action').invoke }
85
+ lambda { test_task.setup.invoke }.should run_tasks('action')
86
+ end
87
+
88
+ it 'should respond to :teardown and return teardown task' do
89
+ test_task.teardown.name.should =~ /test:teardown$/
90
+ end
91
+
92
+ it 'should respond to :teardown and add prerequisites to test:teardown' do
93
+ test_task.teardown 'prereq'
94
+ test_task.teardown.prerequisites.should include('prereq')
95
+ end
96
+
97
+ it 'should respond to :teardown and add action for test:teardown' do
98
+ task 'action'
99
+ test_task.teardown { task('action').invoke }
100
+ lambda { test_task.teardown.invoke }.should run_tasks('action')
101
+ end
102
+
103
+ it 'should respond to :with and return self' do
104
+ test_task.with.should be(test_task)
105
+ end
106
+
107
+ it 'should respond to :with and add artifacfs to compile task dependencies' do
108
+ test_task.with 'test.jar', 'acme:example:jar:1.0'
109
+ test_task.compile.dependencies.should include(File.expand_path('test.jar'))
110
+ test_task.compile.dependencies.should include(artifact('acme:example:jar:1.0'))
111
+ end
112
+
113
+ it 'should respond to :with and add artifacfs to task dependencies' do
114
+ test_task.with 'test.jar', 'acme:example:jar:1.0'
115
+ test_task.dependencies.should include(File.expand_path('test.jar'))
116
+ test_task.dependencies.should include(artifact('acme:example:jar:1.0'))
117
+ end
118
+
119
+ it 'should response to :options and return test framework options' do
120
+ test_task.using :foo=>'bar'
121
+ test_task.options[:foo].should eql('bar')
122
+ end
123
+
124
+ it 'should respond to :using and return self' do
125
+ test_task.using.should be(test_task)
126
+ end
127
+
128
+ it 'should respond to :using and set value options' do
129
+ test_task.using('foo'=>'FOO', 'bar'=>'BAR')
130
+ test_task.options[:foo].should eql('FOO')
131
+ test_task.options[:bar].should eql('BAR')
132
+ end
133
+
134
+ it 'should start without pre-selected test framework' do
135
+ test_task.framework.should be_nil
136
+ end
137
+
138
+ it 'should respond to :using and select test framework' do
139
+ test_task.using(:testng)
140
+ test_task.framework.should eql(:testng)
141
+ end
142
+
143
+ it 'should infer test framework from compiled language' do
144
+ lambda { test_task.compile.using(:javac) }.should change { test_task.framework }.to(:junit)
145
+ end
146
+
147
+ it 'should respond to :include and return self' do
148
+ test_task.include.should be(test_task)
149
+ end
150
+
151
+ it 'should respond to :include and add inclusion patterns' do
152
+ test_task.include 'Foo', 'Bar'
153
+ test_task.send(:include?, 'Foo').should be_true
154
+ test_task.send(:include?, 'Bar').should be_true
155
+ end
156
+
157
+ it 'should respond to :exclude and return self' do
158
+ test_task.exclude.should be(test_task)
159
+ end
160
+
161
+ it 'should respond to :exclude and add exclusion patterns' do
162
+ test_task.exclude 'FooTest', 'BarTest'
163
+ test_task.send(:include?, 'FooTest').should be_false
164
+ test_task.send(:include?, 'BarTest').should be_false
165
+ test_task.send(:include?, 'BazTest').should be_true
166
+ end
167
+
168
+ it 'should execute setup task before running tests' do
169
+ mock = mock('actions')
170
+ test_task.setup { mock.setup }
171
+ test_task.enhance { mock.tests }
172
+ mock.should_receive(:setup).ordered
173
+ mock.should_receive(:tests).ordered
174
+ test_task.invoke
175
+ end
176
+
177
+ it 'should execute teardown task after running tests' do
178
+ mock = mock('actions')
179
+ test_task.teardown { mock.teardown }
180
+ test_task.enhance { mock.tests }
181
+ mock.should_receive(:tests).ordered
182
+ mock.should_receive(:teardown).ordered
183
+ test_task.invoke
184
+ end
185
+
186
+ it 'should not execute teardown if setup failed' do
187
+ test_task.setup { fail }
188
+ lambda { test_task.invoke rescue nil }.should_not run_task(test_task.teardown)
189
+ end
190
+
191
+ it 'should use the main compile dependencies' do
192
+ define('foo') { compile.using(:javac).with 'group:id:jar:1.0' }
193
+ project('foo').test.dependencies.should include(artifact('group:id:jar:1.0'))
194
+ end
195
+
196
+ it 'should include the main compile target in its dependencies' do
197
+ define('foo') { compile.using(:javac) }
198
+ project('foo').test.dependencies.should include(project('foo').compile.target)
199
+ end
200
+
201
+ it 'should include the main compile target in its dependencies, even when using non standard directories' do
202
+ write 'src/java/Nothing.java', 'class Nothing {}'
203
+ define('foo') { compile path_to('src/java') }
204
+ project('foo').test.dependencies.should include(project('foo').compile.target)
205
+ end
206
+
207
+ it 'should include the main resources target in its dependencies' do
208
+ write 'src/main/resources/config.xml'
209
+ define('foo').test.dependencies.should include(project('foo').resources.target)
210
+ end
211
+
212
+ it 'should not use the test compile dependencies' do
213
+ define('foo') { test.compile.using(:javac).with 'group:id:jar:1.0' }
214
+ project('foo').test.dependencies.should_not include(artifact('group:id:jar:1.0'))
215
+ end
216
+
217
+ it 'should include the test compile target in its dependencies' do
218
+ define('foo') { test.compile.using(:javac) }
219
+ project('foo').test.dependencies.should include(project('foo').test.compile.target)
220
+ end
221
+
222
+ it 'should include the test compile target in its dependencies, even when using non standard directories' do
223
+ write 'src/test/Test.java', 'class Test {}'
224
+ define('foo') { test.compile path_to('src/test') }
225
+ project('foo').test.dependencies.should include(project('foo').test.compile.target)
226
+ end
227
+
228
+ it 'should add test compile target ahead of regular compile target' do
229
+ write 'src/main/java/Code.java'
230
+ write 'src/test/java/Test.java'
231
+ define 'foo'
232
+ depends = project('foo').test.dependencies
233
+ depends.index(project('foo').test.compile.target).should < depends.index(project('foo').compile.target)
234
+ end
235
+
236
+ it 'should include the test resources target in its dependencies' do
237
+ write 'src/test/resources/config.xml'
238
+ define('foo').test.dependencies.should include(project('foo').test.resources.target)
239
+ end
240
+
241
+ it 'should add test resource target ahead of regular resource target' do
242
+ write 'src/main/resources/config.xml'
243
+ write 'src/test/resources/config.xml'
244
+ define 'foo'
245
+ depends = project('foo').test.dependencies
246
+ depends.index(project('foo').test.resources.target).should < depends.index(project('foo').resources.target)
247
+ end
248
+
249
+ it 'should not have a last successful run timestamp before the tests are run' do
250
+ test_task.timestamp.should == Rake::EARLY
251
+ end
252
+
253
+ it 'should clean after itself (test files)' do
254
+ define('foo') { test.compile.using(:javac) }
255
+ mkpath project('foo').test.compile.target.to_s
256
+ lambda { task('clean').invoke }.should change { File.exist?(project('foo').test.compile.target.to_s) }.to(false)
257
+ end
258
+
259
+ it 'should clean after itself (reports)' do
260
+ define 'foo'
261
+ mkpath project('foo').test.report_to.to_s
262
+ lambda { task('clean').invoke }.should change { File.exist?(project('foo').test.report_to.to_s) }.to(false)
263
+ end
264
+ end
265
+
266
+
267
+ describe Buildr::TestTask, 'with no tests' do
268
+ it 'should pass' do
269
+ lambda { define('foo').test.invoke }.should_not raise_error
270
+ end
271
+
272
+ it 'should report no failed tests' do
273
+ lambda { verbose(true) { define('foo').test.invoke } }.should_not show_error(/fail/i)
274
+ end
275
+
276
+ it 'should return no failed tests' do
277
+ define('foo') { test.using(:junit) }
278
+ project('foo').test.invoke
279
+ project('foo').test.failed_tests.should be_empty
280
+ end
281
+
282
+ it 'should return no passing tests' do
283
+ define('foo') { test.using(:junit) }
284
+ project('foo').test.invoke
285
+ project('foo').test.passed_tests.should be_empty
286
+ end
287
+
288
+ it 'should execute teardown task' do
289
+ lambda { define('foo').test.invoke }.should run_task('foo:test:teardown')
290
+ end
291
+ end
292
+
293
+
294
+ describe Buildr::TestTask, 'with passing tests' do
295
+ def test_task
296
+ @test_task ||= begin
297
+ define 'foo' do
298
+ test.using(:junit)
299
+ test.instance_eval do
300
+ @framework.stub!(:tests).and_return(['PassingTest1', 'PassingTest2'])
301
+ @framework.stub!(:run).and_return(['PassingTest1', 'PassingTest2'])
302
+ end
303
+ end
304
+ project('foo').test
305
+ end
306
+ end
307
+
308
+ it 'should pass' do
309
+ lambda { test_task.invoke }.should_not raise_error
310
+ end
311
+
312
+ it 'should report no failed tests' do
313
+ lambda { verbose(true) { test_task.invoke } }.should_not show_error(/fail/i)
314
+ end
315
+
316
+ it 'should return passed tests' do
317
+ test_task.invoke
318
+ test_task.passed_tests.should == ['PassingTest1', 'PassingTest2']
319
+ end
320
+
321
+ it 'should return no failed tests' do
322
+ test_task.invoke
323
+ test_task.failed_tests.should be_empty
324
+ end
325
+
326
+ it 'should execute teardown task' do
327
+ lambda { test_task.invoke }.should run_task('foo:test:teardown')
328
+ end
329
+
330
+ it 'should update the last successful run timestamp' do
331
+ before = Time.now ; test_task.invoke ; after = Time.now
332
+ (before-1..after+1).should include(test_task.timestamp)
333
+ end
334
+ end
335
+
336
+
337
+ describe Buildr::TestTask, 'with failed test' do
338
+ include TestHelper
339
+
340
+ def test_task
341
+ @test_task ||= begin
342
+ define 'foo' do
343
+ test.using(:junit)
344
+ test.instance_eval do
345
+ @framework.stub!(:tests).and_return(['FailingTest', 'PassingTest'])
346
+ @framework.stub!(:run).and_return(['PassingTest'])
347
+ end
348
+ end
349
+ project('foo').test
350
+ end
351
+ end
352
+
353
+ it 'should fail' do
354
+ lambda { test_task.invoke }.should raise_error(RuntimeError, /Tests failed/)
355
+ end
356
+
357
+ it 'should report failed tests' do
358
+ lambda { verbose(true) { test_task.invoke rescue nil } }.should show_error(/FailingTest/)
359
+ end
360
+
361
+ it 'should return failed tests' do
362
+ test_task.invoke rescue nil
363
+ test_task.failed_tests.should == ['FailingTest']
364
+ end
365
+
366
+ it 'should return passing tests as well' do
367
+ test_task.invoke rescue nil
368
+ test_task.passed_tests.should == ['PassingTest']
369
+ end
370
+
371
+ it 'should not fail if fail_on_failure is false' do
372
+ test_task.using(:fail_on_failure=>false).invoke
373
+ lambda { test_task.invoke }.should_not raise_error
374
+ end
375
+
376
+ it 'should report failed tests even if fail_on_failure is false' do
377
+ test_task.using(:fail_on_failure=>false)
378
+ lambda { verbose(true) { test_task.invoke } }.should show_error(/FailingTest/)
379
+ end
380
+
381
+ it 'should return failed tests even if fail_on_failure is false' do
382
+ test_task.using(:fail_on_failure=>false).invoke
383
+ test_task.failed_tests.should == ['FailingTest']
384
+ end
385
+
386
+ it 'should execute teardown task' do
387
+ lambda { test_task.invoke rescue nil }.should run_task('foo:test:teardown')
388
+ end
389
+
390
+ it 'should not update the last successful run timestamp' do
391
+ a_second_ago = Time.now - 1
392
+ touch_last_successful_test_run test_task, a_second_ago
393
+ test_task.invoke rescue nil
394
+ test_task.timestamp.should <= a_second_ago
395
+ end
396
+ end
397
+
398
+
399
+ describe Buildr::Project, '#test' do
400
+ it 'should return the project\'s test task' do
401
+ define('foo') { test.should be(task('test')) }
402
+ end
403
+
404
+ it 'should accept prerequisites for task' do
405
+ define('foo') { test 'prereq' }
406
+ project('foo').test.prerequisites.should include('prereq')
407
+ end
408
+
409
+ it 'should accept actions for task' do
410
+ task 'action'
411
+ define('foo') { test { task('action').invoke } }
412
+ lambda { project('foo').test.invoke }.should run_tasks('action')
413
+ end
414
+
415
+ it 'should set fail_on_failure true by default' do
416
+ define('foo').test.options[:fail_on_failure].should be_true
417
+ end
418
+
419
+ it 'should set fork mode by default' do
420
+ define('foo').test.options[:fork].should == :once
421
+ end
422
+
423
+ it 'should set properties to empty hash by default' do
424
+ define('foo').test.options[:properties].should == {}
425
+ end
426
+
427
+ it 'should set environment variables to empty hash by default' do
428
+ define('foo').test.options[:environment].should == {}
429
+ end
430
+
431
+ it 'should inherit options from parent project' do
432
+ define 'foo' do
433
+ test.using :fail_on_failure=>false, :fork=>:each, :properties=>{ :foo=>'bar' }, :environment=>{ 'config'=>'config.yaml' }
434
+ define 'bar' do
435
+ test.using :junit
436
+ test.options[:fail_on_failure].should be_false
437
+ test.options[:fork].should == :each
438
+ test.options[:properties][:foo].should == 'bar'
439
+ test.options[:environment]['config'].should == 'config.yaml'
440
+ end
441
+ end
442
+ end
443
+
444
+ it 'should clone options from parent project when using #using' do
445
+ define 'foo' do
446
+ define 'bar' do
447
+ test.using :fail_on_failure=>false, :fork=>:each, :properties=>{ :foo=>'bar' }, :environment=>{ 'config'=>'config.yaml' }
448
+ test.using :junit
449
+ end.invoke
450
+ test.options[:fail_on_failure].should be_true
451
+ test.options[:fork].should == :once
452
+ test.options[:properties].should == {}
453
+ test.options[:environment].should == {}
454
+ end
455
+ end
456
+
457
+ it 'should clone options from parent project when using #options' do
458
+ define 'foo' do
459
+ define 'bar' do
460
+ test.options[:fail_on_failure] = false
461
+ test.options[:fork] = :each
462
+ test.options[:properties][:foo] = 'bar'
463
+ test.options[:environment]['config'] = 'config.yaml'
464
+ test.using :junit
465
+ end.invoke
466
+ test.options[:fail_on_failure].should be_true
467
+ test.options[:fork].should == :once
468
+ test.options[:properties].should == {}
469
+ test.options[:environment].should == {}
470
+ end
471
+ end
472
+
473
+ it 'should accept to set a test property in the top project' do
474
+ define 'foo' do
475
+ test.options[:properties][:foo] = 'bar'
476
+ end
477
+ project('foo').test.options[:properties][:foo].should == 'bar'
478
+ end
479
+
480
+ it 'should accept to set a test property in a subproject' do
481
+ define 'foo' do
482
+ define 'bar' do
483
+ test.options[:properties][:bar] = 'baz'
484
+ end
485
+ end
486
+ project('foo:bar').test.options[:properties][:bar].should == 'baz'
487
+ end
488
+
489
+ it 'should not change options of unrelated projects when using #options' do
490
+ define 'foo' do
491
+ test.options[:properties][:foo] = 'bar'
492
+ end
493
+ define 'bar' do
494
+ test.options[:properties].should == {}
495
+ end
496
+ end
497
+
498
+ it "should run from project's build task" do
499
+ write 'src/main/java/Foo.java'
500
+ write 'src/test/java/FooTest.java'
501
+ define('foo')
502
+ lambda { task('foo:build').invoke }.should run_task('foo:test')
503
+ end
504
+ end
505
+
506
+
507
+ describe Buildr::Project, '#test.compile' do
508
+ it 'should identify compiler from project' do
509
+ write 'src/test/java/com/example/Test.java'
510
+ define('foo') do
511
+ test.compile.compiler.should eql(:javac)
512
+ end
513
+ end
514
+
515
+ it 'should include identified sources' do
516
+ write 'src/test/java/Test.java'
517
+ define('foo') do
518
+ test.compile.sources.should include(_('src/test/java'))
519
+ end
520
+ end
521
+
522
+ it 'should compile to target/test/<code>' do
523
+ define 'foo', :target=>'targeted' do
524
+ test.compile.using(:javac)
525
+ test.compile.target.should eql(file('targeted/test/classes'))
526
+ end
527
+ end
528
+
529
+ it 'should use main compile dependencies' do
530
+ define 'foo' do
531
+ compile.using(:javac).with 'group:id:jar:1.0'
532
+ test.compile.using(:javac)
533
+ end
534
+ project('foo').test.compile.dependencies.should include(artifact('group:id:jar:1.0'))
535
+ end
536
+
537
+ it 'should include the main compiled target in its dependencies' do
538
+ define 'foo' do
539
+ compile.using(:javac).into 'bytecode'
540
+ test.compile.using(:javac)
541
+ end
542
+ project('foo').test.compile.dependencies.should include(file('bytecode'))
543
+ end
544
+
545
+ it 'should include the test framework dependencies' do
546
+ define 'foo' do
547
+ test.compile.using(:javac)
548
+ test.using(:junit)
549
+ end
550
+ project('foo').test.compile.dependencies.should include(*artifacts(JUnit.dependencies))
551
+ end
552
+
553
+ it 'should clean after itself' do
554
+ write 'src/test/java/Nothing.java', 'class Nothing {}'
555
+ define('foo') { test.compile.into 'bytecode' }
556
+ project('foo').test.compile.invoke
557
+ lambda { project('foo').clean.invoke }.should change { File.exist?('bytecode') }.to(false)
558
+ end
559
+ end
560
+
561
+
562
+ describe Buildr::Project, '#test.resources' do
563
+ it 'should ignore resources unless they exist' do
564
+ define('foo').test.resources.sources.should be_empty
565
+ project('foo').test.resources.target.should be_nil
566
+ end
567
+
568
+ it 'should pick resources from src/test/resources if found' do
569
+ mkpath 'src/test/resources'
570
+ define('foo') { test.resources.sources.should include(file('src/test/resources')) }
571
+ end
572
+
573
+ it 'should copy to the resources target directory' do
574
+ write 'src/test/resources/config.xml', '</xml>'
575
+ define('foo', :target=>'targeted').test.invoke
576
+ file('targeted/test/resources/config.xml').should contain('</xml>')
577
+ end
578
+
579
+ it 'should create target directory even if no files to copy' do
580
+ define('foo').test.resources.filter.into('resources')
581
+ lambda { file(File.expand_path('resources')).invoke }.should change { File.exist?('resources') }.to(true)
582
+ end
583
+
584
+ it 'should execute alongside compile task' do
585
+ task 'action'
586
+ define('foo') { test.resources { task('action').invoke } }
587
+ lambda { project('foo').test.compile.invoke }.should run_tasks('action')
588
+ end
589
+ end
590
+
591
+
592
+ describe Buildr::TestTask, '#invoke' do
593
+ include TestHelper
594
+
595
+ def test_task
596
+ @test_task ||= define('foo') {
597
+ test.using(:junit)
598
+ test.instance_eval do
599
+ @framework.stub!(:tests).and_return(['PassingTest'])
600
+ @framework.stub!(:run).and_return(['PassingTest'])
601
+ end
602
+ }.test
603
+ end
604
+
605
+ it 'should require dependencies to exist' do
606
+ lambda { test_task.with('no-such.jar').invoke }.should \
607
+ raise_error(RuntimeError, /Don't know how to build/)
608
+ end
609
+
610
+ it 'should run all dependencies as prerequisites' do
611
+ file(File.expand_path('no-such.jar')) { task('prereq').invoke }
612
+ lambda { test_task.with('no-such.jar').invoke }.should run_tasks(['prereq', 'foo:test'])
613
+ end
614
+
615
+ it 'should run tests if they have never run' do
616
+ lambda { test_task.invoke }.should run_task('foo:test')
617
+ end
618
+
619
+ it 'should not run tests if test option is off' do
620
+ Buildr.options.test = false
621
+ lambda { test_task.invoke }.should_not run_task('foo:test')
622
+ end
623
+
624
+ describe 'when there was a successful test run already' do
625
+ before do
626
+ @a_second_ago = Time.now - 1
627
+ src = ['main/java/Foo.java', 'main/resources/config.xml', 'test/java/FooTest.java', 'test/resources/config-test.xml'].map { |f| File.join('src', f) }
628
+ target = ['classes/Foo.class', 'resources/config.xml', 'test/classes/FooTest.class', 'test/resources/config-test.xml'].map { |f| File.join('target', f) }
629
+ files = ['buildfile'] + src + target
630
+ files.each { |file| write file }
631
+ (files + files.map { |file| file.pathmap('%d') }).each { |file| File.utime(@a_second_ago, @a_second_ago, file) }
632
+ touch_last_successful_test_run test_task, @a_second_ago
633
+ end
634
+
635
+ it 'should not run tests if nothing changed' do
636
+ lambda { test_task.invoke }.should_not run_task('foo:test')
637
+ end
638
+
639
+ it 'should run tests if options.test is :all' do
640
+ Buildr.options.test = :all
641
+ lambda { test_task.invoke }.should run_task('foo:test')
642
+ end
643
+
644
+ it 'should run tests if main compile target changed' do
645
+ touch project('foo').compile.target.to_s
646
+ lambda { test_task.invoke }.should run_task('foo:test')
647
+ end
648
+
649
+ it 'should run tests if test compile target changed' do
650
+ touch test_task.compile.target.to_s
651
+ lambda { test_task.invoke }.should run_task('foo:test')
652
+ end
653
+
654
+ it 'should run tests if main resources changed' do
655
+ touch project('foo').resources.target.to_s
656
+ lambda { test_task.invoke }.should run_task('foo:test')
657
+ end
658
+
659
+ it 'should run tests if test resources changed' do
660
+ touch test_task.resources.target.to_s
661
+ lambda { test_task.invoke }.should run_task('foo:test')
662
+ end
663
+
664
+ it 'should run tests if compile-dependent project changed' do
665
+ write 'bar/src/main/java/Bar.java', 'public class Bar {}'
666
+ define('bar', :version=>'1.0', :base_dir=>'bar') { package :jar }
667
+ project('foo').compile.with project('bar')
668
+ lambda { test_task.invoke }.should run_task('foo:test')
669
+ end
670
+
671
+ it 'should run tests if test-dependent project changed' do
672
+ write 'bar/src/main/java/Bar.java', 'public class Bar {}'
673
+ define('bar', :version=>'1.0', :base_dir=>'bar') { package :jar }
674
+ test_task.with project('bar')
675
+ lambda { test_task.invoke }.should run_task('foo:test')
676
+ end
677
+
678
+ it 'should run tests if buildfile changed' do
679
+ touch 'buildfile'
680
+ lambda { test_task.invoke }.should run_task('foo:test')
681
+ end
682
+ end
683
+ end
684
+
685
+ describe Rake::Task, 'test' do
686
+ it 'should be recursive' do
687
+ define('foo') { define 'bar' }
688
+ lambda { task('test').invoke }.should run_tasks('foo:test', 'foo:bar:test')
689
+ end
690
+
691
+ it 'should be local task' do
692
+ define('foo') { define 'bar' }
693
+ lambda do
694
+ in_original_dir project('foo:bar').base_dir do
695
+ task('test').invoke
696
+ end
697
+ end.should run_task('foo:bar:test').but_not('foo:test')
698
+ end
699
+
700
+ it 'should stop at first failure' do
701
+ define('foo') { test { fail } }
702
+ define('bar') { test { fail } }
703
+ lambda { task('test').invoke rescue nil }.should run_tasks('foo:test').but_not('bar:test')
704
+ end
705
+
706
+ it 'should ignore failure if options.test is :all' do
707
+ define('foo') { test { fail } }
708
+ define('bar') { test { fail } }
709
+ options.test = :all
710
+ lambda { task('test').invoke rescue nil }.should run_tasks('foo:test', 'bar:test')
711
+ end
712
+
713
+ it 'should ignore failure if environment variable test is \'all\'' do
714
+ define('foo') { test { fail } }
715
+ define('bar') { test { fail } }
716
+ ENV['test'] = 'all'
717
+ lambda { task('test').invoke rescue nil }.should run_tasks('foo:test', 'bar:test')
718
+ end
719
+
720
+ it 'should ignore failure if environment variable TEST is \'all\'' do
721
+ define('foo') { test { fail } }
722
+ define('bar') { test { fail } }
723
+ ENV['TEST'] = 'all'
724
+ lambda { task('test').invoke rescue nil }.should run_tasks('foo:test', 'bar:test')
725
+ end
726
+
727
+ it 'should execute no tests if options.test is false' do
728
+ define('foo') { test { fail } }
729
+ define('bar') { test { fail } }
730
+ options.test = false
731
+ lambda { task('test').invoke rescue nil }.should_not run_tasks('foo:test', 'bar:test')
732
+ end
733
+
734
+ it 'should execute no tests if environment variable test is \'no\'' do
735
+ define('foo') { test { fail } }
736
+ define('bar') { test { fail } }
737
+ ENV['test'] = 'no'
738
+ lambda { task('test').invoke rescue nil }.should_not run_tasks('foo:test', 'bar:test')
739
+ end
740
+
741
+ it 'should execute no tests if environment variable TEST is \'no\'' do
742
+ define('foo') { test { fail } }
743
+ define('bar') { test { fail } }
744
+ ENV['TEST'] = 'no'
745
+ lambda { task('test').invoke rescue nil }.should_not run_tasks('foo:test', 'bar:test')
746
+ end
747
+ end
748
+
749
+
750
+ describe 'test rule' do
751
+ include TestHelper
752
+
753
+ it 'should execute test task on local project' do
754
+ define('foo') { define 'bar' }
755
+ lambda { task('test:something').invoke }.should run_task('foo:test')
756
+ end
757
+
758
+ it 'should reset tasks to specific pattern' do
759
+ define 'foo' do
760
+ test.using(:junit)
761
+ test.instance_eval { @framework.stub!(:tests).and_return(['something', 'nothing']) }
762
+ define 'bar' do
763
+ test.using(:junit)
764
+ test.instance_eval { @framework.stub!(:tests).and_return(['something', 'nothing']) }
765
+ end
766
+ end
767
+ task('test:something').invoke
768
+ ['foo', 'foo:bar'].map { |name| project(name) }.each do |project|
769
+ project.test.tests.should include('something')
770
+ project.test.tests.should_not include('nothing')
771
+ end
772
+ end
773
+
774
+ it 'should apply *name* pattern' do
775
+ define 'foo' do
776
+ test.using(:junit)
777
+ test.instance_eval { @framework.stub!(:tests).and_return(['prefix-something-suffix']) }
778
+ end
779
+ task('test:something').invoke
780
+ project('foo').test.tests.should include('prefix-something-suffix')
781
+ end
782
+
783
+ it 'should not apply *name* pattern if asterisks used' do
784
+ define 'foo' do
785
+ test.using(:junit)
786
+ test.instance_eval { @framework.stub!(:tests).and_return(['prefix-something', 'prefix-something-suffix']) }
787
+ end
788
+ task('test:*something').invoke
789
+ project('foo').test.tests.should include('prefix-something')
790
+ project('foo').test.tests.should_not include('prefix-something-suffix')
791
+ end
792
+
793
+ it 'should accept multiple tasks separated by commas' do
794
+ define 'foo' do
795
+ test.using(:junit)
796
+ test.instance_eval { @framework.stub!(:tests).and_return(['foo', 'bar', 'baz']) }
797
+ end
798
+ task('test:foo,bar').invoke
799
+ project('foo').test.tests.should include('foo')
800
+ project('foo').test.tests.should include('bar')
801
+ project('foo').test.tests.should_not include('baz')
802
+ end
803
+
804
+ it 'should execute only the named tests' do
805
+ write 'src/test/java/TestSomething.java',
806
+ 'public class TestSomething extends junit.framework.TestCase { public void testNothing() {} }'
807
+ write 'src/test/java/TestFails.java',
808
+ 'public class TestFails extends junit.framework.TestCase { public void testFailure() { fail(); } }'
809
+ define 'foo'
810
+ task('test:Something').invoke
811
+ end
812
+
813
+ it 'should execute the named tests even if the test task is not needed' do
814
+ define 'foo' do
815
+ test.using(:junit)
816
+ test.instance_eval { @framework.stub!(:tests).and_return(['something', 'nothing']) }
817
+ end
818
+ touch_last_successful_test_run project('foo').test
819
+ task('test:something').invoke
820
+ project('foo').test.tests.should include('something')
821
+ end
822
+
823
+ it 'should not update the last successful test run timestamp' do
824
+ define 'foo' do
825
+ test.using(:junit)
826
+ test.instance_eval { @framework.stub!(:tests).and_return(['something', 'nothing']) }
827
+ end
828
+ a_second_ago = Time.now - 1
829
+ touch_last_successful_test_run project('foo').test, a_second_ago
830
+ task('test:something').invoke
831
+ project('foo').test.timestamp.should <= a_second_ago
832
+ end
833
+ end
834
+
835
+
836
+ describe Buildr::Options, 'test' do
837
+ it 'should be true by default' do
838
+ Buildr.options.test.should be_true
839
+ end
840
+
841
+ ['skip', 'no', 'off', 'false'].each do |value|
842
+ it "should be false if test environment variable is '#{value}'" do
843
+ lambda { ENV['test'] = value }.should change { Buildr.options.test }.to(false)
844
+ end
845
+ end
846
+
847
+ ['skip', 'no', 'off', 'false'].each do |value|
848
+ it "should be false if TEST environment variable is '#{value}'" do
849
+ lambda { ENV['TEST'] = value }.should change { Buildr.options.test }.to(false)
850
+ end
851
+ end
852
+
853
+ it 'should be :all if test environment variable is all' do
854
+ lambda { ENV['test'] = 'all' }.should change { Buildr.options.test }.to(:all)
855
+ end
856
+
857
+ it 'should be :all if TEST environment variable is all' do
858
+ lambda { ENV['TEST'] = 'all' }.should change { Buildr.options.test }.to(:all)
859
+ end
860
+
861
+ it 'should be true and warn for any other value' do
862
+ ENV['TEST'] = 'funky'
863
+ lambda { Buildr.options.test.should be(true) }.should show_warning(/expecting the environment variable/i)
864
+ end
865
+ end
866
+
867
+
868
+ describe Buildr, 'integration' do
869
+ it 'should return the same task from all contexts' do
870
+ task = task('integration')
871
+ define 'foo' do
872
+ integration.should be(task)
873
+ define 'bar' do
874
+ integration.should be(task)
875
+ end
876
+ end
877
+ integration.should be(task)
878
+ end
879
+
880
+ it 'should respond to :setup and return setup task' do
881
+ setup = integration.setup
882
+ define('foo') { integration.setup.should be(setup) }
883
+ end
884
+
885
+ it 'should respond to :setup and add prerequisites to integration:setup' do
886
+ define('foo') { integration.setup 'prereq' }
887
+ integration.setup.prerequisites.should include('prereq')
888
+ end
889
+
890
+ it 'should respond to :setup and add action for integration:setup' do
891
+ action = task('action')
892
+ define('foo') { integration.setup { action.invoke } }
893
+ lambda { integration.setup.invoke }.should run_tasks(action)
894
+ end
895
+
896
+ it 'should respond to :teardown and return teardown task' do
897
+ teardown = integration.teardown
898
+ define('foo') { integration.teardown.should be(teardown) }
899
+ end
900
+
901
+ it 'should respond to :teardown and add prerequisites to integration:teardown' do
902
+ define('foo') { integration.teardown 'prereq' }
903
+ integration.teardown.prerequisites.should include('prereq')
904
+ end
905
+
906
+ it 'should respond to :teardown and add action for integration:teardown' do
907
+ action = task('action')
908
+ define('foo') { integration.teardown { action.invoke } }
909
+ lambda { integration.teardown.invoke }.should run_tasks(action)
910
+ end
911
+ end
912
+
913
+
914
+ describe Rake::Task, 'integration' do
915
+ it 'should be a local task' do
916
+ define('foo') { test.using :integration }
917
+ define('bar', :base_dir=>'other') { test.using :integration }
918
+ lambda { task('integration').invoke }.should run_task('foo:test').but_not('bar:test')
919
+ end
920
+
921
+ it 'should be a recursive task' do
922
+ define 'foo' do
923
+ test.using :integration
924
+ define('bar') { test.using :integration }
925
+ end
926
+ lambda { task('integration').invoke }.should run_tasks('foo:test', 'foo:bar:test')
927
+ end
928
+
929
+ it 'should find nested integration tests' do
930
+ define 'foo' do
931
+ define('bar') { test.using :integration }
932
+ end
933
+ lambda { task('integration').invoke }.should run_tasks('foo:bar:test').but_not('foo:test')
934
+ end
935
+
936
+ it 'should ignore nested regular tasks' do
937
+ define 'foo' do
938
+ test.using :integration
939
+ define('bar') { test.using :integration=>false }
940
+ end
941
+ lambda { task('integration').invoke }.should run_tasks('foo:test').but_not('foo:bar:test')
942
+ end
943
+
944
+ it 'should agree not to run the same tasks as test' do
945
+ define 'foo' do
946
+ define 'bar' do
947
+ test.using :integration
948
+ define('baz') { test.using :integration=>false }
949
+ end
950
+ end
951
+ lambda { task('test').invoke }.should run_tasks('foo:test', 'foo:bar:baz:test').but_not('foo:bar:test')
952
+ lambda { task('integration').invoke }.should run_tasks('foo:bar:test').but_not('foo:test', 'foo:bar:baz:test')
953
+ end
954
+
955
+ it 'should run setup task before any project integration tests' do
956
+ define('foo') { test.using :integration }
957
+ define('bar') { test.using :integration }
958
+ lambda { task('integration').invoke }.should run_tasks([integration.setup, 'bar:test'], [integration.setup, 'foo:test'])
959
+ end
960
+
961
+ it 'should run teardown task after all project integrations tests' do
962
+ define('foo') { test.using :integration }
963
+ define('bar') { test.using :integration }
964
+ lambda { task('integration').invoke }.should run_tasks(['bar:test', integration.teardown], ['foo:test', integration.teardown])
965
+ end
966
+
967
+ it 'should run test cases marked for integration' do
968
+ write 'src/test/java/FailingTest.java',
969
+ 'public class FailingTest extends junit.framework.TestCase { public void testNothing() { assertTrue(false); } }'
970
+ define('foo') { test.using :integration }
971
+ lambda { task('test').invoke }.should_not raise_error
972
+ lambda { task('integration').invoke }.should raise_error(RuntimeError, /tests failed/i)
973
+ end
974
+
975
+ it 'should run setup and teardown tasks marked for integration' do
976
+ define('foo') { test.using :integration }
977
+ lambda { task('test').invoke }.should run_tasks().but_not('foo:test:setup', 'foo:test:teardown')
978
+ lambda { task('integration').invoke }.should run_tasks('foo:test:setup', 'foo:test:teardown')
979
+ end
980
+
981
+ it 'should run test actions marked for integration' do
982
+ task 'action'
983
+ define 'foo' do
984
+ test.using :integration, :junit
985
+ end
986
+ lambda { task('test').invoke }.should_not change { project('foo').test.passed_tests }
987
+ lambda { task('integration').invoke }.should change { project('foo').test.passed_tests }
988
+ project('foo').test.passed_tests.should be_empty
989
+ end
990
+
991
+ it 'should not fail if test=all' do
992
+ write 'src/test/java/FailingTest.java',
993
+ 'public class FailingTest extends junit.framework.TestCase { public void testNothing() { assertTrue(false); } }'
994
+ define('foo') { test.using :integration }
995
+ options.test = :all
996
+ lambda { task('integration').invoke }.should_not raise_error
997
+ end
998
+
999
+ it 'should execute by local package task' do
1000
+ define 'foo', :version=>'1.0' do
1001
+ test.using :integration
1002
+ package :jar
1003
+ end
1004
+ lambda { task('package').invoke }.should run_tasks(['foo:package', 'foo:test'])
1005
+ end
1006
+
1007
+ it 'should execute by local package task along with unit tests' do
1008
+ define 'foo', :version=>'1.0' do
1009
+ test.using :integration
1010
+ package :jar
1011
+ define('bar') { test.using :integration=>false }
1012
+ end
1013
+ lambda { task('package').invoke }.should run_tasks(['foo:package', 'foo:test'],
1014
+ ['foo:bar:test', 'foo:bar:package'])
1015
+ end
1016
+
1017
+ it 'should not execute by local package task if test=no' do
1018
+ define 'foo', :version=>'1.0' do
1019
+ test.using :integration
1020
+ package :jar
1021
+ end
1022
+ options.test = false
1023
+ lambda { task('package').invoke }.should run_task('foo:package').but_not('foo:test')
1024
+ end
1025
+ end
1026
+
1027
+
1028
+ describe 'integration rule' do
1029
+ it 'should execute integration tests on local project' do
1030
+ define 'foo' do
1031
+ test.using :junit, :integration
1032
+ define 'bar'
1033
+ end
1034
+ lambda { task('integration:something').invoke }.should run_task('foo:test')
1035
+ end
1036
+
1037
+ it 'should reset tasks to specific pattern' do
1038
+ define 'foo' do
1039
+ test.using :junit, :integration
1040
+ test.instance_eval { @framework.stub!(:tests).and_return(['something', 'nothing']) }
1041
+ define 'bar' do
1042
+ test.using :junit, :integration
1043
+ test.instance_eval { @framework.stub!(:tests).and_return(['something', 'nothing']) }
1044
+ end
1045
+ end
1046
+ task('integration:something').invoke
1047
+ ['foo', 'foo:bar'].map { |name| project(name) }.each do |project|
1048
+ project.test.tests.should include('something')
1049
+ project.test.tests.should_not include('nothing')
1050
+ end
1051
+ end
1052
+
1053
+ it 'should apply *name* pattern' do
1054
+ define 'foo' do
1055
+ test.using :junit, :integration
1056
+ test.instance_eval { @framework.stub!(:tests).and_return(['prefix-something-suffix']) }
1057
+ end
1058
+ task('integration:something').invoke
1059
+ project('foo').test.tests.should include('prefix-something-suffix')
1060
+ end
1061
+
1062
+ it 'should not apply *name* pattern if asterisks used' do
1063
+ define 'foo' do
1064
+ test.using :junit, :integration
1065
+ test.instance_eval { @framework.stub!(:tests).and_return(['prefix-something', 'prefix-something-suffix']) }
1066
+ end
1067
+ task('integration:*something').invoke
1068
+ project('foo').test.tests.should include('prefix-something')
1069
+ project('foo').test.tests.should_not include('prefix-something-suffix')
1070
+ end
1071
+
1072
+ it 'should accept multiple tasks separated by commas' do
1073
+ define 'foo' do
1074
+ test.using :junit, :integration
1075
+ test.instance_eval { @framework.stub!(:tests).and_return(['foo', 'bar', 'baz']) }
1076
+ end
1077
+ task('integration:foo,bar').invoke
1078
+ project('foo').test.tests.should include('foo')
1079
+ project('foo').test.tests.should include('bar')
1080
+ project('foo').test.tests.should_not include('baz')
1081
+ end
1082
+
1083
+ it 'should execute only the named tests' do
1084
+ write 'src/test/java/TestSomething.java',
1085
+ 'public class TestSomething extends junit.framework.TestCase { public void testNothing() {} }'
1086
+ write 'src/test/java/TestFails.java',
1087
+ 'public class TestFails extends junit.framework.TestCase { public void testFailure() { fail(); } }'
1088
+ define('foo') { test.using :junit, :integration }
1089
+ task('integration:Something').invoke
1090
+ end
1091
+ end