padrino-gen 0.10.2 → 0.10.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (36) hide show
  1. data/.document +3 -3
  2. data/.yardopts +1 -0
  3. data/{LICENSE → LICENSE.txt} +0 -0
  4. data/README.rdoc +1 -1
  5. data/lib/padrino-gen/command.rb +7 -0
  6. data/lib/padrino-gen/generators/actions.rb +264 -24
  7. data/lib/padrino-gen/generators/app/app.rb.tt +11 -11
  8. data/lib/padrino-gen/generators/app.rb +10 -9
  9. data/lib/padrino-gen/generators/cli.rb +3 -0
  10. data/lib/padrino-gen/generators/components/actions.rb +86 -11
  11. data/lib/padrino-gen/generators/components/mocks/rr.rb +3 -1
  12. data/lib/padrino-gen/generators/components/orms/mongoid.rb +1 -1
  13. data/lib/padrino-gen/generators/components/orms/mongomapper.rb +1 -1
  14. data/lib/padrino-gen/generators/components/orms/mongomatic.rb +1 -1
  15. data/lib/padrino-gen/generators/components/stylesheets/less.rb +1 -1
  16. data/lib/padrino-gen/generators/components/tests/minitest.rb +78 -0
  17. data/lib/padrino-gen/generators/controller.rb +3 -0
  18. data/lib/padrino-gen/generators/mailer.rb +3 -0
  19. data/lib/padrino-gen/generators/model.rb +3 -0
  20. data/lib/padrino-gen/generators/plugin.rb +2 -0
  21. data/lib/padrino-gen/generators/project.rb +11 -3
  22. data/lib/padrino-gen/generators/runner.rb +85 -34
  23. data/lib/padrino-gen/generators/templates/Gemfile.tt +12 -21
  24. data/lib/padrino-gen/padrino-tasks/activerecord.rb +0 -194
  25. data/lib/padrino-gen.rb +21 -0
  26. data/test/helper.rb +2 -20
  27. data/test/test_app_generator.rb +17 -17
  28. data/test/test_cli.rb +6 -5
  29. data/test/test_controller_generator.rb +52 -44
  30. data/test/test_generator.rb +1 -1
  31. data/test/test_mailer_generator.rb +18 -18
  32. data/test/test_migration_generator.rb +44 -44
  33. data/test/test_model_generator.rb +140 -123
  34. data/test/test_plugin_generator.rb +21 -33
  35. data/test/test_project_generator.rb +125 -103
  36. metadata +10 -8
data/test/helper.rb CHANGED
@@ -1,10 +1,8 @@
1
1
  require File.expand_path('../../../load_paths', __FILE__)
2
- require 'test/unit'
2
+ require File.join(File.dirname(__FILE__), '..', '..', 'padrino-core', 'test', 'mini_shoulda')
3
3
  require 'rack/test'
4
4
  require 'rack'
5
5
  require 'uuid'
6
- require 'shoulda'
7
- require 'mocha'
8
6
  require 'webrat'
9
7
  require 'grit'
10
8
  require 'thor/group'
@@ -14,7 +12,7 @@ require 'padrino-core/support_lite' unless defined?(SupportLite)
14
12
 
15
13
  Padrino::Generators.load_components!
16
14
 
17
- class Test::Unit::TestCase
15
+ class MiniTest::Spec
18
16
  include Rack::Test::Methods
19
17
  include Webrat::Methods
20
18
  include Webrat::Matchers
@@ -108,10 +106,6 @@ class Test::Unit::TestCase
108
106
  Thor::Actions::CreateFile.expects(:new).with(anything, path, kind_of(Proc), anything).returns(instance)
109
107
  end
110
108
 
111
- def expects
112
-
113
- end
114
-
115
109
  # expects_rake "custom"
116
110
  def expects_rake(command,options={})
117
111
  #options.reverse_merge!(:root => '/tmp')
@@ -133,18 +127,6 @@ class Test::Unit::TestCase
133
127
 
134
128
  end
135
129
 
136
- class Object
137
- # Silences the output by redirecting to stringIO
138
- # silence_logger { ...commands... } => "...output..."
139
- def silence_logger(&block)
140
- orig_stdout = $stdout
141
- $stdout = log_buffer = StringIO.new
142
- block.call
143
- $stdout = orig_stdout
144
- log_buffer.rewind && log_buffer.read
145
- end
146
- end
147
-
148
130
  module Webrat
149
131
  module Logging
150
132
  def logger # # @private
@@ -1,6 +1,6 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/helper')
2
2
 
3
- class TestAppGenerator < Test::Unit::TestCase
3
+ describe "AppGenerator" do
4
4
  def setup
5
5
  @apptmp = "#{Dir.tmpdir}/padrino-tests/#{UUID.new.generate}"
6
6
  `mkdir -p #{@apptmp}`
@@ -12,14 +12,14 @@ class TestAppGenerator < Test::Unit::TestCase
12
12
 
13
13
  context 'the app generator' do
14
14
  should "fail outside app root" do
15
- output = silence_logger { generate(:app, 'demo_root', "-r=#{@apptmp}") }
16
- assert_match(/not at the root/, output)
15
+ out, err = capture_io { generate(:app, 'demo_root', "-r=#{@apptmp}") }
16
+ assert_match(/not at the root/, out)
17
17
  assert_no_file_exists("#{@apptmp}/demo_root")
18
18
  end
19
19
 
20
20
  should "create correctly a new padrino application" do
21
- assert_nothing_raised { silence_logger { generate(:project, 'sample_project', "--root=#{@apptmp}") } }
22
- assert_nothing_raised { silence_logger { generate(:app, 'demo', "--root=#{@apptmp}/sample_project") } }
21
+ capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}") }
22
+ capture_io { generate(:app, 'demo', "--root=#{@apptmp}/sample_project") }
23
23
  assert_file_exists("#{@apptmp}/sample_project")
24
24
  assert_file_exists("#{@apptmp}/sample_project/demo")
25
25
  assert_file_exists("#{@apptmp}/sample_project/demo/app.rb")
@@ -35,8 +35,8 @@ class TestAppGenerator < Test::Unit::TestCase
35
35
  end
36
36
 
37
37
  should "generate tiny app skeleton" do
38
- assert_nothing_raised { silence_logger { generate(:project, 'sample_project', "--root=#{@apptmp}") } }
39
- assert_nothing_raised { silence_logger { generate(:app, 'demo','--tiny',"--root=#{@apptmp}/sample_project") } }
38
+ capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}") }
39
+ capture_io { generate(:app, 'demo','--tiny',"--root=#{@apptmp}/sample_project") }
40
40
  assert_file_exists("#{@apptmp}/sample_project")
41
41
  assert_file_exists("#{@apptmp}/sample_project/demo")
42
42
  assert_file_exists("#{@apptmp}/sample_project/demo/helpers.rb")
@@ -49,27 +49,27 @@ class TestAppGenerator < Test::Unit::TestCase
49
49
  end
50
50
 
51
51
  should "correctly create a new controller inside a padrino application" do
52
- silence_logger { generate(:project, 'sample_project', "--root=#{@apptmp}") }
53
- silence_logger { generate(:app, 'demo', "--root=#{@apptmp}/sample_project") }
54
- silence_logger { generate(:controller, 'demo_items', "-r=#{@apptmp}/sample_project", '-a=demo') }
52
+ capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}") }
53
+ capture_io { generate(:app, 'demo', "--root=#{@apptmp}/sample_project") }
54
+ capture_io { generate(:controller, 'demo_items', "-r=#{@apptmp}/sample_project", '-a=demo') }
55
55
  assert_match_in_file(/Demo.controllers :demo_items do/m, "#{@apptmp}/sample_project/demo/controllers/demo_items.rb")
56
56
  assert_match_in_file(/Demo.helpers do/m, "#{@apptmp}/sample_project/demo/helpers/demo_items_helper.rb")
57
57
  assert_file_exists("#{@apptmp}/sample_project/demo/views/demo_items")
58
58
  end
59
59
 
60
60
  should "correctly create a new mailer inside a padrino application" do
61
- silence_logger { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=bacon') }
62
- silence_logger { generate(:app, 'demo_app', "--root=#{@apptmp}/sample_project") }
63
- silence_logger { generate(:mailer, 'demo', "-r=#{@apptmp}/sample_project", '-a=demoapp') }
61
+ capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=bacon') }
62
+ capture_io { generate(:app, 'demo_app', "--root=#{@apptmp}/sample_project") }
63
+ capture_io { generate(:mailer, 'demo', "-r=#{@apptmp}/sample_project", '-a=demoapp') }
64
64
  end
65
65
 
66
66
  # only destroys what it generated.
67
67
  # hence, the folder will still exists if other changes were made to it.
68
68
  should "destroys itself" do
69
- silence_logger { generate(:project, 'sample_project', "--root=#{@apptmp}") }
70
- silence_logger { generate(:app, 'demo', "--root=#{@apptmp}/sample_project") }
71
- output = silence_logger { generate(:app, 'demo', "--root=#{@apptmp}/sample_project", '-d') }
72
- assert_no_match(/has been mounted/, output)
69
+ capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}") }
70
+ capture_io { generate(:app, 'demo', "--root=#{@apptmp}/sample_project") }
71
+ out, err = capture_io { generate(:app, 'demo', "--root=#{@apptmp}/sample_project", '-d') }
72
+ assert_no_match(/has been mounted/, out)
73
73
  assert_no_dir_exists("#{@apptmp}/sample_project/public/demo")
74
74
  assert_no_file_exists("#{@apptmp}/sample_project/demo/app.rb")
75
75
  assert_no_dir_exists("#{@apptmp}/sample_project/demo/controllers")
data/test/test_cli.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/helper')
2
2
  require 'padrino-gen/generators/cli'
3
3
 
4
- class TestCli < Test::Unit::TestCase
4
+ describe "Cli" do
5
5
  def setup
6
6
  @apptmp = "#{Dir.tmpdir}/padrino-tests/#{UUID.new.generate}"
7
7
  `mkdir -p #{@apptmp}`
@@ -14,13 +14,14 @@ class TestCli < Test::Unit::TestCase
14
14
  context 'the cli' do
15
15
 
16
16
  should "fail without arguments" do
17
- output = silence_logger { generate(:cli) }
18
- assert_match "Please specify generator to use", output
17
+ out, err = capture_io { generate(:cli) }
18
+ assert_match(/Please specify generator to use/, out)
19
19
  end
20
20
 
21
21
  should "work correctly if we have a project" do
22
- silence_logger { generate(:project, 'sample_project', "--root=#{@apptmp}") }
23
- assert_nothing_raised { silence_logger { generate(:cli, "--root=#{@apptmp}/sample_project") } }
22
+ capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}") }
23
+ capture_io { generate(:cli, "--root=#{@apptmp}/sample_project") }
24
+ skip "Make a great asserition"
24
25
  end
25
26
  end
26
27
  end
@@ -1,6 +1,6 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/helper')
2
2
 
3
- class TestControllerGenerator < Test::Unit::TestCase
3
+ describe "ControllerGenerator" do
4
4
  def setup
5
5
  @apptmp = "#{Dir.tmpdir}/padrino-tests/#{UUID.new.generate}"
6
6
  `mkdir -p #{@apptmp}`
@@ -14,14 +14,14 @@ class TestControllerGenerator < Test::Unit::TestCase
14
14
 
15
15
  context 'the controller generator' do
16
16
  should "fail outside app root" do
17
- output = silence_logger { generate(:controller, 'demo', "-r=#{@apptmp}") }
18
- assert_match(/not at the root/, output)
17
+ out, err = capture_io { generate(:controller, 'demo', "-r=#{@apptmp}") }
18
+ assert_match(/not at the root/, out)
19
19
  assert_no_file_exists("#{@apptmp}/app/controllers/demo.rb")
20
20
  end
21
21
 
22
22
  should "generate controller within existing project" do
23
- silence_logger { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=bacon') }
24
- silence_logger { generate(:controller, 'DemoItems', "-r=#{@apptmp}/sample_project") }
23
+ capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=bacon') }
24
+ capture_io { generate(:controller, 'DemoItems', "-r=#{@apptmp}/sample_project") }
25
25
  assert_match_in_file(/SampleProject.controllers :demo_items do/m, @controller_path)
26
26
  assert_match_in_file(/SampleProject.helpers do/m, "#{@apptmp}/sample_project/app/helpers/demo_items_helper.rb")
27
27
  assert_file_exists("#{@apptmp}/sample_project/app/views/demo_items")
@@ -29,17 +29,17 @@ class TestControllerGenerator < Test::Unit::TestCase
29
29
  end
30
30
 
31
31
  should "generate controller within existing project with weird name" do
32
- silence_logger { generate(:project, 'warepedia', "--root=#{@apptmp}", '--script=none', '-t=bacon') }
33
- silence_logger { generate(:controller, 'DemoItems', "-r=#{@apptmp}/warepedia") }
32
+ capture_io { generate(:project, 'warepedia', "--root=#{@apptmp}", '--script=none', '-t=bacon') }
33
+ capture_io { generate(:controller, 'DemoItems', "-r=#{@apptmp}/warepedia") }
34
34
  assert_match_in_file(/Warepedia.controllers :demo_items do/m, "#{@apptmp}/warepedia/app/controllers/demo_items.rb")
35
35
  assert_match_in_file(/Warepedia.helpers do/m, "#{@apptmp}/warepedia/app/helpers/demo_items_helper.rb")
36
36
  assert_file_exists("#{@apptmp}/warepedia/app/views/demo_items")
37
37
  end
38
38
 
39
39
  should "generate controller in specified app" do
40
- silence_logger { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=bacon') }
41
- silence_logger { generate(:app, 'subby', "-r=#{@apptmp}/sample_project") }
42
- silence_logger { generate(:controller, 'DemoItems','-a=/subby', "-r=#{@apptmp}/sample_project") }
40
+ capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=bacon') }
41
+ capture_io { generate(:app, 'subby', "-r=#{@apptmp}/sample_project") }
42
+ capture_io { generate(:controller, 'DemoItems','-a=/subby', "-r=#{@apptmp}/sample_project") }
43
43
  assert_match_in_file(/Subby.controllers :demo_items do/m, @controller_path.gsub('app','subby'))
44
44
  assert_match_in_file(/Subby.helpers do/m, "#{@apptmp}/sample_project/subby/helpers/demo_items_helper.rb")
45
45
  assert_file_exists("#{@apptmp}/sample_project/subby/views/demo_items")
@@ -47,8 +47,8 @@ class TestControllerGenerator < Test::Unit::TestCase
47
47
  end
48
48
 
49
49
  should 'not fail if we don\'t have test component' do
50
- silence_logger { generate(:project, 'sample_project', "--root=#{@apptmp}", '--test=none') }
51
- silence_logger { generate(:controller, 'DemoItems', "-r=#{@apptmp}/sample_project") }
50
+ capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--test=none') }
51
+ capture_io { generate(:controller, 'DemoItems', "-r=#{@apptmp}/sample_project") }
52
52
  assert_match_in_file(/SampleProject.controllers :demo_items do/m, @controller_path)
53
53
  assert_match_in_file(/SampleProject.helpers do/m, "#{@apptmp}/sample_project/app/helpers/demo_items_helper.rb")
54
54
  assert_file_exists("#{@apptmp}/sample_project/app/views/demo_items")
@@ -56,40 +56,48 @@ class TestControllerGenerator < Test::Unit::TestCase
56
56
  end
57
57
 
58
58
  should "generate controller test for bacon" do
59
- silence_logger { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=bacon') }
60
- silence_logger { generate(:app, 'subby', "-r=#{@apptmp}/sample_project") }
61
- silence_logger { generate(:controller, 'DemoItems','-a=/subby', "-r=#{@apptmp}/sample_project") }
59
+ capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=bacon') }
60
+ capture_io { generate(:app, 'subby', "-r=#{@apptmp}/sample_project") }
61
+ capture_io { generate(:controller, 'DemoItems','-a=/subby', "-r=#{@apptmp}/sample_project") }
62
62
  assert_match_in_file(/(\/\.\.){2}/m, @controller_test_path.gsub('app','subby'))
63
63
  assert_match_in_file(/describe "DemoItemsController" do/m, @controller_test_path.gsub('app','subby'))
64
64
  end
65
65
 
66
66
  should "generate controller test for riot" do
67
- silence_logger { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=riot') }
68
- silence_logger { generate(:app, 'subby', "-r=#{@apptmp}/sample_project") }
69
- silence_logger { generate(:controller, 'DemoItems','-a=/subby', "-r=#{@apptmp}/sample_project") }
67
+ capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=riot') }
68
+ capture_io { generate(:app, 'subby', "-r=#{@apptmp}/sample_project") }
69
+ capture_io { generate(:controller, 'DemoItems','-a=/subby', "-r=#{@apptmp}/sample_project") }
70
70
  assert_match_in_file(/(\/\.\.){2}/m, @controller_test_path.gsub('app','subby'))
71
71
  assert_match_in_file(/context "DemoItemsController" do/m, @controller_test_path.gsub('app','subby'))
72
72
  end
73
73
 
74
+ should "generate controller test for minitest" do
75
+ capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=minitest') }
76
+ capture_io { generate(:app, 'subby', "-r=#{@apptmp}/sample_project") }
77
+ capture_io { generate(:controller, 'DemoItems','-a=/subby', "-r=#{@apptmp}/sample_project") }
78
+ assert_match_in_file(/(\/\.\.){2}/m, @controller_test_path.gsub('app', 'subby'))
79
+ assert_match_in_file(/describe "DemoItemsController" do/m, @controller_test_path.gsub('app', 'subby'))
80
+ end
81
+
74
82
  should "generate controller test for testspec" do
75
- silence_logger { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=testspec') }
76
- silence_logger { generate(:app, 'subby', "-r=#{@apptmp}/sample_project") }
77
- silence_logger { generate(:controller, 'DemoItems','-a=/subby', "-r=#{@apptmp}/sample_project") }
83
+ capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=testspec') }
84
+ capture_io { generate(:app, 'subby', "-r=#{@apptmp}/sample_project") }
85
+ capture_io { generate(:controller, 'DemoItems','-a=/subby', "-r=#{@apptmp}/sample_project") }
78
86
  assert_match_in_file(/(\/\.\.){2}/m, @controller_test_path.gsub('app','subby'))
79
87
  assert_match_in_file(/context "DemoItemsController" do/m, @controller_test_path.gsub('app','subby'))
80
88
  end
81
89
 
82
90
  should "generate controller test for rspec" do
83
- silence_logger { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=rspec') }
84
- silence_logger { generate(:app, 'subby', "-r=#{@apptmp}/sample_project") }
85
- silence_logger { generate(:controller, 'DemoItems','-a=/subby', "-r=#{@apptmp}/sample_project") }
91
+ capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=rspec') }
92
+ capture_io { generate(:app, 'subby', "-r=#{@apptmp}/sample_project") }
93
+ capture_io { generate(:controller, 'DemoItems','-a=/subby', "-r=#{@apptmp}/sample_project") }
86
94
  assert_match_in_file(/describe "DemoItemsController" do/m, "#{@apptmp}/sample_project/spec/subby/controllers/demo_items_controller_spec.rb")
87
95
  end
88
96
 
89
97
  should "generate controller test for shoulda" do
90
- silence_logger { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=shoulda') }
91
- silence_logger { generate(:app, 'subby', "-r=#{@apptmp}/sample_project") }
92
- silence_logger { generate(:controller, 'DemoItems','-a=/subby', "-r=#{@apptmp}/sample_project") }
98
+ capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=shoulda') }
99
+ capture_io { generate(:app, 'subby', "-r=#{@apptmp}/sample_project") }
100
+ capture_io { generate(:controller, 'DemoItems','-a=/subby', "-r=#{@apptmp}/sample_project") }
93
101
  expected_pattern = /class DemoItemsControllerTest < Test::Unit::TestCase/m
94
102
  assert_match_in_file(expected_pattern, @controller_test_path.gsub('app','subby'))
95
103
  assert_match_in_file(/(\/\.\.){2}/m, @controller_test_path.gsub('app','subby'))
@@ -97,16 +105,16 @@ class TestControllerGenerator < Test::Unit::TestCase
97
105
  end
98
106
 
99
107
  should "generate controller test for cucumber" do
100
- silence_logger { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=cucumber') }
101
- silence_logger { generate(:app, 'subby', "-r=#{@apptmp}/sample_project") }
102
- silence_logger { generate(:controller, 'DemoItems','-a=/subby', "-r=#{@apptmp}/sample_project") }
108
+ capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=cucumber') }
109
+ capture_io { generate(:app, 'subby', "-r=#{@apptmp}/sample_project") }
110
+ capture_io { generate(:controller, 'DemoItems','-a=/subby', "-r=#{@apptmp}/sample_project") }
103
111
  assert_match_in_file(/describe "DemoItemsController" do/m, "#{@apptmp}/sample_project/spec/subby/controllers/demo_items_controller_spec.rb")
104
112
  assert_match_in_file(/Capybara.app = /, "#{@apptmp}/sample_project/features/support/env.rb")
105
113
  end
106
114
 
107
115
  should "correctly generate file names" do
108
- silence_logger { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=rspec') }
109
- silence_logger { generate(:controller, 'DemoItems', "-r=#{@apptmp}/sample_project") }
116
+ capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=rspec') }
117
+ capture_io { generate(:controller, 'DemoItems', "-r=#{@apptmp}/sample_project") }
110
118
  assert_file_exists("#{@apptmp}/sample_project/app/views/demo_items")
111
119
  assert_file_exists("#{@apptmp}/sample_project/app/controllers/demo_items.rb")
112
120
  assert_file_exists("#{@apptmp}/sample_project/app/helpers/demo_items_helper.rb")
@@ -115,8 +123,8 @@ class TestControllerGenerator < Test::Unit::TestCase
115
123
 
116
124
  # Controller action generation
117
125
  should "generate actions for get:test post:yada" do
118
- silence_logger { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=shoulda') }
119
- silence_logger { generate(:controller, 'demo_items', "get:test", "post:yada","-r=#{@apptmp}/sample_project") }
126
+ capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=shoulda') }
127
+ capture_io { generate(:controller, 'demo_items', "get:test", "post:yada","-r=#{@apptmp}/sample_project") }
120
128
  assert_match_in_file(/get :test do\n end\n/m, @controller_path)
121
129
  assert_match_in_file(/post :yada do\n end\n/m, @controller_path)
122
130
  end
@@ -124,28 +132,28 @@ class TestControllerGenerator < Test::Unit::TestCase
124
132
 
125
133
  context "the controller destroy option" do
126
134
  should "destroy controller files" do
127
- silence_logger { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=bacon') }
128
- silence_logger { generate(:controller, 'demo_items',"-r=#{@apptmp}/sample_project") }
129
- silence_logger { generate(:controller, 'demo_items',"-r=#{@apptmp}/sample_project",'-d') }
135
+ capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=bacon') }
136
+ capture_io { generate(:controller, 'demo_items',"-r=#{@apptmp}/sample_project") }
137
+ capture_io { generate(:controller, 'demo_items',"-r=#{@apptmp}/sample_project",'-d') }
130
138
  assert_no_file_exists(@controller_path)
131
139
  assert_no_file_exists(@controller_test_path)
132
140
  assert_no_file_exists("#{@apptmp}/sample_project/app/helpers/demo_items_helper.rb")
133
141
  end
134
142
 
135
143
  should "destroy controller files with rspec" do
136
- silence_logger { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=rspec') }
137
- silence_logger { generate(:controller, 'demo_items',"-r=#{@apptmp}/sample_project") }
138
- silence_logger { generate(:controller, 'demo_items',"-r=#{@apptmp}/sample_project",'-d') }
144
+ capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=rspec') }
145
+ capture_io { generate(:controller, 'demo_items',"-r=#{@apptmp}/sample_project") }
146
+ capture_io { generate(:controller, 'demo_items',"-r=#{@apptmp}/sample_project",'-d') }
139
147
  assert_no_file_exists(@controller_path)
140
148
  assert_no_file_exists("#{@apptmp}/sample_project/app/helpers/demo_items_helper.rb")
141
149
  assert_no_file_exists("#{@apptmp}/sample_project/spec/app/controllers/demo_items_controller_spec.rb")
142
150
  end
143
151
 
144
152
  should "destroy controller files in sub apps" do
145
- silence_logger { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=bacon') }
146
- silence_logger { generate(:app, 'subby', "-r=#{@apptmp}/sample_project") }
147
- silence_logger { generate(:controller, 'demo_items',"-a=/subby","-r=#{@apptmp}/sample_project") }
148
- silence_logger { generate(:controller, 'demo_items',"-a=/subby","-r=#{@apptmp}/sample_project",'-d') }
153
+ capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=bacon') }
154
+ capture_io { generate(:app, 'subby', "-r=#{@apptmp}/sample_project") }
155
+ capture_io { generate(:controller, 'demo_items',"-a=/subby","-r=#{@apptmp}/sample_project") }
156
+ capture_io { generate(:controller, 'demo_items',"-a=/subby","-r=#{@apptmp}/sample_project",'-d') }
149
157
  assert_no_file_exists(@controller_path.gsub('app','subby'))
150
158
  assert_no_file_exists(@controller_test_path.gsub('app','subby'))
151
159
  assert_no_file_exists("#{@apptmp}/sample_project/app/helpers/demo_items_helper.rb")
@@ -1,6 +1,6 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/helper')
2
2
 
3
- class TestGenerator < Test::Unit::TestCase
3
+ describe "Generator" do
4
4
 
5
5
  context "the generator" do
6
6
  should "have default generators" do
@@ -1,6 +1,6 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/helper')
2
2
 
3
- class TestMailerGenerator < Test::Unit::TestCase
3
+ describe "MailerGenerator" do
4
4
  def setup
5
5
  @apptmp = "#{Dir.tmpdir}/padrino-tests/#{UUID.new.generate}"
6
6
  `mkdir -p #{@apptmp}`
@@ -12,23 +12,23 @@ class TestMailerGenerator < Test::Unit::TestCase
12
12
 
13
13
  context 'the mailer generator' do
14
14
  should "fail outside app root" do
15
- output = silence_logger { generate(:mailer, 'demo', "-r=#{@apptmp}") }
16
- assert_match(/not at the root/, output)
15
+ out, err = capture_io { generate(:mailer, 'demo', "-r=#{@apptmp}") }
16
+ assert_match(/not at the root/, out)
17
17
  assert_no_file_exists('/tmp/app/mailers/demo_mailer.rb')
18
18
  end
19
19
 
20
20
  should "generate mailer in specified app" do
21
- silence_logger { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=bacon') }
22
- silence_logger { generate(:app, 'subby', "-r=#{@apptmp}/sample_project") }
23
- silence_logger { generate(:mailer, 'demo', '-a=/subby', "-r=#{@apptmp}/sample_project") }
21
+ capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=bacon') }
22
+ capture_io { generate(:app, 'subby', "-r=#{@apptmp}/sample_project") }
23
+ capture_io { generate(:mailer, 'demo', '-a=/subby', "-r=#{@apptmp}/sample_project") }
24
24
  assert_match_in_file(/Subby.mailer :demo/m, "#{@apptmp}/sample_project/subby/mailers/demo.rb")
25
25
  assert_dir_exists("#{@apptmp}/sample_project/subby/views/mailers/demo")
26
26
  end
27
27
 
28
28
  should "generate mailer in specified app with actions" do
29
- silence_logger { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=bacon') }
30
- silence_logger { generate(:app, 'subby', "-r=#{@apptmp}/sample_project") }
31
- silence_logger { generate(:mailer, 'demo', 'action1', 'action2', '-a=/subby', "-r=#{@apptmp}/sample_project") }
29
+ capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=bacon') }
30
+ capture_io { generate(:app, 'subby', "-r=#{@apptmp}/sample_project") }
31
+ capture_io { generate(:mailer, 'demo', 'action1', 'action2', '-a=/subby', "-r=#{@apptmp}/sample_project") }
32
32
  assert_match_in_file(/Subby.mailer :demo/m, "#{@apptmp}/sample_project/subby/mailers/demo.rb")
33
33
  assert_match_in_file(/email :action1 do.*?end/m, "#{@apptmp}/sample_project/subby/mailers/demo.rb")
34
34
  assert_match_in_file(/email :action2 do.*?end/m, "#{@apptmp}/sample_project/subby/mailers/demo.rb")
@@ -36,22 +36,22 @@ class TestMailerGenerator < Test::Unit::TestCase
36
36
  end
37
37
 
38
38
  should "support generating a new mailer extended from base" do
39
- silence_logger { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=bacon') }
40
- silence_logger { generate(:mailer, 'demo', "-r=#{@apptmp}/sample_project") }
39
+ capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=bacon') }
40
+ capture_io { generate(:mailer, 'demo', "-r=#{@apptmp}/sample_project") }
41
41
  assert_match_in_file(/SampleProject.mailer :demo/m, "#{@apptmp}/sample_project/app/mailers/demo.rb")
42
42
  assert_dir_exists("#{@apptmp}/sample_project/app/views/mailers/demo")
43
43
  end
44
44
 
45
45
  should "support generating a new mailer extended from base with long name" do
46
- silence_logger { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=bacon') }
47
- silence_logger { generate(:mailer, 'UserNotice', "-r=#{@apptmp}/sample_project") }
46
+ capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=bacon') }
47
+ capture_io { generate(:mailer, 'UserNotice', "-r=#{@apptmp}/sample_project") }
48
48
  assert_match_in_file(/SampleProject.mailer :user_notice/m, "#{@apptmp}/sample_project/app/mailers/user_notice.rb")
49
49
  assert_dir_exists("#{@apptmp}/sample_project/app/views/mailers/user_notice")
50
50
  end
51
51
 
52
52
  should "support generating a new mailer extended from base with capitalized name" do
53
- silence_logger { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=bacon') }
54
- silence_logger { generate(:mailer, 'DEMO', "-r=#{@apptmp}/sample_project") }
53
+ capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=bacon') }
54
+ capture_io { generate(:mailer, 'DEMO', "-r=#{@apptmp}/sample_project") }
55
55
  assert_match_in_file(/SampleProject.mailer :demo/m, "#{@apptmp}/sample_project/app/mailers/demo.rb")
56
56
  assert_dir_exists("#{@apptmp}/sample_project/app/views/mailers/demo")
57
57
  end
@@ -59,9 +59,9 @@ class TestMailerGenerator < Test::Unit::TestCase
59
59
 
60
60
  context "the mailer destroy option" do
61
61
  should "destroy mailer file" do
62
- silence_logger { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=bacon') }
63
- silence_logger { generate(:mailer, 'demo', "-r=#{@apptmp}/sample_project") }
64
- silence_logger { generate(:mailer, 'demo', "-r=#{@apptmp}/sample_project",'-d') }
62
+ capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=bacon') }
63
+ capture_io { generate(:mailer, 'demo', "-r=#{@apptmp}/sample_project") }
64
+ capture_io { generate(:mailer, 'demo', "-r=#{@apptmp}/sample_project",'-d') }
65
65
  assert_no_dir_exists("#{@apptmp}/sample_project/app/views/demo")
66
66
  assert_no_file_exists("#{@apptmp}/sample_project/app/mailers/demo.rb")
67
67
  end
@@ -1,6 +1,6 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/helper')
2
2
 
3
- class TestMigrationGenerator < Test::Unit::TestCase
3
+ describe "MigrationGenerator" do
4
4
  def setup
5
5
  @apptmp = "#{Dir.tmpdir}/padrino-tests/#{UUID.new.generate}"
6
6
  `mkdir -p #{@apptmp}`
@@ -12,33 +12,33 @@ class TestMigrationGenerator < Test::Unit::TestCase
12
12
 
13
13
  context 'the migration generator' do
14
14
  should "fail outside app root" do
15
- output = silence_logger { generate(:migration, 'add_email_to_users', '-r=/tmp') }
16
- assert_match(/not at the root/, output)
15
+ out, err = capture_io { generate(:migration, 'add_email_to_users', '-r=/tmp') }
16
+ assert_match(/not at the root/, out)
17
17
  assert_no_file_exists("#{@apptmp}/db/migrate")
18
18
  end
19
19
 
20
20
  should "fail if we don't use an adapter" do
21
- silence_logger { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=bacon') }
22
- assert_raise(SystemExit) { silence_logger { generate(:migration, 'AddEmailToUsers', "-r=#{@apptmp}/sample_project") } }
21
+ capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=bacon') }
22
+ assert_raises(SystemExit) { capture_io { generate(:migration, 'AddEmailToUsers', "-r=#{@apptmp}/sample_project") } }
23
23
  end
24
24
 
25
25
  should "generate migration inside app root" do
26
- silence_logger { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=bacon', '-d=activerecord') }
27
- response_success = silence_logger { generate(:migration, 'AddEmailToUsers', "-r=#{@apptmp}/sample_project") }
26
+ capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=bacon', '-d=activerecord') }
27
+ response_success = capture_io { generate(:migration, 'AddEmailToUsers', "-r=#{@apptmp}/sample_project") }
28
28
  migration_file_path = "#{@apptmp}/sample_project/db/migrate/001_add_email_to_users.rb"
29
29
  assert_match_in_file(/class AddEmailToUser/m, migration_file_path)
30
30
  end
31
31
 
32
32
  should "generate migration inside app root with lowercase migration argument" do
33
- silence_logger { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=bacon', '-d=activerecord') }
34
- response_success = silence_logger { generate(:migration, 'add_email_to_users', "-r=#{@apptmp}/sample_project") }
33
+ capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=bacon', '-d=activerecord') }
34
+ response_success = capture_io { generate(:migration, 'add_email_to_users', "-r=#{@apptmp}/sample_project") }
35
35
  migration_file_path = "#{@apptmp}/sample_project/db/migrate/001_add_email_to_users.rb"
36
36
  assert_match_in_file(/class AddEmailToUsers/m, migration_file_path)
37
37
  end
38
38
 
39
39
  should "generate migration inside app root with singular table" do
40
- silence_logger { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=bacon', '-d=activerecord') }
41
- silence_logger { generate(:migration, 'add_email_to_user', "email:string", "-r=#{@apptmp}/sample_project") }
40
+ capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=bacon', '-d=activerecord') }
41
+ capture_io { generate(:migration, 'add_email_to_user', "email:string", "-r=#{@apptmp}/sample_project") }
42
42
  migration_file_path = "#{@apptmp}/sample_project/db/migrate/001_add_email_to_user.rb"
43
43
  assert_match_in_file(/class AddEmailToUser/m, migration_file_path)
44
44
  assert_match_in_file(/t.string :email/, migration_file_path)
@@ -46,10 +46,10 @@ class TestMigrationGenerator < Test::Unit::TestCase
46
46
  end
47
47
 
48
48
  should "properly calculate version number" do
49
- silence_logger { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=bacon', '-d=sequel') }
50
- silence_logger { generate(:migration, 'add_email_to_person', "email:string", "-r=#{@apptmp}/sample_project") }
51
- silence_logger { generate(:migration, 'add_name_to_person', "email:string", "-r=#{@apptmp}/sample_project") }
52
- silence_logger { generate(:migration, 'add_age_to_user', "email:string", "-r=#{@apptmp}/sample_project") }
49
+ capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=bacon', '-d=sequel') }
50
+ capture_io { generate(:migration, 'add_email_to_person', "email:string", "-r=#{@apptmp}/sample_project") }
51
+ capture_io { generate(:migration, 'add_name_to_person', "email:string", "-r=#{@apptmp}/sample_project") }
52
+ capture_io { generate(:migration, 'add_age_to_user', "email:string", "-r=#{@apptmp}/sample_project") }
53
53
  assert_match_in_file(/class AddEmailToPerson/m, "#{@apptmp}/sample_project/db/migrate/001_add_email_to_person.rb")
54
54
  assert_match_in_file(/class AddNameToPerson/m, "#{@apptmp}/sample_project/db/migrate/002_add_name_to_person.rb")
55
55
  assert_match_in_file(/class AddAgeToUser/m, "#{@apptmp}/sample_project/db/migrate/003_add_age_to_user.rb")
@@ -58,8 +58,8 @@ class TestMigrationGenerator < Test::Unit::TestCase
58
58
 
59
59
  context 'the migration generator for activerecord' do
60
60
  should "generate migration for generic needs" do
61
- silence_logger { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=bacon', '-d=activerecord') }
62
- response_success = silence_logger { generate(:migration, 'ModifyUserFields', "-r=#{@apptmp}/sample_project") }
61
+ capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=bacon', '-d=activerecord') }
62
+ response_success = capture_io { generate(:migration, 'ModifyUserFields', "-r=#{@apptmp}/sample_project") }
63
63
  migration_file_path = "#{@apptmp}/sample_project/db/migrate/001_modify_user_fields.rb"
64
64
  assert_match_in_file(/class ModifyUserFields/m, migration_file_path)
65
65
  assert_match_in_file(/def self\.up\s+end/m, migration_file_path)
@@ -67,9 +67,9 @@ class TestMigrationGenerator < Test::Unit::TestCase
67
67
  end
68
68
 
69
69
  should "generate migration for adding columns" do
70
- silence_logger { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=bacon', '-d=activerecord') }
70
+ capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=bacon', '-d=activerecord') }
71
71
  migration_params = ['AddEmailToUsers', "email:string", "age:integer", "-r=#{@apptmp}/sample_project"]
72
- response_success = silence_logger { generate(:migration, *migration_params) }
72
+ response_success = capture_io { generate(:migration, *migration_params) }
73
73
  migration_file_path = "#{@apptmp}/sample_project/db/migrate/001_add_email_to_users.rb"
74
74
  assert_match_in_file(/class AddEmailToUsers/m, migration_file_path)
75
75
  assert_match_in_file(/change_table :users.*?t\.string :email/m, migration_file_path)
@@ -79,9 +79,9 @@ class TestMigrationGenerator < Test::Unit::TestCase
79
79
  end
80
80
 
81
81
  should "generate migration for removing columns" do
82
- silence_logger { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=bacon', '-d=activerecord') }
82
+ capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=bacon', '-d=activerecord') }
83
83
  migration_params = ['RemoveEmailFromUsers', "email:string", "age:integer", "-r=#{@apptmp}/sample_project"]
84
- response_success = silence_logger { generate(:migration, *migration_params) }
84
+ response_success = capture_io { generate(:migration, *migration_params) }
85
85
  migration_file_path = "#{@apptmp}/sample_project/db/migrate/001_remove_email_from_users.rb"
86
86
  assert_match_in_file(/class RemoveEmailFromUsers/m, migration_file_path)
87
87
  assert_match_in_file(/change_table :users.*?t\.remove :email/m, migration_file_path)
@@ -93,8 +93,8 @@ class TestMigrationGenerator < Test::Unit::TestCase
93
93
 
94
94
  context 'the migration generator for datamapper' do
95
95
  should "generate migration for generic needs" do
96
- silence_logger { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=bacon', '-d=datamapper') }
97
- response_success = silence_logger { generate(:migration, 'ModifyUserFields', "-r=#{@apptmp}/sample_project") }
96
+ capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=bacon', '-d=datamapper') }
97
+ response_success = capture_io { generate(:migration, 'ModifyUserFields', "-r=#{@apptmp}/sample_project") }
98
98
  migration_file_path = "#{@apptmp}/sample_project/db/migrate/001_modify_user_fields.rb"
99
99
  assert_match_in_file(/migration\s1.*?:modify_user_fields/m, migration_file_path)
100
100
  assert_match_in_file(/up\sdo\s+end/m, migration_file_path)
@@ -102,9 +102,9 @@ class TestMigrationGenerator < Test::Unit::TestCase
102
102
  end
103
103
 
104
104
  should "generate migration for adding columns" do
105
- silence_logger { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=bacon', '-d=datamapper') }
105
+ capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=bacon', '-d=datamapper') }
106
106
  migration_params = ['AddEmailToUsers', "email:string", "age:integer", "-r=#{@apptmp}/sample_project"]
107
- response_success = silence_logger { generate(:migration, *migration_params) }
107
+ response_success = capture_io { generate(:migration, *migration_params) }
108
108
  migration_file_path = "#{@apptmp}/sample_project/db/migrate/001_add_email_to_users.rb"
109
109
  assert_match_in_file(/migration\s1.*?:add_email_to_users/m, migration_file_path)
110
110
  assert_match_in_file(/modify_table :users.*?add_column :email, String/m, migration_file_path)
@@ -114,9 +114,9 @@ class TestMigrationGenerator < Test::Unit::TestCase
114
114
  end
115
115
 
116
116
  should "generate migration for removing columns" do
117
- silence_logger { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=bacon', '-d=datamapper') }
117
+ capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=bacon', '-d=datamapper') }
118
118
  migration_params = ['RemoveEmailFromUsers', "email:string", "age:integer", "-r=#{@apptmp}/sample_project"]
119
- response_success = silence_logger { generate(:migration, *migration_params) }
119
+ response_success = capture_io { generate(:migration, *migration_params) }
120
120
  migration_file_path = "#{@apptmp}/sample_project/db/migrate/001_remove_email_from_users.rb"
121
121
  assert_match_in_file(/migration\s1.*?:remove_email_from_users/m, migration_file_path)
122
122
  assert_match_in_file(/modify_table :users.*?drop_column :email/m, migration_file_path)
@@ -126,10 +126,10 @@ class TestMigrationGenerator < Test::Unit::TestCase
126
126
  end
127
127
 
128
128
  should "properly version migration files" do
129
- silence_logger { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=bacon', '-d=datamapper') }
130
- response_success = silence_logger { generate(:migration, 'ModifyUserFields', "-r=#{@apptmp}/sample_project") }
131
- response_success = silence_logger { generate(:migration, 'ModifyUserFields2', "-r=#{@apptmp}/sample_project") }
132
- response_success = silence_logger { generate(:migration, 'ModifyUserFields3', "-r=#{@apptmp}/sample_project") }
129
+ capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=bacon', '-d=datamapper') }
130
+ response_success = capture_io { generate(:migration, 'ModifyUserFields', "-r=#{@apptmp}/sample_project") }
131
+ response_success = capture_io { generate(:migration, 'ModifyUserFields2', "-r=#{@apptmp}/sample_project") }
132
+ response_success = capture_io { generate(:migration, 'ModifyUserFields3', "-r=#{@apptmp}/sample_project") }
133
133
  assert_match_in_file(/migration\s1.*?:modify_user_fields/m, "#{@apptmp}/sample_project/db/migrate/001_modify_user_fields.rb")
134
134
  assert_match_in_file(/migration\s2.*?:modify_user_fields2/m, "#{@apptmp}/sample_project/db/migrate/002_modify_user_fields2.rb")
135
135
  assert_match_in_file(/migration\s3.*?:modify_user_fields3/m, "#{@apptmp}/sample_project/db/migrate/003_modify_user_fields3.rb")
@@ -138,8 +138,8 @@ class TestMigrationGenerator < Test::Unit::TestCase
138
138
 
139
139
  context 'the migration generator for sequel' do
140
140
  should "generate migration for generic needs" do
141
- silence_logger { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=bacon', '-d=sequel') }
142
- response_success = silence_logger { generate(:migration, 'ModifyUserFields', "-r=#{@apptmp}/sample_project") }
141
+ capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=bacon', '-d=sequel') }
142
+ response_success = capture_io { generate(:migration, 'ModifyUserFields', "-r=#{@apptmp}/sample_project") }
143
143
  migration_file_path = "#{@apptmp}/sample_project/db/migrate/001_modify_user_fields.rb"
144
144
  assert_match_in_file(/class ModifyUserFields/m, migration_file_path)
145
145
  assert_match_in_file(/def\sup\s+end/m, migration_file_path)
@@ -147,9 +147,9 @@ class TestMigrationGenerator < Test::Unit::TestCase
147
147
  end
148
148
 
149
149
  should "generate migration for adding columns" do
150
- silence_logger { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=bacon', '-d=sequel') }
150
+ capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=bacon', '-d=sequel') }
151
151
  migration_params = ['AddEmailToUsers', "email:string", "age:integer", "-r=#{@apptmp}/sample_project"]
152
- response_success = silence_logger { generate(:migration, *migration_params) }
152
+ response_success = capture_io { generate(:migration, *migration_params) }
153
153
  migration_file_path = "#{@apptmp}/sample_project/db/migrate/001_add_email_to_users.rb"
154
154
  assert_match_in_file(/class AddEmailToUsers/m, migration_file_path)
155
155
  assert_match_in_file(/alter_table :users.*?add_column :email, String/m, migration_file_path)
@@ -159,9 +159,9 @@ class TestMigrationGenerator < Test::Unit::TestCase
159
159
  end
160
160
 
161
161
  should "generate migration for removing columns" do
162
- silence_logger { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=bacon', '-d=sequel') }
162
+ capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=bacon', '-d=sequel') }
163
163
  migration_params = ['RemoveEmailFromUsers', "email:string", "age:integer", "-r=#{@apptmp}/sample_project"]
164
- response_success = silence_logger { generate(:migration, *migration_params) }
164
+ response_success = capture_io { generate(:migration, *migration_params) }
165
165
  migration_file_path = "#{@apptmp}/sample_project/db/migrate/001_remove_email_from_users.rb"
166
166
  assert_match_in_file(/class RemoveEmailFromUsers/m, migration_file_path)
167
167
  assert_match_in_file(/alter_table :users.*?drop_column :email/m, migration_file_path)
@@ -174,20 +174,20 @@ class TestMigrationGenerator < Test::Unit::TestCase
174
174
  context "the migration destroy option" do
175
175
 
176
176
  should "destroy the migration files" do
177
- silence_logger { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=bacon', '-d=sequel') }
177
+ capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=bacon', '-d=sequel') }
178
178
  migration_params = ['RemoveEmailFromUsers', "email:string", "age:integer", "-r=#{@apptmp}/sample_project"]
179
- silence_logger { generate(:migration, *migration_params) }
180
- silence_logger { generate(:migration, 'RemoveEmailFromUsers', "-r=#{@apptmp}/sample_project",'-d') }
179
+ capture_io { generate(:migration, *migration_params) }
180
+ capture_io { generate(:migration, 'RemoveEmailFromUsers', "-r=#{@apptmp}/sample_project",'-d') }
181
181
  assert_no_file_exists("#{@apptmp}/sample_project/db/migrate/001_remove_email_from_users.rb")
182
182
  end
183
183
 
184
184
  should "destroy the migration file regardless of number" do
185
- silence_logger { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=bacon', '-d=sequel') }
185
+ capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=bacon', '-d=sequel') }
186
186
  migration_params = ['RemoveEmailFromUsers', "email:string", "age:integer", "-r=#{@apptmp}/sample_project"]
187
187
  migration_param2 = ['AddEmailFromUsers', "email:string", "age:integer", "-r=#{@apptmp}/sample_project"]
188
- silence_logger { generate(:migration, *migration_param2) }
189
- silence_logger { generate(:migration, *migration_params) }
190
- silence_logger { generate(:migration, 'RemoveEmailFromUsers', "-r=#{@apptmp}/sample_project",'-d') }
188
+ capture_io { generate(:migration, *migration_param2) }
189
+ capture_io { generate(:migration, *migration_params) }
190
+ capture_io { generate(:migration, 'RemoveEmailFromUsers', "-r=#{@apptmp}/sample_project",'-d') }
191
191
  assert_no_file_exists("#{@apptmp}/sample_project/db/migrate/002_remove_email_from_users.rb")
192
192
  end
193
193
  end