padrino-gen 0.9.9 → 0.9.10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (72) hide show
  1. data/README.rdoc +10 -10
  2. data/Rakefile +4 -15
  3. data/bin/padrino-gen +3 -0
  4. data/lib/padrino-gen/generators/actions.rb +10 -4
  5. data/lib/padrino-gen/generators/app/app.rb.tt +2 -2
  6. data/lib/padrino-gen/generators/components/mocks/mocha.rb +9 -0
  7. data/lib/padrino-gen/generators/components/mocks/rr.rb +11 -0
  8. data/lib/padrino-gen/generators/components/orms/activerecord.rb +112 -0
  9. data/lib/padrino-gen/generators/components/orms/couchrest.rb +44 -0
  10. data/lib/padrino-gen/generators/components/orms/datamapper.rb +86 -0
  11. data/lib/padrino-gen/generators/components/orms/mongoid.rb +68 -0
  12. data/lib/padrino-gen/generators/components/orms/mongomapper.rb +43 -0
  13. data/lib/padrino-gen/generators/components/orms/sequel.rb +71 -0
  14. data/lib/padrino-gen/generators/components/renderers/erb.rb +3 -0
  15. data/lib/padrino-gen/generators/components/renderers/haml.rb +3 -0
  16. data/lib/padrino-gen/generators/components/scripts/extcore.rb +4 -0
  17. data/lib/padrino-gen/generators/components/scripts/jquery.rb +4 -0
  18. data/lib/padrino-gen/generators/components/scripts/mootools.rb +4 -0
  19. data/lib/padrino-gen/generators/components/scripts/prototype.rb +5 -0
  20. data/lib/padrino-gen/generators/components/scripts/rightjs.rb +4 -0
  21. data/lib/padrino-gen/generators/components/stylesheets/less.rb +33 -0
  22. data/lib/padrino-gen/generators/components/stylesheets/sass.rb +25 -0
  23. data/lib/padrino-gen/generators/components/tests/bacon.rb +64 -0
  24. data/lib/padrino-gen/generators/components/tests/cucumber.rb +63 -0
  25. data/lib/padrino-gen/generators/components/tests/riot.rb +69 -0
  26. data/lib/padrino-gen/generators/components/tests/rspec.rb +66 -0
  27. data/lib/padrino-gen/generators/components/tests/shoulda.rb +70 -0
  28. data/lib/padrino-gen/generators/components/tests/testspec.rb +63 -0
  29. data/lib/padrino-gen/generators/controller.rb +4 -4
  30. data/lib/padrino-gen/generators/project/config/apps.rb.tt +12 -4
  31. data/lib/padrino-gen/generators/project/config/boot.rb +1 -1
  32. data/lib/padrino-gen/generators/project.rb +1 -1
  33. data/lib/padrino-gen/generators/templates/controller.rb.tt +1 -1
  34. data/lib/padrino-gen/generators/templates/scripts/ext-core.js +8 -0
  35. data/lib/padrino-gen/generators/templates/scripts/jquery.js +150 -15
  36. data/lib/padrino-gen/padrino-tasks/activerecord.rb +1 -1
  37. data/lib/padrino-gen/padrino-tasks/mongomapper.rb +1 -1
  38. data/lib/padrino-gen/padrino-tasks/sequel.rb +37 -0
  39. data/lib/padrino-gen.rb +9 -2
  40. data/padrino-gen.gemspec +30 -28
  41. data/test/helper.rb +5 -0
  42. data/test/test_app_generator.rb +11 -19
  43. data/test/test_cli.rb +4 -6
  44. data/test/test_controller_generator.rb +43 -33
  45. data/test/test_mailer_generator.rb +11 -17
  46. data/test/test_migration_generator.rb +42 -47
  47. data/test/test_model_generator.rb +90 -89
  48. data/test/test_project_generator.rb +43 -39
  49. metadata +30 -28
  50. data/VERSION +0 -1
  51. data/lib/padrino-gen/generators/components/mocks/mocha_gen.rb +0 -20
  52. data/lib/padrino-gen/generators/components/mocks/rr_gen.rb +0 -22
  53. data/lib/padrino-gen/generators/components/orms/activerecord_gen.rb +0 -123
  54. data/lib/padrino-gen/generators/components/orms/couchrest_gen.rb +0 -56
  55. data/lib/padrino-gen/generators/components/orms/datamapper_gen.rb +0 -97
  56. data/lib/padrino-gen/generators/components/orms/mongoid_gen.rb +0 -80
  57. data/lib/padrino-gen/generators/components/orms/mongomapper_gen.rb +0 -55
  58. data/lib/padrino-gen/generators/components/orms/sequel_gen.rb +0 -83
  59. data/lib/padrino-gen/generators/components/renderers/erb_gen.rb +0 -14
  60. data/lib/padrino-gen/generators/components/renderers/haml_gen.rb +0 -15
  61. data/lib/padrino-gen/generators/components/scripts/jquery_gen.rb +0 -15
  62. data/lib/padrino-gen/generators/components/scripts/mootools_gen.rb +0 -15
  63. data/lib/padrino-gen/generators/components/scripts/prototype_gen.rb +0 -16
  64. data/lib/padrino-gen/generators/components/scripts/rightjs_gen.rb +0 -15
  65. data/lib/padrino-gen/generators/components/stylesheets/less_gen.rb +0 -43
  66. data/lib/padrino-gen/generators/components/stylesheets/sass_gen.rb +0 -35
  67. data/lib/padrino-gen/generators/components/tests/bacon_test_gen.rb +0 -75
  68. data/lib/padrino-gen/generators/components/tests/cucumber_test_gen.rb +0 -76
  69. data/lib/padrino-gen/generators/components/tests/riot_test_gen.rb +0 -80
  70. data/lib/padrino-gen/generators/components/tests/rspec_test_gen.rb +0 -85
  71. data/lib/padrino-gen/generators/components/tests/shoulda_test_gen.rb +0 -81
  72. data/lib/padrino-gen/generators/components/tests/testspec_test_gen.rb +0 -74
@@ -1,42 +1,39 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/helper')
2
- require 'thor/group'
3
2
 
4
3
  class TestMigrationGenerator < Test::Unit::TestCase
5
4
  def setup
6
- @project = Padrino::Generators::Project.dup
7
- @mig_gen = Padrino::Generators::Migration.dup
8
5
  `rm -rf /tmp/sample_project`
9
6
  end
10
7
 
11
8
  context 'the migration generator' do
12
9
  should "fail outside app root" do
13
- output = silence_logger { @mig_gen.start(['add_email_to_users', '-r=/tmp']) }
10
+ output = silence_logger { generate(:migration, 'add_email_to_users', '-r=/tmp') }
14
11
  assert_match(/not at the root/, output)
15
12
  assert_no_file_exists('/tmp/db/migration')
16
13
  end
17
14
 
18
15
  should "fail if we don't use an adapter" do
19
- silence_logger { @project.start(['sample_project', '--root=/tmp', '--script=none', '-t=bacon']) }
20
- assert_raise(SystemExit) { silence_logger { @mig_gen.start(['AddEmailToUsers', '-r=/tmp/sample_project']) } }
16
+ silence_logger { generate(:project, 'sample_project', '--root=/tmp', '--script=none', '-t=bacon') }
17
+ assert_raise(SystemExit) { silence_logger { generate(:migration, 'AddEmailToUsers', '-r=/tmp/sample_project') } }
21
18
  end
22
19
 
23
20
  should "generate migration inside app root" do
24
- silence_logger { @project.start(['sample_project', '--root=/tmp', '--script=none', '-t=bacon', '-d=activerecord']) }
25
- response_success = silence_logger { @mig_gen.start(['AddEmailToUsers', '-r=/tmp/sample_project']) }
21
+ silence_logger { generate(:project, 'sample_project', '--root=/tmp', '--script=none', '-t=bacon', '-d=activerecord') }
22
+ response_success = silence_logger { generate(:migration, 'AddEmailToUsers', '-r=/tmp/sample_project') }
26
23
  migration_file_path = "/tmp/sample_project/db/migrate/001_add_email_to_users.rb"
27
24
  assert_match_in_file(/class AddEmailToUser/m, migration_file_path)
28
25
  end
29
26
 
30
27
  should "generate migration inside app root with lowercase migration argument" do
31
- silence_logger { @project.start(['sample_project', '--root=/tmp', '--script=none', '-t=bacon', '-d=activerecord']) }
32
- response_success = silence_logger { @mig_gen.start(['add_email_to_users', '-r=/tmp/sample_project']) }
28
+ silence_logger { generate(:project, 'sample_project', '--root=/tmp', '--script=none', '-t=bacon', '-d=activerecord') }
29
+ response_success = silence_logger { generate(:migration, 'add_email_to_users', '-r=/tmp/sample_project') }
33
30
  migration_file_path = "/tmp/sample_project/db/migrate/001_add_email_to_users.rb"
34
31
  assert_match_in_file(/class AddEmailToUsers/m, migration_file_path)
35
32
  end
36
33
 
37
34
  should "generate migration inside app root with singular table" do
38
- silence_logger { @project.start(['sample_project', '--root=/tmp', '--script=none', '-t=bacon', '-d=activerecord']) }
39
- silence_logger { @mig_gen.start(['add_email_to_user', "email:string", '-r=/tmp/sample_project']) }
35
+ silence_logger { generate(:project, 'sample_project', '--root=/tmp', '--script=none', '-t=bacon', '-d=activerecord') }
36
+ silence_logger { generate(:migration, 'add_email_to_user', "email:string", '-r=/tmp/sample_project') }
40
37
  migration_file_path = "/tmp/sample_project/db/migrate/001_add_email_to_user.rb"
41
38
  assert_match_in_file(/class AddEmailToUser/m, migration_file_path)
42
39
  assert_match_in_file(/t.string :email/, migration_file_path)
@@ -44,10 +41,10 @@ class TestMigrationGenerator < Test::Unit::TestCase
44
41
  end
45
42
 
46
43
  should "properly calculate version number" do
47
- silence_logger { @project.start(['sample_project', '--root=/tmp', '--script=none', '-t=bacon', '-d=sequel']) }
48
- silence_logger { @mig_gen.start(['add_email_to_person', "email:string", '-r=/tmp/sample_project']) }
49
- silence_logger { @mig_gen.start(['add_name_to_person', "email:string", '-r=/tmp/sample_project']) }
50
- silence_logger { @mig_gen.start(['add_age_to_user', "email:string", '-r=/tmp/sample_project']) }
44
+ silence_logger { generate(:project, 'sample_project', '--root=/tmp', '--script=none', '-t=bacon', '-d=sequel') }
45
+ silence_logger { generate(:migration, 'add_email_to_person', "email:string", '-r=/tmp/sample_project') }
46
+ silence_logger { generate(:migration, 'add_name_to_person', "email:string", '-r=/tmp/sample_project') }
47
+ silence_logger { generate(:migration, 'add_age_to_user', "email:string", '-r=/tmp/sample_project') }
51
48
  assert_match_in_file(/class AddEmailToPerson/m, "/tmp/sample_project/db/migrate/001_add_email_to_person.rb")
52
49
  assert_match_in_file(/class AddNameToPerson/m, "/tmp/sample_project/db/migrate/002_add_name_to_person.rb")
53
50
  assert_match_in_file(/class AddAgeToUser/m, "/tmp/sample_project/db/migrate/003_add_age_to_user.rb")
@@ -56,8 +53,8 @@ class TestMigrationGenerator < Test::Unit::TestCase
56
53
 
57
54
  context 'the migration generator for activerecord' do
58
55
  should "generate migration for generic needs" do
59
- silence_logger { @project.start(['sample_project', '--root=/tmp', '--script=none', '-t=bacon', '-d=activerecord']) }
60
- response_success = silence_logger { @mig_gen.start(['ModifyUserFields', '-r=/tmp/sample_project']) }
56
+ silence_logger { generate(:project, 'sample_project', '--root=/tmp', '--script=none', '-t=bacon', '-d=activerecord') }
57
+ response_success = silence_logger { generate(:migration, 'ModifyUserFields', '-r=/tmp/sample_project') }
61
58
  migration_file_path = "/tmp/sample_project/db/migrate/001_modify_user_fields.rb"
62
59
  assert_match_in_file(/class ModifyUserFields/m, migration_file_path)
63
60
  assert_match_in_file(/def self\.up\s+end/m, migration_file_path)
@@ -65,9 +62,9 @@ class TestMigrationGenerator < Test::Unit::TestCase
65
62
  end
66
63
 
67
64
  should "generate migration for adding columns" do
68
- silence_logger { @project.start(['sample_project', '--root=/tmp', '--script=none', '-t=bacon', '-d=activerecord']) }
65
+ silence_logger { generate(:project, 'sample_project', '--root=/tmp', '--script=none', '-t=bacon', '-d=activerecord') }
69
66
  migration_params = ['AddEmailToUsers', "email:string", "age:integer", '-r=/tmp/sample_project']
70
- response_success = silence_logger { @mig_gen.start(migration_params) }
67
+ response_success = silence_logger { generate(:migration, *migration_params) }
71
68
  migration_file_path = "/tmp/sample_project/db/migrate/001_add_email_to_users.rb"
72
69
  assert_match_in_file(/class AddEmailToUsers/m, migration_file_path)
73
70
  assert_match_in_file(/change_table :users.*?t\.string :email/m, migration_file_path)
@@ -77,9 +74,9 @@ class TestMigrationGenerator < Test::Unit::TestCase
77
74
  end
78
75
 
79
76
  should "generate migration for removing columns" do
80
- silence_logger { @project.start(['sample_project', '--root=/tmp', '--script=none', '-t=bacon', '-d=activerecord']) }
77
+ silence_logger { generate(:project, 'sample_project', '--root=/tmp', '--script=none', '-t=bacon', '-d=activerecord') }
81
78
  migration_params = ['RemoveEmailFromUsers', "email:string", "age:integer", '-r=/tmp/sample_project']
82
- response_success = silence_logger { @mig_gen.start(migration_params) }
79
+ response_success = silence_logger { generate(:migration, *migration_params) }
83
80
  migration_file_path = "/tmp/sample_project/db/migrate/001_remove_email_from_users.rb"
84
81
  assert_match_in_file(/class RemoveEmailFromUsers/m, migration_file_path)
85
82
  assert_match_in_file(/change_table :users.*?t\.remove :email/m, migration_file_path)
@@ -91,8 +88,8 @@ class TestMigrationGenerator < Test::Unit::TestCase
91
88
 
92
89
  context 'the migration generator for datamapper' do
93
90
  should "generate migration for generic needs" do
94
- silence_logger { @project.start(['sample_project', '--root=/tmp', '--script=none', '-t=bacon', '-d=datamapper']) }
95
- response_success = silence_logger { @mig_gen.start(['ModifyUserFields', '-r=/tmp/sample_project']) }
91
+ silence_logger { generate(:project, 'sample_project', '--root=/tmp', '--script=none', '-t=bacon', '-d=datamapper') }
92
+ response_success = silence_logger { generate(:migration, 'ModifyUserFields', '-r=/tmp/sample_project') }
96
93
  migration_file_path = "/tmp/sample_project/db/migrate/001_modify_user_fields.rb"
97
94
  assert_match_in_file(/migration\s1.*?:modify_user_fields/m, migration_file_path)
98
95
  assert_match_in_file(/up\sdo\s+end/m, migration_file_path)
@@ -100,9 +97,9 @@ class TestMigrationGenerator < Test::Unit::TestCase
100
97
  end
101
98
 
102
99
  should "generate migration for adding columns" do
103
- silence_logger { @project.start(['sample_project', '--root=/tmp', '--script=none', '-t=bacon', '-d=datamapper']) }
100
+ silence_logger { generate(:project, 'sample_project', '--root=/tmp', '--script=none', '-t=bacon', '-d=datamapper') }
104
101
  migration_params = ['AddEmailToUsers', "email:string", "age:integer", '-r=/tmp/sample_project']
105
- response_success = silence_logger { @mig_gen.start(migration_params) }
102
+ response_success = silence_logger { generate(:migration, *migration_params) }
106
103
  migration_file_path = "/tmp/sample_project/db/migrate/001_add_email_to_users.rb"
107
104
  assert_match_in_file(/migration\s1.*?:add_email_to_users/m, migration_file_path)
108
105
  assert_match_in_file(/modify_table :users.*?add_column :email, String/m, migration_file_path)
@@ -112,9 +109,9 @@ class TestMigrationGenerator < Test::Unit::TestCase
112
109
  end
113
110
 
114
111
  should "generate migration for removing columns" do
115
- silence_logger { @project.start(['sample_project', '--root=/tmp', '--script=none', '-t=bacon', '-d=datamapper']) }
112
+ silence_logger { generate(:project, 'sample_project', '--root=/tmp', '--script=none', '-t=bacon', '-d=datamapper') }
116
113
  migration_params = ['RemoveEmailFromUsers', "email:string", "age:integer", '-r=/tmp/sample_project']
117
- response_success = silence_logger { @mig_gen.start(migration_params) }
114
+ response_success = silence_logger { generate(:migration, *migration_params) }
118
115
  migration_file_path = "/tmp/sample_project/db/migrate/001_remove_email_from_users.rb"
119
116
  assert_match_in_file(/migration\s1.*?:remove_email_from_users/m, migration_file_path)
120
117
  assert_match_in_file(/modify_table :users.*?drop_column :email/m, migration_file_path)
@@ -124,10 +121,10 @@ class TestMigrationGenerator < Test::Unit::TestCase
124
121
  end
125
122
 
126
123
  should "properly version migration files" do
127
- silence_logger { @project.start(['sample_project', '--root=/tmp', '--script=none', '-t=bacon', '-d=datamapper']) }
128
- response_success = silence_logger { @mig_gen.start(['ModifyUserFields', '-r=/tmp/sample_project']) }
129
- response_success = silence_logger { @mig_gen.start(['ModifyUserFields2', '-r=/tmp/sample_project']) }
130
- response_success = silence_logger { @mig_gen.start(['ModifyUserFields3', '-r=/tmp/sample_project']) }
124
+ silence_logger { generate(:project, 'sample_project', '--root=/tmp', '--script=none', '-t=bacon', '-d=datamapper') }
125
+ response_success = silence_logger { generate(:migration, 'ModifyUserFields', '-r=/tmp/sample_project') }
126
+ response_success = silence_logger { generate(:migration, 'ModifyUserFields2', '-r=/tmp/sample_project') }
127
+ response_success = silence_logger { generate(:migration, 'ModifyUserFields3', '-r=/tmp/sample_project') }
131
128
  assert_match_in_file(/migration\s1.*?:modify_user_fields/m, "/tmp/sample_project/db/migrate/001_modify_user_fields.rb")
132
129
  assert_match_in_file(/migration\s2.*?:modify_user_fields2/m, "/tmp/sample_project/db/migrate/002_modify_user_fields2.rb")
133
130
  assert_match_in_file(/migration\s3.*?:modify_user_fields3/m, "/tmp/sample_project/db/migrate/003_modify_user_fields3.rb")
@@ -136,8 +133,8 @@ class TestMigrationGenerator < Test::Unit::TestCase
136
133
 
137
134
  context 'the migration generator for sequel' do
138
135
  should "generate migration for generic needs" do
139
- silence_logger { @project.start(['sample_project', '--root=/tmp', '--script=none', '-t=bacon', '-d=sequel']) }
140
- response_success = silence_logger { @mig_gen.start(['ModifyUserFields', '-r=/tmp/sample_project']) }
136
+ silence_logger { generate(:project, 'sample_project', '--root=/tmp', '--script=none', '-t=bacon', '-d=sequel') }
137
+ response_success = silence_logger { generate(:migration, 'ModifyUserFields', '-r=/tmp/sample_project') }
141
138
  migration_file_path = "/tmp/sample_project/db/migrate/001_modify_user_fields.rb"
142
139
  assert_match_in_file(/class ModifyUserFields/m, migration_file_path)
143
140
  assert_match_in_file(/def\sup\s+end/m, migration_file_path)
@@ -145,9 +142,9 @@ class TestMigrationGenerator < Test::Unit::TestCase
145
142
  end
146
143
 
147
144
  should "generate migration for adding columns" do
148
- silence_logger { @project.start(['sample_project', '--root=/tmp', '--script=none', '-t=bacon', '-d=sequel']) }
145
+ silence_logger { generate(:project, 'sample_project', '--root=/tmp', '--script=none', '-t=bacon', '-d=sequel') }
149
146
  migration_params = ['AddEmailToUsers', "email:string", "age:integer", '-r=/tmp/sample_project']
150
- response_success = silence_logger { @mig_gen.start(migration_params) }
147
+ response_success = silence_logger { generate(:migration, *migration_params) }
151
148
  migration_file_path = "/tmp/sample_project/db/migrate/001_add_email_to_users.rb"
152
149
  assert_match_in_file(/class AddEmailToUsers/m, migration_file_path)
153
150
  assert_match_in_file(/alter_table :users.*?add_column :email, String/m, migration_file_path)
@@ -157,9 +154,9 @@ class TestMigrationGenerator < Test::Unit::TestCase
157
154
  end
158
155
 
159
156
  should "generate migration for removing columns" do
160
- silence_logger { @project.start(['sample_project', '--root=/tmp', '--script=none', '-t=bacon', '-d=sequel']) }
157
+ silence_logger { generate(:project, 'sample_project', '--root=/tmp', '--script=none', '-t=bacon', '-d=sequel') }
161
158
  migration_params = ['RemoveEmailFromUsers', "email:string", "age:integer", '-r=/tmp/sample_project']
162
- response_success = silence_logger { @mig_gen.start(migration_params) }
159
+ response_success = silence_logger { generate(:migration, *migration_params) }
163
160
  migration_file_path = "/tmp/sample_project/db/migrate/001_remove_email_from_users.rb"
164
161
  assert_match_in_file(/class RemoveEmailFromUsers/m, migration_file_path)
165
162
  assert_match_in_file(/alter_table :users.*?drop_column :email/m, migration_file_path)
@@ -172,23 +169,21 @@ class TestMigrationGenerator < Test::Unit::TestCase
172
169
  context "the migration destroy option" do
173
170
 
174
171
  should "destroy the migration files" do
175
- silence_logger { @project.start(['sample_project', '--root=/tmp', '--script=none', '-t=bacon', '-d=sequel']) }
172
+ silence_logger { generate(:project, 'sample_project', '--root=/tmp', '--script=none', '-t=bacon', '-d=sequel') }
176
173
  migration_params = ['RemoveEmailFromUsers', "email:string", "age:integer", '-r=/tmp/sample_project']
177
- silence_logger { @mig_gen.start(migration_params) }
178
- silence_logger { @mig_gen.start(['RemoveEmailFromUsers', '-r=/tmp/sample_project','-d']) }
174
+ silence_logger { generate(:migration, *migration_params) }
175
+ silence_logger { generate(:migration, 'RemoveEmailFromUsers', '-r=/tmp/sample_project','-d') }
179
176
  assert_no_file_exists("/tmp/sample_project/db/migrate/001_remove_email_from_users.rb")
180
177
  end
181
178
 
182
179
  should "destroy the migration file regardless of number" do
183
- silence_logger { @project.start(['sample_project', '--root=/tmp', '--script=none', '-t=bacon', '-d=sequel']) }
180
+ silence_logger { generate(:project, 'sample_project', '--root=/tmp', '--script=none', '-t=bacon', '-d=sequel') }
184
181
  migration_params = ['RemoveEmailFromUsers', "email:string", "age:integer", '-r=/tmp/sample_project']
185
182
  migration_param2 = ['AddEmailFromUsers', "email:string", "age:integer", '-r=/tmp/sample_project']
186
- silence_logger { @mig_gen.start(migration_param2) }
187
- silence_logger { @mig_gen.start(migration_params) }
188
- silence_logger { @mig_gen.start(['RemoveEmailFromUsers', '-r=/tmp/sample_project','-d']) }
183
+ silence_logger { generate(:migration, *migration_param2) }
184
+ silence_logger { generate(:migration, *migration_params) }
185
+ silence_logger { generate(:migration, 'RemoveEmailFromUsers', '-r=/tmp/sample_project','-d') }
189
186
  assert_no_file_exists("/tmp/sample_project/db/migrate/002_remove_email_from_users.rb")
190
187
  end
191
-
192
188
  end
193
-
194
189
  end
@@ -1,46 +1,49 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/helper')
2
- require 'thor/group'
3
2
 
4
3
  class TestModelGenerator < Test::Unit::TestCase
5
4
  def setup
6
- @project = Padrino::Generators::Project.dup
7
- @model_gen = Padrino::Generators::Model.dup
8
5
  `rm -rf /tmp/sample_project`
9
6
  end
10
7
 
11
8
  context 'the model generator' do
12
9
  should "fail outside app root" do
13
- output = silence_logger { @model_gen.start(['user', '-r=/tmp']) }
10
+ output = silence_logger { generate(:model, 'user', '-r=/tmp') }
14
11
  assert_match(/not at the root/, output)
15
12
  assert_no_file_exists('/tmp/app/models/user.rb')
16
13
  end
17
14
 
15
+ should "generate filename properly" do
16
+ silence_logger { generate(:project, 'sample_project', '--root=/tmp', '--script=none', '-t=bacon', '-d=couchrest') }
17
+ silence_logger { generate(:model, 'DemoItem', "name:string", "age", "email:string", '-r=/tmp/sample_project') }
18
+ assert_file_exists('/tmp/sample_project/app/models/demo_item.rb')
19
+ end
20
+
18
21
  should "fail if we don't use an adapter" do
19
- silence_logger { @project.start(['sample_project', '--root=/tmp', '--script=none', '-t=bacon']) }
20
- assert_raise(SystemExit) { silence_logger { @model_gen.start(['user', '-r=/tmp/sample_project']) } }
22
+ silence_logger { generate(:project, 'sample_project', '--root=/tmp', '--script=none', '-t=bacon') }
23
+ assert_raise(SystemExit) { silence_logger { generate(:model, 'user', '-r=/tmp/sample_project') } }
21
24
  end
22
25
 
23
26
  should 'not fail if we don\'t have test component' do
24
- silence_logger { @project.start(['sample_project', '--root=/tmp', '--test=none', '-d=activerecord']) }
25
- response_success = silence_logger { @model_gen.start(['user', '-r=/tmp/sample_project']) }
27
+ silence_logger { generate(:project, 'sample_project', '--root=/tmp', '--test=none', '-d=activerecord') }
28
+ response_success = silence_logger { generate(:model, 'user', '-r=/tmp/sample_project') }
26
29
  assert_match_in_file(/class User < ActiveRecord::Base/m, '/tmp/sample_project/app/models/user.rb')
27
30
  assert_no_file_exists('/tmp/sample_project/test')
28
31
  end
29
32
 
30
33
  should "generate only generate model once" do
31
- silence_logger { @project.start(['sample_project', '--root=/tmp', '--script=none', '-t=bacon', '-d=activerecord']) }
32
- response_success = silence_logger { @model_gen.start(['user', '-r=/tmp/sample_project']) }
33
- response_duplicate = silence_logger { @model_gen.start(['user', '-r=/tmp/sample_project']) }
34
+ silence_logger { generate(:project, 'sample_project', '--root=/tmp', '--script=none', '-t=bacon', '-d=activerecord') }
35
+ response_success = silence_logger { generate(:model, 'user', '-r=/tmp/sample_project') }
36
+ response_duplicate = silence_logger { generate(:model, 'user', '-r=/tmp/sample_project') }
34
37
  assert_match_in_file(/class User < ActiveRecord::Base/m, '/tmp/sample_project/app/models/user.rb')
35
38
  assert_match "identical\e[0m app/models/user.rb", response_duplicate
36
39
  assert_match "identical\e[0m test/models/user_test.rb", response_duplicate
37
40
  end
38
41
 
39
42
  should "generate migration file versions properly" do
40
- silence_logger { @project.start(['sample_project', '--root=/tmp', '--script=none', '-t=bacon', '-d=activerecord']) }
41
- silence_logger { @model_gen.start(['user', '-r=/tmp/sample_project']) }
42
- silence_logger { @model_gen.start(['account', '-r=/tmp/sample_project']) }
43
- silence_logger { @model_gen.start(['bank', '-r=/tmp/sample_project']) }
43
+ silence_logger { generate(:project, 'sample_project', '--root=/tmp', '--script=none', '-t=bacon', '-d=activerecord') }
44
+ silence_logger { generate(:model, 'user', '-r=/tmp/sample_project') }
45
+ silence_logger { generate(:model, 'account', '-r=/tmp/sample_project') }
46
+ silence_logger { generate(:model, 'bank', '-r=/tmp/sample_project') }
44
47
  assert_file_exists('/tmp/sample_project/db/migrate/001_create_users.rb')
45
48
  assert_file_exists('/tmp/sample_project/db/migrate/002_create_accounts.rb')
46
49
  assert_file_exists('/tmp/sample_project/db/migrate/003_create_banks.rb')
@@ -50,15 +53,15 @@ class TestModelGenerator < Test::Unit::TestCase
50
53
  # ACTIVERECORD
51
54
  context "model generator using activerecord" do
52
55
  should "generate model file" do
53
- silence_logger { @project.start(['sample_project', '--root=/tmp', '--script=none', '-t=bacon', '-d=activerecord']) }
54
- silence_logger { @model_gen.start(['user', '-r=/tmp/sample_project']) }
56
+ silence_logger { generate(:project, 'sample_project', '--root=/tmp', '--script=none', '-t=bacon', '-d=activerecord') }
57
+ silence_logger { generate(:model, 'user', '-r=/tmp/sample_project') }
55
58
  assert_match_in_file(/class User < ActiveRecord::Base/m, '/tmp/sample_project/app/models/user.rb')
56
59
  end
57
60
 
58
61
  should "generate migration file with no fields" do
59
62
  current_time = stop_time_for_test.strftime("%Y%m%d%H%M%S")
60
- silence_logger { @project.start(['sample_project', '--root=/tmp', '--script=none', '-t=bacon', '-d=activerecord']) }
61
- silence_logger { @model_gen.start(['user', '-r=/tmp/sample_project']) }
63
+ silence_logger { generate(:project, 'sample_project', '--root=/tmp', '--script=none', '-t=bacon', '-d=activerecord') }
64
+ silence_logger { generate(:model, 'user', '-r=/tmp/sample_project') }
62
65
  migration_file_path = "/tmp/sample_project/db/migrate/001_create_users.rb"
63
66
  assert_match_in_file(/class CreateUsers < ActiveRecord::Migration/m, migration_file_path)
64
67
  assert_match_in_file(/create_table :users/m, migration_file_path)
@@ -67,8 +70,8 @@ class TestModelGenerator < Test::Unit::TestCase
67
70
 
68
71
  should "generate migration file with given fields" do
69
72
  current_time = stop_time_for_test.strftime("%Y%m%d%H%M%S")
70
- silence_logger { @project.start(['sample_project', '--root=/tmp', '--script=none', '-t=bacon', '-d=activerecord']) }
71
- silence_logger { @model_gen.start(['person', "name:string", "age:integer", "email:string", '-r=/tmp/sample_project']) }
73
+ silence_logger { generate(:project, 'sample_project', '--root=/tmp', '--script=none', '-t=bacon', '-d=activerecord') }
74
+ silence_logger { generate(:model, 'person', "name:string", "age:integer", "email:string", '-r=/tmp/sample_project') }
72
75
  migration_file_path = "/tmp/sample_project/db/migrate/001_create_people.rb"
73
76
  assert_match_in_file(/class CreatePeople < ActiveRecord::Migration/m, migration_file_path)
74
77
  assert_match_in_file(/create_table :people/m, migration_file_path)
@@ -82,16 +85,16 @@ class TestModelGenerator < Test::Unit::TestCase
82
85
  # COUCHREST
83
86
  context "model generator using couchrest" do
84
87
  should "generate model file with no properties" do
85
- silence_logger { @project.start(['sample_project', '--root=/tmp', '--script=none', '-t=bacon', '-d=couchrest']) }
86
- silence_logger { @model_gen.start(['user', '-r=/tmp/sample_project']) }
88
+ silence_logger { generate(:project, 'sample_project', '--root=/tmp', '--script=none', '-t=bacon', '-d=couchrest') }
89
+ silence_logger { generate(:model, 'user', '-r=/tmp/sample_project') }
87
90
  assert_match_in_file(/class User < CouchRest::ExtendedDocument/m, '/tmp/sample_project/app/models/user.rb')
88
91
  assert_match_in_file(/use_database COUCHDB/m, '/tmp/sample_project/app/models/user.rb')
89
92
  assert_match_in_file(/# property <name>[\s\n]+?end/m, '/tmp/sample_project/app/models/user.rb')
90
93
  end
91
94
 
92
95
  should "generate model file with given fields" do
93
- silence_logger { @project.start(['sample_project', '--root=/tmp', '--script=none', '-t=bacon', '-d=couchrest']) }
94
- silence_logger { @model_gen.start(['person', "name:string", "age", "email:string", '-r=/tmp/sample_project']) }
96
+ silence_logger { generate(:project, 'sample_project', '--root=/tmp', '--script=none', '-t=bacon', '-d=couchrest') }
97
+ silence_logger { generate(:model, 'person', "name:string", "age", "email:string", '-r=/tmp/sample_project') }
95
98
  assert_match_in_file(/class Person < CouchRest::ExtendedDocument/m, '/tmp/sample_project/app/models/person.rb')
96
99
  assert_match_in_file(/use_database COUCHDB/m, '/tmp/sample_project/app/models/person.rb')
97
100
  assert_match_in_file(/property :name/m, '/tmp/sample_project/app/models/person.rb')
@@ -104,14 +107,14 @@ class TestModelGenerator < Test::Unit::TestCase
104
107
  context "model generator using datamapper" do
105
108
 
106
109
  should "generate gemfile gem" do
107
- silence_logger { @project.start(['sample_project', '--root=/tmp', '--script=none', '-d=datamapper']) }
108
- silence_logger { @model_gen.start(['user', "name:string", "age:integer", "created_at:datetime", '-r=/tmp/sample_project']) }
110
+ silence_logger { generate(:project, 'sample_project', '--root=/tmp', '--script=none', '-d=datamapper') }
111
+ silence_logger { generate(:model, 'user', "name:string", "age:integer", "created_at:datetime", '-r=/tmp/sample_project') }
109
112
  assert_match_in_file(/gem 'datamapper'/m,'/tmp/sample_project/Gemfile')
110
113
  end
111
114
 
112
115
  should "generate model file with fields" do
113
- silence_logger { @project.start(['sample_project', '--root=/tmp', '--script=none', '-d=datamapper']) }
114
- silence_logger { @model_gen.start(['user', "name:string", "age:integer", "created_at:datetime", '-r=/tmp/sample_project']) }
116
+ silence_logger { generate(:project, 'sample_project', '--root=/tmp', '--script=none', '-d=datamapper') }
117
+ silence_logger { generate(:model, 'user', "name:string", "age:integer", "created_at:datetime", '-r=/tmp/sample_project') }
115
118
  assert_match_in_file(/class User\n\s+include DataMapper::Resource/m, '/tmp/sample_project/app/models/user.rb')
116
119
  assert_match_in_file(/property :name, String/m, '/tmp/sample_project/app/models/user.rb')
117
120
  assert_match_in_file(/property :age, Integer/m, '/tmp/sample_project/app/models/user.rb')
@@ -120,10 +123,10 @@ class TestModelGenerator < Test::Unit::TestCase
120
123
  end
121
124
 
122
125
  should "properly generate version numbers" do
123
- silence_logger { @project.start(['sample_project', '--root=/tmp', '--script=none', '-d=datamapper']) }
124
- silence_logger { @model_gen.start(['user', "name:string", "age:integer", "created_at:datetime", '-r=/tmp/sample_project']) }
125
- silence_logger { @model_gen.start(['person', "name:string", "age:integer", "created_at:datetime", '-r=/tmp/sample_project']) }
126
- silence_logger { @model_gen.start(['account', "name:string", "age:integer", "created_at:datetime", '-r=/tmp/sample_project']) }
126
+ silence_logger { generate(:project, 'sample_project', '--root=/tmp', '--script=none', '-d=datamapper') }
127
+ silence_logger { generate(:model, 'user', "name:string", "age:integer", "created_at:datetime", '-r=/tmp/sample_project') }
128
+ silence_logger { generate(:model, 'person', "name:string", "age:integer", "created_at:datetime", '-r=/tmp/sample_project') }
129
+ silence_logger { generate(:model, 'account', "name:string", "age:integer", "created_at:datetime", '-r=/tmp/sample_project') }
127
130
  assert_match_in_file(/class User\n\s+include DataMapper::Resource/m, '/tmp/sample_project/app/models/user.rb')
128
131
  assert_match_in_file(/migration 1, :create_users do/m, "/tmp/sample_project/db/migrate/001_create_users.rb")
129
132
  assert_match_in_file(/class Person\n\s+include DataMapper::Resource/m, '/tmp/sample_project/app/models/person.rb')
@@ -134,15 +137,15 @@ class TestModelGenerator < Test::Unit::TestCase
134
137
 
135
138
  should "generate migration with given fields" do
136
139
  current_time = stop_time_for_test.strftime("%Y%m%d%H%M%S")
137
- silence_logger { @project.start(['sample_project', '--root=/tmp', '--script=none', '-d=datamapper']) }
138
- silence_logger { @model_gen.start(['person', "name:string", "created_at:datetime", "email:string", '-r=/tmp/sample_project']) }
140
+ silence_logger { generate(:project, 'sample_project', '--root=/tmp', '--script=none', '-d=datamapper') }
141
+ silence_logger { generate(:model, 'person', "name:string", "created_at:datetime", "email:string", '-r=/tmp/sample_project') }
139
142
  assert_match_in_file(/class Person\n\s+include DataMapper::Resource/m, '/tmp/sample_project/app/models/person.rb')
140
143
  migration_file_path = "/tmp/sample_project/db/migrate/001_create_people.rb"
141
144
  assert_match_in_file(/migration 1, :create_people do/m, migration_file_path)
142
145
  assert_match_in_file(/create_table :people do/m, migration_file_path)
143
- assert_match_in_file(/column :name, String/m, migration_file_path)
144
- assert_match_in_file(/column :created_at, DateTime/m, migration_file_path)
145
- assert_match_in_file(/column :email, String/m, migration_file_path)
146
+ assert_match_in_file(/column :name, "STRING"/m, migration_file_path)
147
+ assert_match_in_file(/column :created_at, "DATETIME"/m, migration_file_path)
148
+ assert_match_in_file(/column :email, "STRING"/m, migration_file_path)
146
149
  assert_match_in_file(/drop_table :people/m, migration_file_path)
147
150
  end
148
151
  end
@@ -150,16 +153,16 @@ class TestModelGenerator < Test::Unit::TestCase
150
153
  # MONGOMAPPER
151
154
  context "model generator using mongomapper" do
152
155
  should "generate model file with no properties" do
153
- silence_logger { @project.start(['sample_project', '--root=/tmp', '--script=none', '-d=mongomapper']) }
154
- silence_logger { @model_gen.start(['person', '-r=/tmp/sample_project']) }
156
+ silence_logger { generate(:project, 'sample_project', '--root=/tmp', '--script=none', '-d=mongomapper') }
157
+ silence_logger { generate(:model, 'person', '-r=/tmp/sample_project') }
155
158
  assert_match_in_file(/class Person\n\s+include MongoMapper::Document/m, '/tmp/sample_project/app/models/person.rb')
156
159
  assert_match_in_file(/# key <name>, <type>/m, '/tmp/sample_project/app/models/person.rb')
157
160
  assert_match_in_file(/timestamps![\n\s]+end/m, '/tmp/sample_project/app/models/person.rb')
158
161
  end
159
162
 
160
163
  should "generate model file with given fields" do
161
- silence_logger { @project.start(['sample_project', '--root=/tmp', '--script=none', '-d=mongomapper']) }
162
- silence_logger { @model_gen.start(['user', "name:string", "age:integer", "email:string", '-r=/tmp/sample_project']) }
164
+ silence_logger { generate(:project, 'sample_project', '--root=/tmp', '--script=none', '-d=mongomapper') }
165
+ silence_logger { generate(:model, 'user', "name:string", "age:integer", "email:string", '-r=/tmp/sample_project') }
163
166
  assert_match_in_file(/class User\n\s+include MongoMapper::Document/m, '/tmp/sample_project/app/models/user.rb')
164
167
  assert_match_in_file(/key :name, String/m, '/tmp/sample_project/app/models/user.rb')
165
168
  assert_match_in_file(/key :age, Integer/m, '/tmp/sample_project/app/models/user.rb')
@@ -170,15 +173,15 @@ class TestModelGenerator < Test::Unit::TestCase
170
173
 
171
174
  context "model generator using mongoid" do
172
175
  should "generate model file with no properties" do
173
- silence_logger { @project.start(['sample_project', '--root=/tmp', '--script=none', '-d=mongoid']) }
174
- silence_logger { @model_gen.start(['person', '-r=/tmp/sample_project']) }
176
+ silence_logger { generate(:project, 'sample_project', '--root=/tmp', '--script=none', '-d=mongoid') }
177
+ silence_logger { generate(:model, 'person', '-r=/tmp/sample_project') }
175
178
  assert_match_in_file(/class Person\n\s+include Mongoid::Document/m, '/tmp/sample_project/app/models/person.rb')
176
179
  assert_match_in_file(/# field <name>, :type => <type>, :default => <value>/m, '/tmp/sample_project/app/models/person.rb')
177
180
  end
178
181
 
179
182
  should "generate model file with given fields" do
180
- silence_logger { @project.start(['sample_project', '--root=/tmp', '--script=none', '-d=mongoid']) }
181
- silence_logger { @model_gen.start(['user', "name:string", "age:integer", "email:string", '-r=/tmp/sample_project']) }
183
+ silence_logger { generate(:project, 'sample_project', '--root=/tmp', '--script=none', '-d=mongoid') }
184
+ silence_logger { generate(:model, 'user', "name:string", "age:integer", "email:string", '-r=/tmp/sample_project') }
182
185
  assert_match_in_file(/class User\n\s+include Mongoid::Document/m, '/tmp/sample_project/app/models/user.rb')
183
186
  assert_match_in_file(/field :name, :type => String/m, '/tmp/sample_project/app/models/user.rb')
184
187
  assert_match_in_file(/field :age, :type => Integer/m, '/tmp/sample_project/app/models/user.rb')
@@ -189,15 +192,15 @@ class TestModelGenerator < Test::Unit::TestCase
189
192
  # SEQUEL
190
193
  context "model generator using sequel" do
191
194
  should "generate model file with given properties" do
192
- silence_logger { @project.start(['sample_project', '--root=/tmp', '--script=none', '-d=sequel']) }
193
- silence_logger { @model_gen.start(['user', "name:string", "age:integer", "created:datetime", '-r=/tmp/sample_project']) }
195
+ silence_logger { generate(:project, 'sample_project', '--root=/tmp', '--script=none', '-d=sequel') }
196
+ silence_logger { generate(:model, 'user', "name:string", "age:integer", "created:datetime", '-r=/tmp/sample_project') }
194
197
  assert_match_in_file(/class User < Sequel::Model/m, '/tmp/sample_project/app/models/user.rb')
195
198
  end
196
199
 
197
200
  should "generate migration file with given properties" do
198
201
  current_time = stop_time_for_test.strftime("%Y%m%d%H%M%S")
199
- silence_logger { @project.start(['sample_project', '--root=/tmp', '--script=none', '-d=sequel']) }
200
- silence_logger { @model_gen.start(['person', "name:string", "age:integer", "created:datetime", '-r=/tmp/sample_project']) }
202
+ silence_logger { generate(:project, 'sample_project', '--root=/tmp', '--script=none', '-d=sequel') }
203
+ silence_logger { generate(:model, 'person', "name:string", "age:integer", "created:datetime", '-r=/tmp/sample_project') }
201
204
  migration_file_path = "/tmp/sample_project/db/migrate/001_create_people.rb"
202
205
  assert_match_in_file(/class Person < Sequel::Model/m, '/tmp/sample_project/app/models/person.rb')
203
206
  assert_match_in_file(/class CreatePeople < Sequel::Migration/m, migration_file_path)
@@ -212,77 +215,75 @@ class TestModelGenerator < Test::Unit::TestCase
212
215
  context "model generator testing files" do
213
216
  # BACON
214
217
  should "generate test file for bacon" do
215
- silence_logger { @project.start(['sample_project', '--root=/tmp', '--script=none', '-t=bacon', '-d=activerecord']) }
216
- silence_logger { @model_gen.start(['User', '-r=/tmp/sample_project']) }
217
- assert_match_in_file(/describe "User Model"/m, '/tmp/sample_project/test/models/user_test.rb')
218
- assert_match_in_file(/@user = User.new/m, '/tmp/sample_project/test/models/user_test.rb')
219
- assert_match_in_file(/@user\.should\.not\.be\.nil/m, '/tmp/sample_project/test/models/user_test.rb')
218
+ silence_logger { generate(:project, 'sample_project', '--root=/tmp', '--script=none', '-t=bacon', '-d=activerecord') }
219
+ silence_logger { generate(:model, 'SomeUser', '-r=/tmp/sample_project') }
220
+ assert_match_in_file(/describe "SomeUser Model"/m, '/tmp/sample_project/test/models/some_user_test.rb')
221
+ assert_match_in_file(/@some_user = SomeUser.new/m, '/tmp/sample_project/test/models/some_user_test.rb')
222
+ assert_match_in_file(/@some_user\.should\.not\.be\.nil/m, '/tmp/sample_project/test/models/some_user_test.rb')
220
223
  end
221
224
 
222
225
  # RIOT
223
226
  should "generate test file for riot" do
224
- silence_logger { @project.start(['sample_project', '--root=/tmp', '--script=none', '-t=riot', '-d=activerecord']) }
225
- silence_logger { @model_gen.start(['User', '-r=/tmp/sample_project']) }
226
- assert_match_in_file(/context "User Model" do/m, '/tmp/sample_project/test/models/user_test.rb')
227
- assert_match_in_file(/@user = User.new/m, '/tmp/sample_project/test/models/user_test.rb')
228
- assert_match_in_file(/asserts\("that record is not nil"\) \{ \!@user.nil\? \}/m, '/tmp/sample_project/test/models/user_test.rb')
227
+ silence_logger { generate(:project, 'sample_project', '--root=/tmp', '--script=none', '-t=riot', '-d=activerecord') }
228
+ silence_logger { generate(:model, 'SomeUser', '-r=/tmp/sample_project') }
229
+ assert_match_in_file(/context "SomeUser Model" do/m, '/tmp/sample_project/test/models/some_user_test.rb')
230
+ assert_match_in_file(/@some_user = SomeUser.new/m, '/tmp/sample_project/test/models/some_user_test.rb')
231
+ assert_match_in_file(/asserts\("that record is not nil"\) \{ \!@some_user.nil\? \}/m, '/tmp/sample_project/test/models/some_user_test.rb')
229
232
  end
230
233
 
231
234
  # RSPEC
232
235
  should "generate test file for rspec" do
233
- silence_logger { @project.start(['sample_project', '--root=/tmp', '--script=none', '-t=rspec', '-d=activerecord']) }
234
- silence_logger { @model_gen.start(['User', '-r=/tmp/sample_project']) }
235
- assert_match_in_file(/describe "User Model"/m, '/tmp/sample_project/spec/models/user_spec.rb')
236
- assert_match_in_file(/@user = User.new/m, '/tmp/sample_project/spec/models/user_spec.rb')
237
- assert_match_in_file(/@user\.should_not be_nil/m, '/tmp/sample_project/spec/models/user_spec.rb')
236
+ silence_logger { generate(:project, 'sample_project', '--root=/tmp', '--script=none', '-t=rspec', '-d=activerecord') }
237
+ silence_logger { generate(:model, 'SomeUser', '-r=/tmp/sample_project') }
238
+ assert_match_in_file(/describe "SomeUser Model"/m, '/tmp/sample_project/spec/models/some_user_spec.rb')
239
+ assert_match_in_file(/@some_user = SomeUser.new/m, '/tmp/sample_project/spec/models/some_user_spec.rb')
240
+ assert_match_in_file(/@some_user\.should_not be_nil/m, '/tmp/sample_project/spec/models/some_user_spec.rb')
238
241
  end
239
242
 
240
243
  # SHOULDA
241
244
  should "generate test file for shoulda" do
242
- silence_logger { @project.start(['sample_project', '--root=/tmp', '--script=none', '-t=shoulda', '-d=activerecord']) }
243
- silence_logger { @model_gen.start(['Person', '-r=/tmp/sample_project']) }
244
- assert_match_in_file(/class PersonControllerTest < Test::Unit::TestCase/m, '/tmp/sample_project/test/models/person_test.rb')
245
- assert_match_in_file(/context "Person Model"/m, '/tmp/sample_project/test/models/person_test.rb')
246
- assert_match_in_file(/@person = Person.new/m, '/tmp/sample_project/test/models/person_test.rb')
247
- assert_match_in_file(/assert_not_nil @person/m, '/tmp/sample_project/test/models/person_test.rb')
245
+ silence_logger { generate(:project, 'sample_project', '--root=/tmp', '--script=none', '-t=shoulda', '-d=activerecord') }
246
+ silence_logger { generate(:model, 'SomePerson', '-r=/tmp/sample_project') }
247
+ assert_match_in_file(/class SomePersonControllerTest < Test::Unit::TestCase/m, '/tmp/sample_project/test/models/some_person_test.rb')
248
+ assert_match_in_file(/context "SomePerson Model"/m, '/tmp/sample_project/test/models/some_person_test.rb')
249
+ assert_match_in_file(/@some_person = SomePerson.new/m, '/tmp/sample_project/test/models/some_person_test.rb')
250
+ assert_match_in_file(/assert_not_nil @some_person/m, '/tmp/sample_project/test/models/some_person_test.rb')
248
251
  end
249
252
 
250
253
  # TESTSPEC
251
254
  should "generate test file for testspec" do
252
- silence_logger { @project.start(['sample_project', '--root=/tmp', '--script=none', '-t=testspec', '-d=activerecord']) }
253
- silence_logger { @model_gen.start(['User', '-r=/tmp/sample_project']) }
254
- assert_match_in_file(/context "User Model"/m, '/tmp/sample_project/test/models/user_test.rb')
255
- assert_match_in_file(/@user = User.new/m, '/tmp/sample_project/test/models/user_test.rb')
256
- assert_match_in_file(/@user\.should\.not\.be\.nil/m, '/tmp/sample_project/test/models/user_test.rb')
255
+ silence_logger { generate(:project, 'sample_project', '--root=/tmp', '--script=none', '-t=testspec', '-d=activerecord') }
256
+ silence_logger { generate(:model, 'SomeUser', '-r=/tmp/sample_project') }
257
+ assert_match_in_file(/context "SomeUser Model"/m, '/tmp/sample_project/test/models/some_user_test.rb')
258
+ assert_match_in_file(/@some_user = SomeUser.new/m, '/tmp/sample_project/test/models/some_user_test.rb')
259
+ assert_match_in_file(/@some_user\.should\.not\.be\.nil/m, '/tmp/sample_project/test/models/some_user_test.rb')
257
260
  end
258
261
  end
259
262
 
260
263
  context "the model destroy option" do
261
264
 
262
265
  should "destroy the model file" do
263
- silence_logger { @project.start(['sample_project', '--root=/tmp', '--script=none', '-t=bacon', '-d=activerecord']) }
264
- silence_logger { @model_gen.start(['User', '-r=/tmp/sample_project']) }
265
- silence_logger { @model_gen.start(['User', '-r=/tmp/sample_project', '-d']) }
266
+ silence_logger { generate(:project, 'sample_project', '--root=/tmp', '--script=none', '-t=bacon', '-d=activerecord') }
267
+ silence_logger { generate(:model, 'User', '-r=/tmp/sample_project') }
268
+ silence_logger { generate(:model, 'User', '-r=/tmp/sample_project', '-d') }
266
269
  assert_no_file_exists('/tmp/sample_project/app/models/user.rb')
267
270
  assert_no_file_exists('/tmp/sample_project/test/models/user_test.rb')
268
271
  assert_no_file_exists('/tmp/sample_project/db/migrate/001_create_users.rb')
269
272
  end
270
273
 
271
274
  should "destroy the model test file with rspec" do
272
- silence_logger { @project.start(['sample_project', '--root=/tmp', '--script=none', '-t=rspec', '-d=activerecord']) }
273
- silence_logger { @model_gen.start(['User', '-r=/tmp/sample_project']) }
274
- silence_logger { @model_gen.start(['User', '-r=/tmp/sample_project', '-d']) }
275
+ silence_logger { generate(:project, 'sample_project', '--root=/tmp', '--script=none', '-t=rspec', '-d=activerecord') }
276
+ silence_logger { generate(:model, 'User', '-r=/tmp/sample_project') }
277
+ silence_logger { generate(:model, 'User', '-r=/tmp/sample_project', '-d') }
275
278
  assert_no_file_exists('/tmp/sample_project/spec/models/user_spec.rb')
276
279
  end
277
280
 
278
281
  should "destroy the model migration" do
279
- silence_logger { @project.start(['sample_project', '--root=/tmp', '--script=none', '-t=rspec', '-d=activerecord']) }
280
- silence_logger { @model_gen.start(['Person', '-r=/tmp/sample_project']) }
281
- silence_logger { @model_gen.start(['User', '-r=/tmp/sample_project']) }
282
- silence_logger { @model_gen.start(['User', '-r=/tmp/sample_project', '-d']) }
282
+ silence_logger { generate(:project, 'sample_project', '--root=/tmp', '--script=none', '-t=rspec', '-d=activerecord') }
283
+ silence_logger { generate(:model, 'Person', '-r=/tmp/sample_project') }
284
+ silence_logger { generate(:model, 'User', '-r=/tmp/sample_project') }
285
+ silence_logger { generate(:model, 'User', '-r=/tmp/sample_project', '-d') }
283
286
  assert_no_file_exists('/tmp/sample_project/db/migrate/002_create_users.rb')
284
287
  end
285
-
286
288
  end
287
-
288
- end
289
+ end