/
test_project_generator.rb
699 lines (618 loc) · 45.1 KB
/
test_project_generator.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
require File.expand_path(File.dirname(__FILE__) + '/helper')
describe "ProjectGenerator" do
def setup
@apptmp = "#{Dir.tmpdir}/padrino-tests/#{SecureRandom.hex}"
`mkdir -p #{@apptmp}`
end
def teardown
`rm -rf #{@apptmp}`
`rm -rf /tmp/project`
end
describe 'the project generator' do
it 'should allow simple generator to run and create base_app with no options' do
capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}") }
assert_dir_exists("#{@apptmp}/sample_project")
assert_match_in_file(/module SampleProject/,"#{@apptmp}/sample_project/app/app.rb")
assert_match_in_file(/class App < Padrino::Application/,"#{@apptmp}/sample_project/app/app.rb")
assert_match_in_file("Padrino.mount('SampleProject::App', :app_file => Padrino.root('app/app.rb')).to('/')", "#{@apptmp}/sample_project/config/apps.rb")
assert_file_exists("#{@apptmp}/sample_project/config/boot.rb")
assert_file_exists("#{@apptmp}/sample_project/Rakefile")
assert_file_exists("#{@apptmp}/sample_project/exe/sample_project")
assert_file_exists("#{@apptmp}/sample_project/public/favicon.ico")
assert_dir_exists("#{@apptmp}/sample_project/public/images")
assert_dir_exists("#{@apptmp}/sample_project/public/javascripts")
assert_dir_exists("#{@apptmp}/sample_project/public/stylesheets")
assert_dir_exists("#{@apptmp}/sample_project/app/views")
assert_dir_exists("#{@apptmp}/sample_project/app/views/layouts")
end
it 'should generate a valid name' do
capture_io { generate(:project, 'project.com', "--root=#{@apptmp}") }
assert_dir_exists("#{@apptmp}/project.com")
assert_match_in_file(/module ProjectCom/, "#{@apptmp}/project.com/app/app.rb")
assert_match_in_file(/class App < Padrino::Application/, "#{@apptmp}/project.com/app/app.rb")
assert_match_in_file("Padrino.mount('ProjectCom::App', :app_file => Padrino.root('app/app.rb')).to('/')", "#{@apptmp}/project.com/config/apps.rb")
capture_io { generate(:app, 'ws-dci-2011', "--root=#{@apptmp}/project.com") }
assert_dir_exists("#{@apptmp}/project.com/ws_dci_2011")
assert_match_in_file(/module ProjectCom/, "#{@apptmp}/project.com/ws_dci_2011/app.rb")
assert_match_in_file(/class WsDci2011 < Padrino::Application/, "#{@apptmp}/project.com/ws_dci_2011/app.rb")
assert_match_in_file("Padrino.mount('ProjectCom::WsDci2011', :app_file => Padrino.root('ws_dci_2011/app.rb')).to('/ws_dci_2011')", "#{@apptmp}/project.com/config/apps.rb")
end
it 'should generate nested path with dashes in name' do
capture_io { generate(:project, 'sample-project', "--root=#{@apptmp}") }
assert_dir_exists("#{@apptmp}/sample-project")
assert_match_in_file(/module SampleProject/, "#{@apptmp}/sample-project/app/app.rb")
assert_match_in_file(/class App < Padrino::Application/, "#{@apptmp}/sample-project/app/app.rb")
assert_match_in_file("Padrino.mount('SampleProject::App', :app_file => Padrino.root('app/app.rb')).to('/')", "#{@apptmp}/sample-project/config/apps.rb")
capture_io { generate(:app, 'ws-dci-2011', "--root=#{@apptmp}/sample-project") }
assert_dir_exists("#{@apptmp}/sample-project/ws_dci_2011")
assert_match_in_file(/module SampleProject/, "#{@apptmp}/sample-project/ws_dci_2011/app.rb")
assert_match_in_file(/class WsDci2011 < Padrino::Application/, "#{@apptmp}/sample-project/ws_dci_2011/app.rb")
assert_match_in_file("Padrino.mount('SampleProject::WsDci2011', :app_file => Padrino.root('ws_dci_2011/app.rb')).to('/ws_dci_2011')", "#{@apptmp}/sample-project/config/apps.rb")
end
it 'should raise an Error when given invalid constant names' do
assert_raises(::NameError) { capture_io { generate(:project, "123asdf", "--root=#{@apptmp}") } }
assert_raises(::NameError) { capture_io { generate(:project, "./sample_project", "--root=#{@apptmp}") } }
end
it 'should display the right path' do
out, err = capture_io { generate(:project, 'project', "--root=/tmp") }
assert_dir_exists("/tmp/project")
assert_match(/cd \/tmp\/project/, out)
end
it 'should allow specifying alternate application name' do
capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--app=base_app') }
assert_dir_exists("#{@apptmp}/sample_project")
assert_match_in_file(/module SampleProject/,"#{@apptmp}/sample_project/app/app.rb")
assert_match_in_file(/class BaseApp < Padrino::Application/,"#{@apptmp}/sample_project/app/app.rb")
assert_match_in_file("Padrino.mount('SampleProject::BaseApp', :app_file => Padrino.root('app/app.rb')).to('/')", "#{@apptmp}/sample_project/config/apps.rb")
assert_file_exists("#{@apptmp}/sample_project/config/boot.rb")
assert_file_exists("#{@apptmp}/sample_project/public/favicon.ico")
end
it 'should add database tasks to Rakefile if an ORM is defined' do
capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--app=base_app', '--orm=activerecord') }
assert_match_in_file('PadrinoTasks.use(:database)',"#{@apptmp}/sample_project/Rakefile")
end
it 'should avoid add database tasks on Rakefile if no ORM is specified' do
capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--app=base_app') }
assert_no_match_in_file('PadrinoTasks.use(:database)',"#{@apptmp}/sample_project/Rakefile")
end
it 'should generate lean project' do
capture_io { generate(:project,'sample_project', '--lean', "--root=#{@apptmp}") }
assert_file_exists("#{@apptmp}/sample_project/public/favicon.ico")
assert_file_exists("#{@apptmp}/sample_project/config/boot.rb")
assert_no_file_exists("#{@apptmp}/sample_project/app/app.rb")
assert_no_match_in_file(/Padrino.mount\('SampleProject::App'/, "#{@apptmp}/sample_project/config/apps.rb")
end
it 'should generate lean project correctly even if the component is specified' do
out, err = capture_io { generate(:project,'sample_project', '--lean', "--root=#{@apptmp}", "--orm=activerecord", "--stylesheet=compass") }
assert_match("", err)
end
it 'should generate tiny skeleton' do
capture_io { generate(:project,'sample_project', '--tiny', "--root=#{@apptmp}") }
assert_dir_exists("#{@apptmp}/sample_project")
assert_dir_exists("#{@apptmp}/sample_project/app")
assert_file_exists("#{@apptmp}/sample_project/app/controllers.rb")
assert_file_exists("#{@apptmp}/sample_project/app/helpers.rb")
assert_file_exists("#{@apptmp}/sample_project/app/mailers.rb")
assert_dir_exists("#{@apptmp}/sample_project/public/images")
assert_dir_exists("#{@apptmp}/sample_project/public/javascripts")
assert_dir_exists("#{@apptmp}/sample_project/public/stylesheets")
assert_match_in_file(/:notifier/,"#{@apptmp}/sample_project/app/mailers.rb")
assert_match_in_file(/module Helper/, "#{@apptmp}/sample_project/app/helpers.rb")
assert_match_in_file(/helpers Helper/, "#{@apptmp}/sample_project/app/helpers.rb")
assert_no_file_exists("#{@apptmp}/sample_project/demo/helpers")
assert_no_file_exists("#{@apptmp}/sample_project/demo/controllers")
end
it 'should generate gemspec and special files if gem is expected' do
capture_io { generate(:project,'sample_gem', '--gem', "--root=#{@apptmp}") }
assert_file_exists("#{@apptmp}/sample_gem/sample_gem.gemspec")
assert_match_in_file(/^gemspec/,"#{@apptmp}/sample_gem/Gemfile")
assert_match_in_file(/^module SampleGem/,"#{@apptmp}/sample_gem/app/app.rb")
assert_match_in_file(/class App/,"#{@apptmp}/sample_gem/app/app.rb")
assert_file_exists("#{@apptmp}/sample_gem/README.md")
assert_no_file_exists("#{@apptmp}/sample_gem/tmp/.keep")
assert_no_file_exists("#{@apptmp}/sample_gem/log/.keep")
end
it 'should generate gemspec and special files with dashes in name' do
capture_io { generate(:project,'sample-gem', '--gem', "--root=#{@apptmp}") }
assert_file_exists("#{@apptmp}/sample-gem/sample-gem.gemspec")
assert_file_exists("#{@apptmp}/sample-gem/README.md")
assert_match_in_file(/\/lib\/sample-gem\/version/,"#{@apptmp}/sample-gem/sample-gem.gemspec")
assert_match_in_file(/"sample-gem"/,"#{@apptmp}/sample-gem/sample-gem.gemspec")
assert_match_in_file(/SampleGem::VERSION/,"#{@apptmp}/sample-gem/sample-gem.gemspec")
assert_match_in_file(/^# SampleGem/,"#{@apptmp}/sample-gem/README.md")
assert_match_in_file(/SampleGem::App/,"#{@apptmp}/sample-gem/README.md")
assert_match_in_file(/^module SampleGem/,"#{@apptmp}/sample-gem/lib/sample-gem.rb")
assert_match_in_file(/gem! "sample-gem"/,"#{@apptmp}/sample-gem/lib/sample-gem.rb")
assert_match_in_file(/^module SampleGem/,"#{@apptmp}/sample-gem/lib/sample-gem/version.rb")
assert_match_in_file(/^module SampleGem/,"#{@apptmp}/sample-gem/app/app.rb")
assert_match_in_file(/class App/,"#{@apptmp}/sample-gem/app/app.rb")
end
it 'should not create models folder if no orm is chosen' do
capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '--orm=none') }
assert_no_dir_exists("#{@apptmp}/sample_project/models")
end
it 'should not create tests folder if no test framework is chosen' do
capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '--test=none') }
assert_no_dir_exists("#{@apptmp}/sample_project/test")
end
it 'should place app specific names into correct files' do
capture_io { generate(:project, 'warepedia', "--root=#{@apptmp}", '--script=none') }
assert_match_in_file(/module Warepedia/m, "#{@apptmp}/warepedia/app/app.rb")
assert_match_in_file(/class App < Padrino::Application/m, "#{@apptmp}/warepedia/app/app.rb")
assert_match_in_file("Padrino.mount('Warepedia::App', :app_file => Padrino.root('app/app.rb')).to('/')", "#{@apptmp}/warepedia/config/apps.rb")
end
it 'should store and apply session_secret' do
capture_io { generate(:project,'sample_project', '--tiny',"--root=#{@apptmp}") }
assert_match_in_file(/set :session_secret, '[0-9A-z]*'/, "#{@apptmp}/sample_project/config/apps.rb")
end
it 'should create components file containing options chosen with defaults' do
capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}") }
components_chosen = YAML.load_file("#{@apptmp}/sample_project/.components")
assert_equal 'none', components_chosen[:orm]
assert_equal 'none', components_chosen[:test]
assert_equal 'none', components_chosen[:mock]
assert_equal 'none', components_chosen[:script]
assert_equal 'none', components_chosen[:renderer]
end
it 'should create components file containing options chosen' do
component_options = ['--orm=datamapper', '--test=rspec', '--mock=mocha', '--script=prototype', '--renderer=erb', '--stylesheet=less']
capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", *component_options) }
components_chosen = YAML.load_file("#{@apptmp}/sample_project/.components")
assert_equal 'datamapper', components_chosen[:orm]
assert_equal 'rspec', components_chosen[:test]
assert_equal 'mocha', components_chosen[:mock]
assert_equal 'prototype', components_chosen[:script]
assert_equal 'erb', components_chosen[:renderer]
assert_equal 'less', components_chosen[:stylesheet]
end
it 'should output to log components being applied' do
component_options = ['--orm=datamapper', '--test=rspec', '--mock=mocha', '--script=prototype', '--renderer=erb','--stylesheet=less']
out, err = capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", *component_options) }
assert_match(/applying.*?datamapper.*?orm/, out)
assert_match(/applying.*?rspec.*?test/, out)
assert_match(/applying.*?mocha.*?mock/, out)
assert_match(/applying.*?prototype.*?script/, out)
assert_match(/applying.*?erb.*?renderer/, out)
assert_match(/applying.*?less.*?stylesheet/, out)
end
it 'should output gem files for base app' do
capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none') }
assert_match_in_file(/gem 'padrino'/, "#{@apptmp}/sample_project/Gemfile")
end
it 'should create .keep files for empty directories that are required for running application' do
capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", "--stylesheet=sass", "--orm=sequel") }
assert_file_exists("#{@apptmp}/sample_project/tmp/.keep")
assert_file_exists("#{@apptmp}/sample_project/log/.keep")
end
it 'should allow to pass upcased name as the app name' do
capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", "--app=API") }
assert_file_exists("#{@apptmp}/sample_project/app/app.rb")
assert_match_in_file(/class API < Padrino::Application/, "#{@apptmp}/sample_project/app/app.rb")
end
end
describe "a generator for mock component" do
it 'should properly generate for rr and minitest' do
out, err = capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--mock=rr', '--test=minitest', '--script=none') }
assert_match(/applying.*?rr.*?mock/, out)
assert_match_in_file(/gem 'rr'/, "#{@apptmp}/sample_project/Gemfile")
assert_match_in_file(/include RR::Adapters::MiniTest/, "#{@apptmp}/sample_project/test/test_config.rb")
end
it 'should properly generater for rr and bacon' do
out, err = capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--mock=rr', '--test=bacon', '--script=none') }
assert_match(/applying.*?rr.*?mock/, out)
assert_match_in_file(/gem 'rr'/, "#{@apptmp}/sample_project/Gemfile")
assert_match_in_file(/include RR::Adapters::TestUnit/m, "#{@apptmp}/sample_project/test/test_config.rb")
end
it 'should properly generate for rr and rspec' do
out, err = capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--test=rspec', '--mock=rr', '--script=none') }
assert_match(/applying.*?rr.*?mock/, out)
assert_match_in_file(/gem 'rr', :require => false/, "#{@apptmp}/sample_project/Gemfile")
assert_match_in_file(/require 'rr'/m, "#{@apptmp}/sample_project/spec/spec_helper.rb")
end
it 'should properly generate for mocha and rspec' do
out, err = capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}",'--test=rspec', '--mock=mocha', '--script=none') }
assert_match(/applying.*?mocha.*?mock/, out)
assert_match_in_file(/gem 'mocha'/, "#{@apptmp}/sample_project/Gemfile")
assert_match_in_file(/conf.mock_with :mocha/m, "#{@apptmp}/sample_project/spec/spec_helper.rb")
end
end
describe "the generator for orm components" do
describe "for sequel" do
it 'should properly generate default' do
@app.instance_eval("undef setup_orm if respond_to?('setup_orm')")
out, err = capture_io { generate(:project, 'project.com', "--root=#{@apptmp}", '--orm=sequel', '--script=none') }
assert_match(/applying.*?sequel.*?orm/, out)
assert_match_in_file(/gem 'sequel'/, "#{@apptmp}/project.com/Gemfile")
assert_match_in_file(/gem 'sqlite3'/, "#{@apptmp}/project.com/Gemfile")
assert_match_in_file(/Sequel.connect/, "#{@apptmp}/project.com/config/database.rb")
assert_match_in_file(%r{sqlite://}, "#{@apptmp}/project.com/config/database.rb")
assert_match_in_file(%r{project_com}, "#{@apptmp}/project.com/config/database.rb")
end
it 'should properly generate mysql (default to mysql2)' do
out, err = capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--orm=sequel', '--adapter=mysql') }
assert_match_in_file(/gem 'mysql2'/, "#{@apptmp}/sample_project/Gemfile")
assert_match_in_file(%r{"mysql2://}, "#{@apptmp}/sample_project/config/database.rb")
assert_match_in_file(/sample_project_development/, "#{@apptmp}/sample_project/config/database.rb")
end
it 'should properly generate mysql2' do
out, err = capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--orm=sequel', '--adapter=mysql2') }
assert_match_in_file(/gem 'mysql2'/, "#{@apptmp}/sample_project/Gemfile")
assert_match_in_file(%r{"mysql2://}, "#{@apptmp}/sample_project/config/database.rb")
assert_match_in_file(/sample_project_development/, "#{@apptmp}/sample_project/config/database.rb")
end
it 'should properly generate mysql-gem' do
out, err = capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--orm=sequel', '--adapter=mysql-gem') }
assert_match_in_file(/gem 'mysql'/, "#{@apptmp}/sample_project/Gemfile")
assert_match_in_file(%r{"mysql://}, "#{@apptmp}/sample_project/config/database.rb")
assert_match_in_file(/sample_project_development/, "#{@apptmp}/sample_project/config/database.rb")
end
it 'should properly generate sqlite3' do
out, err = capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--orm=sequel', '--adapter=sqlite') }
assert_match_in_file(/gem 'sqlite3'/, "#{@apptmp}/sample_project/Gemfile")
assert_match_in_file(%r{sqlite://}, "#{@apptmp}/sample_project/config/database.rb")
assert_match_in_file(/sample_project_development/, "#{@apptmp}/sample_project/config/database.rb")
end
it 'should properly generate postgres' do
out, err = capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--orm=sequel', '--adapter=postgres') }
assert_match_in_file(/gem 'pg'/, "#{@apptmp}/sample_project/Gemfile")
assert_match_in_file(%r{"postgres://}, "#{@apptmp}/sample_project/config/database.rb")
assert_match_in_file(/sample_project_development/, "#{@apptmp}/sample_project/config/database.rb")
end
end
describe "for activerecord" do
it 'should properly generate default' do
out, err = capture_io { generate(:project, 'project.com', "--root=#{@apptmp}", '--orm=activerecord', '--script=none') }
assert_match(/applying.*?activerecord.*?orm/, out)
assert_match_in_file(/gem 'activerecord', '>= 3.1', :require => 'active_record'/, "#{@apptmp}/project.com/Gemfile")
assert_match_in_file(/gem 'sqlite3'/, "#{@apptmp}/project.com/Gemfile")
assert_match_in_file(/ActiveRecord::Base.establish_connection/, "#{@apptmp}/project.com/config/database.rb")
assert_match_in_file(/project_com/, "#{@apptmp}/project.com/config/database.rb")
end
it 'should properly generate mysql (default to mysql2)' do
out, err = capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--orm=activerecord','--adapter=mysql') }
assert_match_in_file(/gem 'mysql2'/, "#{@apptmp}/sample_project/Gemfile")
assert_match_in_file(/sample_project_development/, "#{@apptmp}/sample_project/config/database.rb")
assert_match_in_file(%r{:adapter => 'mysql2'}, "#{@apptmp}/sample_project/config/database.rb")
end
it 'should properly generate mysql2' do
out, err = capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--orm=activerecord','--adapter=mysql2') }
assert_match_in_file(/gem 'mysql2'/, "#{@apptmp}/sample_project/Gemfile")
assert_match_in_file(/sample_project_development/, "#{@apptmp}/sample_project/config/database.rb")
assert_match_in_file(%r{:adapter => 'mysql2'}, "#{@apptmp}/sample_project/config/database.rb")
end
it 'should properly generate mysql-gem' do
out, err = capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--orm=activerecord','--adapter=mysql-gem') }
assert_match_in_file(/gem 'mysql', '~> 2.8.1'/, "#{@apptmp}/sample_project/Gemfile")
assert_match_in_file(/sample_project_development/, "#{@apptmp}/sample_project/config/database.rb")
assert_match_in_file(%r{:adapter => 'mysql'}, "#{@apptmp}/sample_project/config/database.rb")
end
it 'should properly generate sqlite3' do
out, err = capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--orm=activerecord', '--adapter=sqlite') }
assert_match_in_file(/gem 'sqlite3'/, "#{@apptmp}/sample_project/Gemfile")
assert_match_in_file(/sample_project_development.db/, "#{@apptmp}/sample_project/config/database.rb")
assert_match_in_file(%r{:adapter => 'sqlite3'}, "#{@apptmp}/sample_project/config/database.rb")
end
it 'should properly generate postgres' do
out, err = capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--orm=activerecord', '--adapter=postgres') }
assert_match_in_file(/gem 'pg'$/, "#{@apptmp}/sample_project/Gemfile")
assert_match_in_file(/sample_project_development/, "#{@apptmp}/sample_project/config/database.rb")
assert_match_in_file(%r{:adapter => 'postgresql'}, "#{@apptmp}/sample_project/config/database.rb")
end
end
describe "for datamapper" do
it 'should properly generate default' do
out, err = capture_io { generate(:project, 'project.com', "--root=#{@apptmp}", '--orm=datamapper', '--script=none') }
assert_match(/applying.*?datamapper.*?orm/, out)
assert_match_in_file(/gem 'dm-core'/, "#{@apptmp}/project.com/Gemfile")
assert_match_in_file(/gem 'dm-sqlite-adapter'/, "#{@apptmp}/project.com/Gemfile")
assert_match_in_file(/DataMapper.setup/, "#{@apptmp}/project.com/config/database.rb")
assert_match_in_file(/project_com/, "#{@apptmp}/project.com/config/database.rb")
end
it 'should properly generate for mysql' do
out, err = capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--orm=datamapper', '--adapter=mysql') }
assert_match_in_file(/gem 'dm-mysql-adapter'/, "#{@apptmp}/sample_project/Gemfile")
assert_match_in_file(%r{"mysql://}, "#{@apptmp}/sample_project/config/database.rb")
assert_match_in_file(/sample_project_development/, "#{@apptmp}/sample_project/config/database.rb")
end
# DataMapper has do_mysql that is the version of MySQL driver.
it 'should properly generate for mysql2' do
out, err = capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--orm=datamapper', '--adapter=mysql2') }
assert_match_in_file(/gem 'dm-mysql-adapter'/, "#{@apptmp}/sample_project/Gemfile")
assert_match_in_file(%r{"mysql://}, "#{@apptmp}/sample_project/config/database.rb")
assert_match_in_file(/sample_project_development/, "#{@apptmp}/sample_project/config/database.rb")
end
it 'should properly generate for sqlite' do
out, err = capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--orm=datamapper', '--adapter=sqlite') }
assert_match_in_file(/gem 'dm-sqlite-adapter'/, "#{@apptmp}/sample_project/Gemfile")
assert_match_in_file(/sample_project_development/, "#{@apptmp}/sample_project/config/database.rb")
end
it 'should properly generate for postgres' do
out, err = capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--orm=datamapper', '--adapter=postgres') }
assert_match_in_file(/gem 'dm-postgres-adapter'/, "#{@apptmp}/sample_project/Gemfile")
assert_match_in_file(%r{"postgres://}, "#{@apptmp}/sample_project/config/database.rb")
assert_match_in_file(/sample_project_development/, "#{@apptmp}/sample_project/config/database.rb")
end
end
it 'should properly generate for mongomapper' do
out, err = capture_io { generate(:project, 'project.com', "--root=#{@apptmp}", '--orm=mongomapper', '--script=none') }
assert_match(/applying.*?mongomapper.*?orm/, out)
assert_match_in_file(/gem 'mongo_mapper'/, "#{@apptmp}/project.com/Gemfile")
assert_match_in_file(/gem 'bson_ext'/, "#{@apptmp}/project.com/Gemfile")
assert_match_in_file(/MongoMapper.database/, "#{@apptmp}/project.com/config/database.rb")
assert_match_in_file(/project_com/, "#{@apptmp}/project.com/config/database.rb")
end
it 'should properly generate for mongoid' do
out, err = capture_io { generate(:project, 'project.com', "--root=#{@apptmp}", '--orm=mongoid', '--script=none') }
assert_match(/applying.*?mongoid.*?orm/, out)
assert_match_in_file(/gem 'mongoid'/, "#{@apptmp}/project.com/Gemfile")
assert_match_in_file(/Mongoid::Config.sessions =/, "#{@apptmp}/project.com/config/database.rb")
end
it 'should properly generate for couchrest' do
out, err = capture_io { generate(:project, 'project.com', "--root=#{@apptmp}", '--orm=couchrest', '--script=none') }
assert_match(/applying.*?couchrest.*?orm/, out)
assert_match_in_file(/gem 'couchrest_model'/, "#{@apptmp}/project.com/Gemfile")
assert_match_in_file(/CouchRest.database!/, "#{@apptmp}/project.com/config/database.rb")
assert_match_in_file(/project_com/, "#{@apptmp}/project.com/config/database.rb")
end
it 'should properly generate for ohm' do
out, err = capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--orm=ohm', '--script=none') }
assert_match(/applying.*?ohm.*?orm/, out)
assert_match_in_file(/gem 'ohm'/, "#{@apptmp}/sample_project/Gemfile")
assert_match_in_file(/Ohm.connect/, "#{@apptmp}/sample_project/config/database.rb")
end
it 'should properly generate for mongomatic' do
out, err = capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--orm=mongomatic', '--script=none') }
assert_match(/applying.*?mongomatic.*?orm/, out)
assert_match_in_file(/gem 'bson_ext'/, "#{@apptmp}/sample_project/Gemfile")
assert_match_in_file(/gem 'mongomatic'/, "#{@apptmp}/sample_project/Gemfile")
assert_match_in_file(/Mongomatic.db = Mongo::Connection.new.db/, "#{@apptmp}/sample_project/config/database.rb")
end
it 'should properly generate for ripple' do
out, err = capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--orm=ripple', '--script=none') }
assert_match(/applying.*?ripple.*?orm/, out)
assert_match_in_file(/gem 'ripple'/, "#{@apptmp}/sample_project/Gemfile")
assert_match_in_file(/Ripple.load_configuration/, "#{@apptmp}/sample_project/config/database.rb")
assert_match_in_file(/http_port: 8098/, "#{@apptmp}/sample_project/config/riak.yml")
end
it 'should properly generate for dynamoid' do
out, err = capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--orm=dynamoid', '--script=none') }
assert_match(/applying.*?dynamoid.*?orm/, out)
assert_match_in_file(/gem 'aws-sdk'/, "#{@apptmp}/sample_project/Gemfile")
assert_match_in_file(/gem 'dynamoid', '~>0.7.1'/, "#{@apptmp}/sample_project/Gemfile")
assert_match_in_file(/AWS.config/, "#{@apptmp}/sample_project/config/database.rb")
assert_match_in_file(/Dynamoid.configure/, "#{@apptmp}/sample_project/config/database.rb")
end
end
describe "the generator for renderer component" do
it 'should properly generate for erb' do
out, err = capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--renderer=erb', '--script=none') }
assert_match(/applying.*?erb.*?renderer/, out)
assert_match_in_file(/gem 'erubi'/, "#{@apptmp}/sample_project/Gemfile")
end
it 'should properly generate for haml' do
out, err = capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--renderer=haml','--script=none') }
assert_match(/applying.*?haml.*?renderer/, out)
assert_match_in_file(/gem 'haml'/, "#{@apptmp}/sample_project/Gemfile")
end
it 'should properly generate for liquid' do
out, err = capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--renderer=liquid','--script=none') }
assert_match(/applying.*?liquid.*?renderer/, out)
assert_match_in_file(/gem 'liquid'/, "#{@apptmp}/sample_project/Gemfile")
end
it 'should properly generate for slim' do
out, err = capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--renderer=slim','--script=none') }
assert_match(/applying.*?slim.*?renderer/, out)
assert_match_in_file(/gem 'slim'/, "#{@apptmp}/sample_project/Gemfile")
end
end
describe "the generator for script component" do
it 'should properly generate for jquery' do
out, err = capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=jquery') }
assert_match(/applying.*?jquery.*?script/, out)
assert_file_exists("#{@apptmp}/sample_project/public/javascripts/jquery.js")
assert_file_exists("#{@apptmp}/sample_project/public/javascripts/jquery-ujs.js")
assert_file_exists("#{@apptmp}/sample_project/public/javascripts/application.js")
end
it 'should properly generate for mootools' do
out, err = capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=mootools') }
assert_match(/applying.*?mootools.*?script/, out)
assert_file_exists("#{@apptmp}/sample_project/public/javascripts/mootools.js")
assert_file_exists("#{@apptmp}/sample_project/public/javascripts/mootools-ujs.js")
assert_file_exists("#{@apptmp}/sample_project/public/javascripts/application.js")
end
it 'should properly generate for prototype' do
out, err = capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=prototype') }
assert_match(/applying.*?prototype.*?script/, out)
assert_file_exists("#{@apptmp}/sample_project/public/javascripts/protopak.js")
assert_file_exists("#{@apptmp}/sample_project/public/javascripts/lowpro.js")
assert_file_exists("#{@apptmp}/sample_project/public/javascripts/prototype-ujs.js")
assert_file_exists("#{@apptmp}/sample_project/public/javascripts/application.js")
end
it 'should properly generate for ext-core' do
out, err = capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=extcore') }
assert_match(/applying.*?extcore.*?script/, out)
assert_file_exists("#{@apptmp}/sample_project/public/javascripts/ext.js")
assert_file_exists("#{@apptmp}/sample_project/public/javascripts/ext-ujs.js")
assert_file_exists("#{@apptmp}/sample_project/public/javascripts/application.js")
end
it 'should properly generate for dojo' do
out, err = capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=dojo') }
assert_match(/applying.*?dojo.*?script/, out)
assert_file_exists("#{@apptmp}/sample_project/public/javascripts/dojo.js")
assert_file_exists("#{@apptmp}/sample_project/public/javascripts/dojo-ujs.js")
assert_file_exists("#{@apptmp}/sample_project/public/javascripts/application.js")
end
end
describe "the generator for test component" do
it 'should properly generate for bacon' do
out, err = capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--test=bacon', '--script=none') }
assert_match(/applying.*?bacon.*?test/, out)
assert_match_in_file(/gem 'rack-test'/, "#{@apptmp}/sample_project/Gemfile")
assert_match_in_file(/:require => 'rack\/test'/, "#{@apptmp}/sample_project/Gemfile")
assert_match_in_file(/:group => 'test'/, "#{@apptmp}/sample_project/Gemfile")
assert_match_in_file(/gem 'bacon'/, "#{@apptmp}/sample_project/Gemfile")
assert_match_in_file(/Bacon::Context/, "#{@apptmp}/sample_project/test/test_config.rb")
assert_match_in_file(/RACK_ENV = 'test' unless defined\?\(RACK_ENV\)/, "#{@apptmp}/sample_project/test/test_config.rb")
assert_file_exists("#{@apptmp}/sample_project/test/test.rake")
assert_match_in_file(/Rake::TestTask.new\("test:\#/,"#{@apptmp}/sample_project/test/test.rake")
assert_match_in_file(/task 'test' => test_tasks/,"#{@apptmp}/sample_project/test/test.rake")
end
it 'should properly generate for rspec' do
out, err = capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--test=rspec', '--script=none') }
assert_match(/applying.*?rspec.*?test/, out)
assert_match_in_file(/gem 'rack-test'/, "#{@apptmp}/sample_project/Gemfile")
assert_match_in_file(/:require => 'rack\/test'/, "#{@apptmp}/sample_project/Gemfile")
assert_match_in_file(/:group => 'test'/, "#{@apptmp}/sample_project/Gemfile")
assert_match_in_file(/gem 'rspec'/, "#{@apptmp}/sample_project/Gemfile")
assert_match_in_file(/RACK_ENV = 'test' unless defined\?\(RACK_ENV\)/, "#{@apptmp}/sample_project/spec/spec_helper.rb")
assert_match_in_file(/RSpec.configure/, "#{@apptmp}/sample_project/spec/spec_helper.rb")
assert_file_exists("#{@apptmp}/sample_project/spec/spec.rake")
assert_match_in_file(/RSpec::Core::RakeTask\.new\("spec:\#/,"#{@apptmp}/sample_project/spec/spec.rake")
assert_match_in_file(/task 'spec' => spec_tasks/,"#{@apptmp}/sample_project/spec/spec.rake")
end
it 'should properly generate for shoulda' do
out, err = capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--test=shoulda', '--script=none') }
assert_match(/applying.*?shoulda.*?test/, out)
assert_match_in_file(/gem 'rack-test'/, "#{@apptmp}/sample_project/Gemfile")
assert_match_in_file(/:require => 'rack\/test'/, "#{@apptmp}/sample_project/Gemfile")
assert_match_in_file(/:group => 'test'/, "#{@apptmp}/sample_project/Gemfile")
assert_match_in_file(/gem 'shoulda'/, "#{@apptmp}/sample_project/Gemfile")
assert_match_in_file(/RACK_ENV = 'test' unless defined\?\(RACK_ENV\)/, "#{@apptmp}/sample_project/test/test_config.rb")
assert_match_in_file(/Test::Unit::TestCase/, "#{@apptmp}/sample_project/test/test_config.rb")
assert_file_exists("#{@apptmp}/sample_project/test/test.rake")
assert_match_in_file(/Rake::TestTask\.new\("test:\#/,"#{@apptmp}/sample_project/test/test.rake")
assert_match_in_file(/task 'test' => test_tasks/,"#{@apptmp}/sample_project/test/test.rake")
end
it 'should properly generate for minitest' do
out, err = capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--test=minitest', '--script=none') }
assert_match(/applying.*?minitest.*?test/, out)
assert_match_in_file(/gem 'rack-test'/, "#{@apptmp}/sample_project/Gemfile")
assert_match_in_file(/:require => 'rack\/test'/, "#{@apptmp}/sample_project/Gemfile")
assert_match_in_file(/:group => 'test'/, "#{@apptmp}/sample_project/Gemfile")
assert_match_in_file(/gem 'minitest'/, "#{@apptmp}/sample_project/Gemfile")
assert_match_in_file(/include Rack::Test::Methods/, "#{@apptmp}/sample_project/test/test_config.rb")
assert_match_in_file(/RACK_ENV = 'test' unless defined\?\(RACK_ENV\)/, "#{@apptmp}/sample_project/test/test_config.rb")
assert_match_in_file(/MiniTest::Spec/, "#{@apptmp}/sample_project/test/test_config.rb")
assert_match_in_file(/SampleProject::App\.tap/, "#{@apptmp}/sample_project/test/test_config.rb")
assert_file_exists("#{@apptmp}/sample_project/test/test.rake")
assert_match_in_file(/Rake::TestTask\.new\("test:\#/,"#{@apptmp}/sample_project/test/test.rake")
assert_match_in_file(/task 'test' => test_tasks/,"#{@apptmp}/sample_project/test/test.rake")
end # minitest
it 'should properly generate for cucumber' do
out, err = capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--test=cucumber', '--script=none') }
assert_match(/applying.*?cucumber.*?test/, out)
assert_match_in_file(/gem 'rack-test'/, "#{@apptmp}/sample_project/Gemfile")
assert_match_in_file(/:require => 'rack\/test'/, "#{@apptmp}/sample_project/Gemfile")
assert_match_in_file(/:group => 'test'/, "#{@apptmp}/sample_project/Gemfile")
assert_match_in_file(/gem 'rspec'/, "#{@apptmp}/sample_project/Gemfile")
assert_match_in_file(/gem 'cucumber'/, "#{@apptmp}/sample_project/Gemfile")
assert_match_in_file(/RACK_ENV = 'test' unless defined\?\(RACK_ENV\)/, "#{@apptmp}/sample_project/spec/spec_helper.rb")
assert_match_in_file(/RACK_ENV = 'test' unless defined\?\(RACK_ENV\)/, "#{@apptmp}/sample_project/features/support/env.rb")
assert_match_in_file(/gem 'capybara'/, "#{@apptmp}/sample_project/Gemfile")
assert_match_in_file(/RSpec.configure/, "#{@apptmp}/sample_project/spec/spec_helper.rb")
assert_match_in_file(/Capybara.app = /, "#{@apptmp}/sample_project/features/support/env.rb")
assert_match_in_file(/World\(Cucumber::Web::URLs\)/, "#{@apptmp}/sample_project/features/support/url.rb")
assert_file_exists("#{@apptmp}/sample_project/spec/spec.rake")
assert_match_in_file(/RSpec::Core::RakeTask\.new\("spec:\#/,"#{@apptmp}/sample_project/spec/spec.rake")
assert_match_in_file(/task 'spec' => spec_tasks/,"#{@apptmp}/sample_project/spec/spec.rake")
assert_file_exists("#{@apptmp}/sample_project/features/support/env.rb")
assert_file_exists("#{@apptmp}/sample_project/features/add.feature")
assert_file_exists("#{@apptmp}/sample_project/features/step_definitions/add_steps.rb")
end
end
describe "the generator for stylesheet component" do
it 'should properly generate for sass' do
capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--renderer=haml','--script=none','--stylesheet=sass') }
assert_match_in_file(/gem 'sass'/, "#{@apptmp}/sample_project/Gemfile")
assert_match_in_file(/module SassInitializer.*Sass::Plugin::Rack/m, "#{@apptmp}/sample_project/config/initializers/sass.rb")
assert_match_in_file(/register SassInitializer/m, "#{@apptmp}/sample_project/app/app.rb")
assert_dir_exists("#{@apptmp}/sample_project/app/stylesheets")
end
it 'should properly generate for less' do
capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--renderer=haml','--script=none','--stylesheet=less') }
assert_match_in_file(/gem 'rack-less'/, "#{@apptmp}/sample_project/Gemfile")
assert_match_in_file(/module LessInitializer.*Rack::Less/m, "#{@apptmp}/sample_project/config/initializers/less.rb")
assert_match_in_file(/register LessInitializer/m, "#{@apptmp}/sample_project/app/app.rb")
assert_dir_exists("#{@apptmp}/sample_project/app/stylesheets")
end
it 'should properly generate for compass' do
capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--renderer=haml','--script=none','--stylesheet=compass') }
assert_match_in_file(/gem 'compass-blueprint'/, "#{@apptmp}/sample_project/Gemfile")
assert_match_in_file(/Compass.configure_sass_plugin\!/, "#{@apptmp}/sample_project/config/initializers/compass.rb")
assert_match_in_file(/module CompassInitializer.*Sass::Plugin::Rack/m, "#{@apptmp}/sample_project/config/initializers/compass.rb")
assert_match_in_file(/register CompassInitializer/m, "#{@apptmp}/sample_project/app/app.rb")
assert_file_exists("#{@apptmp}/sample_project/app/stylesheets/application.scss")
assert_file_exists("#{@apptmp}/sample_project/app/stylesheets/partials/_base.scss")
end
it 'should properly generate for scss' do
capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--renderer=haml','--script=none','--stylesheet=scss') }
assert_match_in_file(/gem 'haml'/, "#{@apptmp}/sample_project/Gemfile")
assert_match_in_file(/module ScssInitializer.*Sass::Plugin::Rack/m, "#{@apptmp}/sample_project/config/initializers/scss.rb")
assert_match_in_file(/Sass::Plugin.options\[:syntax\] = :scss/m, "#{@apptmp}/sample_project/config/initializers/scss.rb")
assert_match_in_file(/register ScssInitializer/m, "#{@apptmp}/sample_project/app/app.rb")
assert_dir_exists("#{@apptmp}/sample_project/app/stylesheets")
end
end
describe "tiny app skeleton generator for test component" do
it "should properly generate for rspec" do
capture_io { generate(:project,'sample_project', '--tiny', "--root=#{@apptmp}", "--test=rspec") }
assert_dir_exists("#{@apptmp}/sample_project/spec/")
assert_file_exists("#{@apptmp}/sample_project/spec/app/controllers/controllers_spec.rb")
assert_file_exists("#{@apptmp}/sample_project/spec/app/helpers/helpers_spec.rb")
assert_match_in_file(/Dir\[File\.expand_path\(File\.dirname\(__FILE__\) \+ "\/\.\.\/app\/helpers\.rb"\)\]\.each\(&method\(:require\)\)/, "#{@apptmp}/sample_project/spec/spec_helper.rb")
assert_match_in_file(/RSpec\.describe "Controller" do/, "#{@apptmp}/sample_project/spec/app/controllers/controllers_spec.rb")
assert_match_in_file(/get "\/"/, "#{@apptmp}/sample_project/spec/app/controllers/controllers_spec.rb")
assert_match_in_file(/RSpec.describe "SampleProject::App::Helper" do/, "#{@apptmp}/sample_project/spec/app/helpers/helpers_spec.rb")
end
it "should properly generate for cucumber" do
capture_io { generate(:project,'sample_project', '--tiny', "--root=#{@apptmp}", "--test=cucumber") }
assert_dir_exists("#{@apptmp}/sample_project/spec/")
assert_file_exists("#{@apptmp}/sample_project/spec/app/controllers/controllers_spec.rb")
assert_file_exists("#{@apptmp}/sample_project/spec/app/helpers/helpers_spec.rb")
assert_match_in_file(/Dir\[File\.expand_path\(File\.dirname\(__FILE__\) \+ "\/\.\.\/app\/helpers\.rb"\)\]\.each\(&method\(:require\)\)/, "#{@apptmp}/sample_project/spec/spec_helper.rb")
assert_match_in_file(/describe "Controller" do/, "#{@apptmp}/sample_project/spec/app/controllers/controllers_spec.rb")
assert_match_in_file(/describe "SampleProject::App::Helper" do/, "#{@apptmp}/sample_project/spec/app/helpers/helpers_spec.rb")
end
it "should properly generate for bacon" do
capture_io { generate(:project,'sample_project', '--tiny', "--root=#{@apptmp}", "--test=bacon") }
assert_dir_exists("#{@apptmp}/sample_project/test/")
assert_file_exists("#{@apptmp}/sample_project/test/app/controllers/controllers_test.rb")
assert_file_exists("#{@apptmp}/sample_project/test/app/helpers/helpers_test.rb")
assert_match_in_file(/Dir\[File\.expand_path\(File\.dirname\(__FILE__\) \+ "\/\.\.\/app\/helpers\.rb"\)\]\.each\(&method\(:require\)\)/, "#{@apptmp}/sample_project/test/test_config.rb")
assert_match_in_file(/describe "Controller" do/, "#{@apptmp}/sample_project/test/app/controllers/controllers_test.rb")
assert_match_in_file(/describe "SampleProject::App::Helper"/, "#{@apptmp}/sample_project/test/app/helpers/helpers_test.rb")
end
it "should properly generate for minitest" do
capture_io { generate(:project,'sample_project', '--tiny', "--root=#{@apptmp}", "--test=minitest") }
assert_dir_exists("#{@apptmp}/sample_project/test/")
assert_file_exists("#{@apptmp}/sample_project/test/app/controllers/controllers_test.rb")
assert_file_exists("#{@apptmp}/sample_project/test/app/helpers/helpers_test.rb")
assert_match_in_file(/Dir\[File\.expand_path\(File\.dirname\(__FILE__\) \+ "\/\.\.\/app\/helpers\.rb"\)\]\.each\(&method\(:require\)\)/, "#{@apptmp}/sample_project/test/test_config.rb")
assert_match_in_file(/describe "Controller" do/, "#{@apptmp}/sample_project/test/app/controllers/controllers_test.rb")
assert_match_in_file(/describe "SampleProject::App::Helper"/, "#{@apptmp}/sample_project/test/app/helpers/helpers_test.rb")
end
it "should properly generate for shoulda" do
capture_io { generate(:project,'sample_project', '--tiny', "--root=#{@apptmp}", "--test=shoulda") }
assert_dir_exists("#{@apptmp}/sample_project/test/")
assert_file_exists("#{@apptmp}/sample_project/test/app/controllers/controllers_test.rb")
assert_file_exists("#{@apptmp}/sample_project/test/app/helpers/helpers_test.rb")
assert_match_in_file(/Dir\[File\.expand_path\(File\.dirname\(__FILE__\) \+ "\/\.\.\/app\/helpers\.rb"\)\]\.each\(&method\(:require\)\)/, "#{@apptmp}/sample_project/test/test_config.rb")
assert_match_in_file(/class ControllerTest < Test::Unit::TestCase/, "#{@apptmp}/sample_project/test/app/controllers/controllers_test.rb")
assert_match_in_file(/class SampleProject::App::HelperTest < Test::Unit::TestCase/, "#{@apptmp}/sample_project/test/app/helpers/helpers_test.rb")
end
it "should properly generate for testunit" do
out, err = capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--test=testunit', '--script=none', '--tiny') }
assert_match(/applying.*?testunit.*?test/, out)
assert_match_in_file(/gem 'rack-test'/, "#{@apptmp}/sample_project/Gemfile")
assert_match_in_file(/:require => 'rack\/test'/, "#{@apptmp}/sample_project/Gemfile")
assert_match_in_file(/:group => 'test'/, "#{@apptmp}/sample_project/Gemfile")
assert_match_in_file(/gem 'test-unit'/, "#{@apptmp}/sample_project/Gemfile")
assert_match_in_file(/RACK_ENV = 'test' unless defined\?\(RACK_ENV\)/, "#{@apptmp}/sample_project/test/test_config.rb")
assert_file_exists("#{@apptmp}/sample_project/test/test.rake")
assert_match_in_file(/task 'test' => test_tasks/,"#{@apptmp}/sample_project/test/test.rake")
assert_match_in_file(/Dir\[File\.expand_path\(File\.dirname\(__FILE__\) \+ "\/\.\.\/app\/helpers\.rb"\)\]\.each\(&method\(:require\)\)/, "#{@apptmp}/sample_project/test/test_config.rb")
assert_match_in_file(/class ControllerTest < Test::Unit::TestCase/, "#{@apptmp}/sample_project/test/app/controllers/controllers_test.rb")
assert_match_in_file(/class SampleProject::App::HelperTest < Test::Unit::TestCase/, "#{@apptmp}/sample_project/test/app/helpers/helpers_test.rb")
end
end
end