padrino-gen 0.7.9 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +42 -13
- data/Rakefile +7 -6
- data/VERSION +1 -1
- data/lib/padrino-gen/generators/actions.rb +25 -3
- data/lib/padrino-gen/generators/app/{app/app.rb.tt → app.rb.tt} +0 -0
- data/lib/padrino-gen/generators/app/{app → controllers}/.empty_directory +0 -0
- data/lib/padrino-gen/generators/app/{app/controllers → helpers}/.empty_directory +0 -0
- data/lib/padrino-gen/generators/app/{app/helpers → views}/.empty_directory +0 -0
- data/lib/padrino-gen/generators/app.rb +28 -36
- data/lib/padrino-gen/generators/components/actions.rb +4 -22
- data/lib/padrino-gen/generators/components/mocks/rr_gen.rb +8 -4
- data/lib/padrino-gen/generators/controller.rb +7 -4
- data/lib/padrino-gen/generators/mailer.rb +5 -2
- data/lib/padrino-gen/generators/model.rb +1 -1
- data/lib/padrino-gen/generators/{app → project}/.gitignore +0 -0
- data/lib/padrino-gen/generators/{app/app/views → project/app}/.empty_directory +0 -0
- data/lib/padrino-gen/generators/project/app/app.rb.tt +37 -0
- data/lib/padrino-gen/generators/{app/config/initializers → project/app/controllers}/.empty_directory +0 -0
- data/lib/padrino-gen/generators/{app/public/images → project/app/helpers}/.empty_directory +0 -0
- data/lib/padrino-gen/generators/{app/public/javascripts → project/app/views}/.empty_directory +0 -0
- data/lib/padrino-gen/generators/{app → project}/config/apps.rb.tt +0 -0
- data/lib/padrino-gen/generators/{app → project}/config/boot.rb +1 -1
- data/lib/padrino-gen/generators/{app/public/stylesheets → project/config/initializers}/.empty_directory +0 -0
- data/lib/padrino-gen/generators/{app → project}/config/initializers/example.rb +0 -0
- data/lib/padrino-gen/generators/{app → project}/config.ru +0 -0
- data/lib/padrino-gen/generators/{app/tmp → project/public/images}/.empty_directory +0 -0
- data/lib/padrino-gen/generators/project/public/javascripts/.empty_directory +0 -0
- data/lib/padrino-gen/generators/project/public/stylesheets/.empty_directory +0 -0
- data/lib/padrino-gen/generators/project/tmp/.empty_directory +0 -0
- data/lib/padrino-gen/generators/project.rb +64 -0
- data/lib/padrino-gen/generators/templates/Gemfile.tt +0 -1
- data/lib/padrino-gen/generators.rb +7 -3
- data/lib/padrino-gen/padrino-tasks/activerecord.rb +1 -1
- data/padrino-gen.gemspec +31 -24
- data/test/helper.rb +7 -7
- data/test/test_app_generator.rb +35 -199
- data/test/test_cli.rb +25 -0
- data/test/test_controller_generator.rb +45 -45
- data/test/test_generator.rb +0 -3
- data/test/test_mailer_generator.rb +25 -26
- data/test/test_migration_generator.rb +61 -62
- data/test/test_model_generator.rb +119 -114
- data/test/test_project_generator.rb +222 -0
- metadata +26 -19
data/padrino-gen.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{padrino-gen}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.8.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Padrino Team", "Nathan Esquenazi", "Davide D'Agostino", "Arthur Chiu"]
|
12
|
-
s.date = %q{2010-02-
|
12
|
+
s.date = %q{2010-02-14}
|
13
13
|
s.default_executable = %q{padrino-gen}
|
14
14
|
s.description = %q{Generators for easily creating and building padrino applications from the console}
|
15
15
|
s.email = %q{padrinorb@gmail.com}
|
@@ -29,21 +29,10 @@ Gem::Specification.new do |s|
|
|
29
29
|
"lib/padrino-gen/generators.rb",
|
30
30
|
"lib/padrino-gen/generators/actions.rb",
|
31
31
|
"lib/padrino-gen/generators/app.rb",
|
32
|
-
"lib/padrino-gen/generators/app
|
33
|
-
"lib/padrino-gen/generators/app/
|
34
|
-
"lib/padrino-gen/generators/app/
|
35
|
-
"lib/padrino-gen/generators/app/
|
36
|
-
"lib/padrino-gen/generators/app/app/helpers/.empty_directory",
|
37
|
-
"lib/padrino-gen/generators/app/app/views/.empty_directory",
|
38
|
-
"lib/padrino-gen/generators/app/config.ru",
|
39
|
-
"lib/padrino-gen/generators/app/config/apps.rb.tt",
|
40
|
-
"lib/padrino-gen/generators/app/config/boot.rb",
|
41
|
-
"lib/padrino-gen/generators/app/config/initializers/.empty_directory",
|
42
|
-
"lib/padrino-gen/generators/app/config/initializers/example.rb",
|
43
|
-
"lib/padrino-gen/generators/app/public/images/.empty_directory",
|
44
|
-
"lib/padrino-gen/generators/app/public/javascripts/.empty_directory",
|
45
|
-
"lib/padrino-gen/generators/app/public/stylesheets/.empty_directory",
|
46
|
-
"lib/padrino-gen/generators/app/tmp/.empty_directory",
|
32
|
+
"lib/padrino-gen/generators/app/app.rb.tt",
|
33
|
+
"lib/padrino-gen/generators/app/controllers/.empty_directory",
|
34
|
+
"lib/padrino-gen/generators/app/helpers/.empty_directory",
|
35
|
+
"lib/padrino-gen/generators/app/views/.empty_directory",
|
47
36
|
"lib/padrino-gen/generators/components/actions.rb",
|
48
37
|
"lib/padrino-gen/generators/components/mocks/mocha_gen.rb",
|
49
38
|
"lib/padrino-gen/generators/components/mocks/rr_gen.rb",
|
@@ -66,6 +55,22 @@ Gem::Specification.new do |s|
|
|
66
55
|
"lib/padrino-gen/generators/mailer.rb",
|
67
56
|
"lib/padrino-gen/generators/migration.rb",
|
68
57
|
"lib/padrino-gen/generators/model.rb",
|
58
|
+
"lib/padrino-gen/generators/project.rb",
|
59
|
+
"lib/padrino-gen/generators/project/.gitignore",
|
60
|
+
"lib/padrino-gen/generators/project/app/.empty_directory",
|
61
|
+
"lib/padrino-gen/generators/project/app/app.rb.tt",
|
62
|
+
"lib/padrino-gen/generators/project/app/controllers/.empty_directory",
|
63
|
+
"lib/padrino-gen/generators/project/app/helpers/.empty_directory",
|
64
|
+
"lib/padrino-gen/generators/project/app/views/.empty_directory",
|
65
|
+
"lib/padrino-gen/generators/project/config.ru",
|
66
|
+
"lib/padrino-gen/generators/project/config/apps.rb.tt",
|
67
|
+
"lib/padrino-gen/generators/project/config/boot.rb",
|
68
|
+
"lib/padrino-gen/generators/project/config/initializers/.empty_directory",
|
69
|
+
"lib/padrino-gen/generators/project/config/initializers/example.rb",
|
70
|
+
"lib/padrino-gen/generators/project/public/images/.empty_directory",
|
71
|
+
"lib/padrino-gen/generators/project/public/javascripts/.empty_directory",
|
72
|
+
"lib/padrino-gen/generators/project/public/stylesheets/.empty_directory",
|
73
|
+
"lib/padrino-gen/generators/project/tmp/.empty_directory",
|
69
74
|
"lib/padrino-gen/generators/templates/Gemfile.tt",
|
70
75
|
"lib/padrino-gen/generators/templates/controller.rb.tt",
|
71
76
|
"lib/padrino-gen/generators/templates/helper.rb.tt",
|
@@ -81,11 +86,13 @@ Gem::Specification.new do |s|
|
|
81
86
|
"padrino-gen.gemspec",
|
82
87
|
"test/helper.rb",
|
83
88
|
"test/test_app_generator.rb",
|
89
|
+
"test/test_cli.rb",
|
84
90
|
"test/test_controller_generator.rb",
|
85
91
|
"test/test_generator.rb",
|
86
92
|
"test/test_mailer_generator.rb",
|
87
93
|
"test/test_migration_generator.rb",
|
88
|
-
"test/test_model_generator.rb"
|
94
|
+
"test/test_model_generator.rb",
|
95
|
+
"test/test_project_generator.rb"
|
89
96
|
]
|
90
97
|
s.homepage = %q{http://github.com/padrino/padrino-framework/tree/master/padrino-gen}
|
91
98
|
s.rdoc_options = ["--charset=UTF-8"]
|
@@ -100,22 +107,22 @@ Gem::Specification.new do |s|
|
|
100
107
|
|
101
108
|
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
102
109
|
s.add_runtime_dependency(%q<sinatra>, [">= 0.9.2"])
|
103
|
-
s.add_runtime_dependency(%q<padrino-core>, ["= 0.
|
110
|
+
s.add_runtime_dependency(%q<padrino-core>, ["= 0.8.0"])
|
104
111
|
s.add_runtime_dependency(%q<thor>, [">= 0.13.0"])
|
105
112
|
s.add_runtime_dependency(%q<bundler>, [">= 0.9.3"])
|
106
113
|
s.add_development_dependency(%q<haml>, [">= 2.2.1"])
|
107
|
-
s.add_development_dependency(%q<shoulda>, [">=
|
114
|
+
s.add_development_dependency(%q<shoulda>, [">= 2.10.3"])
|
108
115
|
s.add_development_dependency(%q<mocha>, [">= 0.9.7"])
|
109
116
|
s.add_development_dependency(%q<rack-test>, [">= 0.5.0"])
|
110
117
|
s.add_development_dependency(%q<webrat>, [">= 0.5.1"])
|
111
118
|
s.add_development_dependency(%q<fakeweb>, [">= 1.2.3"])
|
112
119
|
else
|
113
120
|
s.add_dependency(%q<sinatra>, [">= 0.9.2"])
|
114
|
-
s.add_dependency(%q<padrino-core>, ["= 0.
|
121
|
+
s.add_dependency(%q<padrino-core>, ["= 0.8.0"])
|
115
122
|
s.add_dependency(%q<thor>, [">= 0.13.0"])
|
116
123
|
s.add_dependency(%q<bundler>, [">= 0.9.3"])
|
117
124
|
s.add_dependency(%q<haml>, [">= 2.2.1"])
|
118
|
-
s.add_dependency(%q<shoulda>, [">=
|
125
|
+
s.add_dependency(%q<shoulda>, [">= 2.10.3"])
|
119
126
|
s.add_dependency(%q<mocha>, [">= 0.9.7"])
|
120
127
|
s.add_dependency(%q<rack-test>, [">= 0.5.0"])
|
121
128
|
s.add_dependency(%q<webrat>, [">= 0.5.1"])
|
@@ -123,11 +130,11 @@ Gem::Specification.new do |s|
|
|
123
130
|
end
|
124
131
|
else
|
125
132
|
s.add_dependency(%q<sinatra>, [">= 0.9.2"])
|
126
|
-
s.add_dependency(%q<padrino-core>, ["= 0.
|
133
|
+
s.add_dependency(%q<padrino-core>, ["= 0.8.0"])
|
127
134
|
s.add_dependency(%q<thor>, [">= 0.13.0"])
|
128
135
|
s.add_dependency(%q<bundler>, [">= 0.9.3"])
|
129
136
|
s.add_dependency(%q<haml>, [">= 2.2.1"])
|
130
|
-
s.add_dependency(%q<shoulda>, [">=
|
137
|
+
s.add_dependency(%q<shoulda>, [">= 2.10.3"])
|
131
138
|
s.add_dependency(%q<mocha>, [">= 0.9.7"])
|
132
139
|
s.add_dependency(%q<rack-test>, [">= 0.5.0"])
|
133
140
|
s.add_dependency(%q<webrat>, [">= 0.5.1"])
|
data/test/helper.rb
CHANGED
@@ -15,7 +15,8 @@ end
|
|
15
15
|
|
16
16
|
require 'padrino-gen'
|
17
17
|
|
18
|
-
Padrino::Generators
|
18
|
+
Padrino::Generators.setup!
|
19
|
+
Padrino::Generators.lockup!
|
19
20
|
|
20
21
|
class Test::Unit::TestCase
|
21
22
|
include Rack::Test::Methods
|
@@ -50,28 +51,27 @@ class Test::Unit::TestCase
|
|
50
51
|
raise "Please specify a block!" if html.blank?
|
51
52
|
assert matcher.matches?(html), matcher.failure_message
|
52
53
|
end
|
53
|
-
|
54
|
+
|
54
55
|
# assert_file_exists('/tmp/app')
|
55
56
|
def assert_file_exists(file_path)
|
56
57
|
assert File.exist?(file_path), "File at path '#{file_path}' does not exist!"
|
57
58
|
end
|
58
|
-
alias assert_dir_exists assert_file_exists
|
59
|
-
|
59
|
+
alias :assert_dir_exists :assert_file_exists
|
60
|
+
|
60
61
|
# assert_no_file_exists('/tmp/app')
|
61
62
|
def assert_no_file_exists(file_path)
|
62
63
|
assert !File.exist?(file_path), "File should not exist at path '#{file_path}' but was found!"
|
63
64
|
end
|
64
|
-
alias assert_no_dir_exists assert_no_file_exists
|
65
|
+
alias :assert_no_dir_exists :assert_no_file_exists
|
65
66
|
|
66
67
|
# Asserts that a file matches the pattern
|
67
68
|
def assert_match_in_file(pattern, file)
|
68
69
|
File.exist?(file) ? assert_match(pattern, File.read(file)) : assert_file_exists(file)
|
69
70
|
end
|
70
|
-
|
71
|
+
|
71
72
|
def assert_no_match_in_file(pattern, file)
|
72
73
|
File.exists?(file) ? !assert_match(pattern, File.read(file)) : assert_file_exists(file)
|
73
74
|
end
|
74
|
-
|
75
75
|
end
|
76
76
|
|
77
77
|
class Object
|
data/test/test_app_generator.rb
CHANGED
@@ -4,215 +4,51 @@ require 'fakeweb'
|
|
4
4
|
|
5
5
|
class TestAppGenerator < Test::Unit::TestCase
|
6
6
|
def setup
|
7
|
-
Padrino::Generators.lockup!
|
8
7
|
FakeWeb.allow_net_connect = false
|
9
|
-
`rm -rf /tmp/
|
10
|
-
@
|
8
|
+
`rm -rf /tmp/sample_project`
|
9
|
+
@project = Padrino::Generators::Project.dup
|
10
|
+
@app = Padrino::Generators::App.dup
|
11
|
+
@cont_gen = Padrino::Generators::Controller.dup
|
12
|
+
@mail_gen = Padrino::Generators::Mailer.dup
|
11
13
|
end
|
12
14
|
|
13
|
-
context 'the
|
14
|
-
should "
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
assert_file_exists('/tmp/sample_app/config/boot.rb')
|
19
|
-
assert_dir_exists('/tmp/sample_app/app/models')
|
20
|
-
assert_file_exists('/tmp/sample_app/test/test_config.rb')
|
15
|
+
context 'the app generator' do
|
16
|
+
should "fail outside app root" do
|
17
|
+
output = silence_logger { @app.start(['demo', '-r=/tmp']) }
|
18
|
+
assert_match(/not at the root/, output)
|
19
|
+
assert_no_file_exists('/tmp/demo')
|
21
20
|
end
|
22
21
|
|
23
|
-
should "
|
24
|
-
silence_logger { @
|
25
|
-
|
22
|
+
should "create correctly a new padrino application" do
|
23
|
+
assert_nothing_raised { silence_logger { @project.start(['sample_project', '--root=/tmp']) } }
|
24
|
+
assert_nothing_raised { silence_logger { @app.start(['demo', '--root=/tmp/sample_project']) } }
|
25
|
+
assert_file_exists('/tmp/sample_project')
|
26
|
+
assert_file_exists('/tmp/sample_project/demo')
|
27
|
+
assert_file_exists('/tmp/sample_project/demo/app.rb')
|
28
|
+
assert_file_exists('/tmp/sample_project/demo/controllers')
|
29
|
+
assert_file_exists('/tmp/sample_project/demo/helpers')
|
30
|
+
assert_file_exists('/tmp/sample_project/demo/views')
|
31
|
+
assert_match_in_file 'Padrino.mount("Demo").to("/demo")', '/tmp/sample_project/config/apps.rb'
|
32
|
+
assert_match_in_file 'class Demo < Padrino::Application', '/tmp/sample_project/demo/app.rb'
|
26
33
|
end
|
27
34
|
|
28
|
-
should "
|
29
|
-
silence_logger { @
|
30
|
-
|
35
|
+
should "correctly create a new controller inside a padrino application" do
|
36
|
+
silence_logger { @project.start(['sample_project', '--root=/tmp']) }
|
37
|
+
silence_logger { @app.start(['demo', '--root=/tmp/sample_project']) }
|
38
|
+
silence_logger { @cont_gen.start(['demo_items', '-r=/tmp/sample_project', '-a=demo']) }
|
39
|
+
assert_match_in_file(/SampleProject.controllers :demo_items do/m, '/tmp/sample_project/demo/controllers/demo_items.rb')
|
40
|
+
assert_match_in_file(/SampleProject.helpers do/m, '/tmp/sample_project/demo/helpers/demo_items_helper.rb')
|
41
|
+
assert_file_exists('/tmp/sample_project/demo/views/demo_items')
|
31
42
|
end
|
32
43
|
|
33
|
-
should "
|
34
|
-
silence_logger { @
|
35
|
-
|
36
|
-
|
44
|
+
should "correctly create a new mailer inside a padrino application" do
|
45
|
+
silence_logger { @project.start(['sample_project', '--root=/tmp', '--script=none', '-t=bacon']) }
|
46
|
+
silence_logger { @app.start(['demo', '--root=/tmp/sample_project']) }
|
47
|
+
silence_logger { @mail_gen.start(['demo', '-r=/tmp/sample_project', '-a=demo']) }
|
48
|
+
assert_match_in_file(/class DemoMailer < Padrino::Mailer::Base/m, '/tmp/sample_project/demo/mailers/demo_mailer.rb')
|
49
|
+
assert_match_in_file(/Padrino::Mailer::Base.smtp_settings/m, '/tmp/sample_project/config/initializers/mailer.rb')
|
50
|
+
assert_file_exists('/tmp/sample_project/demo/views/demo_mailer')
|
37
51
|
end
|
38
52
|
|
39
|
-
should "create components file containing options chosen with defaults" do
|
40
|
-
silence_logger { @app.start(['sample_app', '--root=/tmp']) }
|
41
|
-
components_chosen = YAML.load_file('/tmp/sample_app/.components')
|
42
|
-
assert_equal 'datamapper', components_chosen[:orm]
|
43
|
-
assert_equal 'bacon', components_chosen[:test]
|
44
|
-
assert_equal 'mocha', components_chosen[:mock]
|
45
|
-
assert_equal 'jquery', components_chosen[:script]
|
46
|
-
assert_equal 'erb', components_chosen[:renderer]
|
47
|
-
end
|
48
|
-
|
49
|
-
should "create components file containing options chosen" do
|
50
|
-
component_options = ['--orm=datamapper', '--test=riot', '--mock=mocha', '--script=prototype', '--renderer=erb']
|
51
|
-
silence_logger { @app.start(['sample_app', '--root=/tmp', *component_options]) }
|
52
|
-
components_chosen = YAML.load_file('/tmp/sample_app/.components')
|
53
|
-
assert_equal 'datamapper', components_chosen[:orm]
|
54
|
-
assert_equal 'riot', components_chosen[:test]
|
55
|
-
assert_equal 'mocha', components_chosen[:mock]
|
56
|
-
assert_equal 'prototype', components_chosen[:script]
|
57
|
-
assert_equal 'erb', components_chosen[:renderer]
|
58
|
-
end
|
59
|
-
|
60
|
-
should "output to log components being applied" do
|
61
|
-
component_options = ['--orm=datamapper', '--test=riot', '--mock=mocha', '--script=prototype', '--renderer=erb']
|
62
|
-
buffer = silence_logger { @app.start(['sample_app', '--root=/tmp', *component_options]) }
|
63
|
-
assert_match /Applying.*?datamapper.*?orm/, buffer
|
64
|
-
assert_match /Applying.*?riot.*?test/, buffer
|
65
|
-
assert_match /Applying.*?mocha.*?mock/, buffer
|
66
|
-
assert_match /Applying.*?prototype.*?script/, buffer
|
67
|
-
assert_match /Applying.*?erb.*?renderer/, buffer
|
68
|
-
end
|
69
|
-
|
70
|
-
should "output gem files for base app" do
|
71
|
-
silence_logger { @app.start(['sample_app', '--root=/tmp', '--script=none']) }
|
72
|
-
assert_match_in_file(/gem 'sinatra'/, '/tmp/sample_app/Gemfile')
|
73
|
-
assert_match_in_file(/gem 'padrino'/, '/tmp/sample_app/Gemfile')
|
74
|
-
assert_match_in_file(/gem 'rack-flash'/, '/tmp/sample_app/Gemfile')
|
75
|
-
assert_match_in_file(/gem 'rack-test'/, '/tmp/sample_app/Gemfile')
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
context "a generator for mock component" do
|
80
|
-
should "properly generate for rr" do
|
81
|
-
buffer = silence_logger { @app.start(['sample_app', '--root=/tmp', '--mock=rr', '--script=none']) }
|
82
|
-
assert_match /Applying.*?rr.*?mock/, buffer
|
83
|
-
assert_match_in_file(/gem 'rr'/, '/tmp/sample_app/Gemfile')
|
84
|
-
assert_match_in_file(/include RR::Adapters::RRMethods/m, '/tmp/sample_app/test/test_config.rb')
|
85
|
-
end
|
86
|
-
|
87
|
-
should "properly generate default for mocha" do
|
88
|
-
buffer = silence_logger { @app.start(['sample_app', '--root=/tmp', '--mock=mocha', '--script=none']) }
|
89
|
-
assert_match /Applying.*?mocha.*?mock/, buffer
|
90
|
-
assert_match_in_file(/gem 'mocha'/, '/tmp/sample_app/Gemfile')
|
91
|
-
assert_match_in_file(/include Mocha::API/m, '/tmp/sample_app/test/test_config.rb')
|
92
|
-
end
|
93
|
-
end
|
94
|
-
|
95
|
-
context "the generator for orm components" do
|
96
|
-
should "properly generate for sequel" do
|
97
|
-
@app.instance_eval("undef setup_orm if respond_to?('setup_orm')")
|
98
|
-
buffer = silence_logger { @app.start(['sample_app', '--root=/tmp', '--orm=sequel', '--script=none']) }
|
99
|
-
assert_match /Applying.*?sequel.*?orm/, buffer
|
100
|
-
assert_match_in_file(/gem 'sequel'/, '/tmp/sample_app/Gemfile')
|
101
|
-
assert_match_in_file(/Sequel.connect/, '/tmp/sample_app/config/database.rb')
|
102
|
-
assert_dir_exists('/tmp/sample_app/app/models')
|
103
|
-
end
|
104
|
-
|
105
|
-
should "properly generate for activerecord" do
|
106
|
-
buffer = silence_logger { @app.start(['sample_app', '--root=/tmp', '--orm=activerecord', '--script=none']) }
|
107
|
-
assert_match /Applying.*?activerecord.*?orm/, buffer
|
108
|
-
assert_match_in_file(/gem 'activerecord', :require => "active_record"/, '/tmp/sample_app/Gemfile')
|
109
|
-
assert_match_in_file(/ActiveRecord::Base.establish_connection/, '/tmp/sample_app/config/database.rb')
|
110
|
-
assert_dir_exists('/tmp/sample_app/app/models')
|
111
|
-
end
|
112
|
-
|
113
|
-
should "properly generate default for datamapper" do
|
114
|
-
buffer = silence_logger { @app.start(['sample_app', '--root=/tmp', '--orm=datamapper', '--script=none']) }
|
115
|
-
assert_match /Applying.*?datamapper.*?orm/, buffer
|
116
|
-
assert_match_in_file(/gem 'dm-core'/, '/tmp/sample_app/Gemfile')
|
117
|
-
assert_match_in_file(/DataMapper.setup/, '/tmp/sample_app/config/database.rb')
|
118
|
-
assert_dir_exists('/tmp/sample_app/app/models')
|
119
|
-
end
|
120
|
-
|
121
|
-
should "properly generate for mongomapper" do
|
122
|
-
buffer = silence_logger { @app.start(['sample_app', '--root=/tmp', '--orm=mongomapper', '--script=none']) }
|
123
|
-
assert_match /Applying.*?mongomapper.*?orm/, buffer
|
124
|
-
assert_match_in_file(/gem 'mongo_mapper'/, '/tmp/sample_app/Gemfile')
|
125
|
-
assert_match_in_file(/MongoMapper.database/, '/tmp/sample_app/config/database.rb')
|
126
|
-
assert_dir_exists('/tmp/sample_app/app/models')
|
127
|
-
end
|
128
|
-
|
129
|
-
should "properly generate for couchrest" do
|
130
|
-
buffer = silence_logger { @app.start(['sample_app', '--root=/tmp', '--orm=couchrest', '--script=none']) }
|
131
|
-
assert_match /Applying.*?couchrest.*?orm/, buffer
|
132
|
-
assert_match_in_file(/gem 'couchrest'/, '/tmp/sample_app/Gemfile')
|
133
|
-
assert_match_in_file(/CouchRest.database!/, '/tmp/sample_app/config/database.rb')
|
134
|
-
assert_dir_exists('/tmp/sample_app/app/models')
|
135
|
-
end
|
136
|
-
end
|
137
|
-
|
138
|
-
context "the generator for renderer component" do
|
139
|
-
should "properly generate default for erb" do
|
140
|
-
buffer = silence_logger { @app.start(['sample_app', '--root=/tmp', '--renderer=erb', '--script=none']) }
|
141
|
-
assert_match /Applying.*?erb.*?renderer/, buffer
|
142
|
-
assert_match_in_file(/gem 'erubis'/, '/tmp/sample_app/Gemfile')
|
143
|
-
end
|
144
|
-
|
145
|
-
should "properly generate for haml" do
|
146
|
-
buffer = silence_logger { @app.start(['sample_app', '--root=/tmp', '--renderer=haml','--script=none']) }
|
147
|
-
assert_match /Applying.*?haml.*?renderer/, buffer
|
148
|
-
assert_match_in_file(/gem 'haml'/, '/tmp/sample_app/Gemfile')
|
149
|
-
assert_match_in_file(/module SassInitializer.*Sass::Plugin::Rack/m, '/tmp/sample_app/config/initializers/sass.rb')
|
150
|
-
end
|
151
|
-
end
|
152
|
-
|
153
|
-
context "the generator for script component" do
|
154
|
-
should "properly generate for jquery" do
|
155
|
-
buffer = silence_logger { @app.start(['sample_app', '--root=/tmp', '--script=jquery']) }
|
156
|
-
assert_match /Applying.*?jquery.*?script/, buffer
|
157
|
-
assert_file_exists('/tmp/sample_app/public/javascripts/jquery.js')
|
158
|
-
assert_file_exists('/tmp/sample_app/public/javascripts/application.js')
|
159
|
-
end
|
160
|
-
|
161
|
-
should "properly generate for prototype" do
|
162
|
-
buffer = silence_logger { @app.start(['sample_app', '--root=/tmp', '--script=prototype']) }
|
163
|
-
assert_match /Applying.*?prototype.*?script/, buffer
|
164
|
-
assert_file_exists('/tmp/sample_app/public/javascripts/protopak.js')
|
165
|
-
assert_file_exists('/tmp/sample_app/public/javascripts/lowpro.js')
|
166
|
-
assert_file_exists('/tmp/sample_app/public/javascripts/application.js')
|
167
|
-
end
|
168
|
-
|
169
|
-
should "properly generate for rightjs" do
|
170
|
-
buffer = silence_logger { @app.start(['sample_app', '--root=/tmp', '--script=rightjs']) }
|
171
|
-
assert_match /Applying.*?rightjs.*?script/, buffer
|
172
|
-
assert_file_exists('/tmp/sample_app/public/javascripts/right.js')
|
173
|
-
assert_file_exists('/tmp/sample_app/public/javascripts/application.js')
|
174
|
-
end
|
175
|
-
end
|
176
|
-
|
177
|
-
context "the generator for test component" do
|
178
|
-
should "properly default generate for bacon" do
|
179
|
-
buffer = silence_logger { @app.start(['sample_app', '--root=/tmp', '--test=bacon', '--script=none']) }
|
180
|
-
assert_match /Applying.*?bacon.*?test/, buffer
|
181
|
-
assert_match_in_file(/gem 'bacon'/, '/tmp/sample_app/Gemfile')
|
182
|
-
assert_match_in_file(/PADRINO_ENV = 'test' unless defined\?\(PADRINO_ENV\)/, '/tmp/sample_app/test/test_config.rb')
|
183
|
-
assert_match_in_file(/Bacon::Context/, '/tmp/sample_app/test/test_config.rb')
|
184
|
-
end
|
185
|
-
|
186
|
-
should "properly generate for riot" do
|
187
|
-
buffer = silence_logger { @app.start(['sample_app', '--root=/tmp', '--test=riot', '--script=none']) }
|
188
|
-
assert_match /Applying.*?riot.*?test/, buffer
|
189
|
-
assert_match_in_file(/gem 'riot'/, '/tmp/sample_app/Gemfile')
|
190
|
-
assert_match_in_file(/PADRINO_ENV = 'test' unless defined\?\(PADRINO_ENV\)/, '/tmp/sample_app/test/test_config.rb')
|
191
|
-
assert_match_in_file(/Riot::Situation/, '/tmp/sample_app/test/test_config.rb')
|
192
|
-
end
|
193
|
-
|
194
|
-
should "properly generate for rspec" do
|
195
|
-
buffer = silence_logger { @app.start(['sample_app', '--root=/tmp', '--test=rspec', '--script=none']) }
|
196
|
-
assert_match /Applying.*?rspec.*?test/, buffer
|
197
|
-
assert_match_in_file(/gem 'rspec'.*?:require => "spec"/, '/tmp/sample_app/Gemfile')
|
198
|
-
assert_match_in_file(/PADRINO_ENV = 'test' unless defined\?\(PADRINO_ENV\)/, '/tmp/sample_app/test/test_config.rb')
|
199
|
-
assert_match_in_file(/Spec::Runner/, '/tmp/sample_app/test/test_config.rb')
|
200
|
-
end
|
201
|
-
|
202
|
-
should "properly generate for shoulda" do
|
203
|
-
buffer = silence_logger { @app.start(['sample_app', '--root=/tmp', '--test=shoulda', '--script=none']) }
|
204
|
-
assert_match /Applying.*?shoulda.*?test/, buffer
|
205
|
-
assert_match_in_file(/gem 'shoulda'/, '/tmp/sample_app/Gemfile')
|
206
|
-
assert_match_in_file(/PADRINO_ENV = 'test' unless defined\?\(PADRINO_ENV\)/, '/tmp/sample_app/test/test_config.rb')
|
207
|
-
assert_match_in_file(/Test::Unit::TestCase/, '/tmp/sample_app/test/test_config.rb')
|
208
|
-
end
|
209
|
-
|
210
|
-
should "properly generate for testspec" do
|
211
|
-
buffer = silence_logger { @app.start(['sample_app', '--root=/tmp', '--test=testspec', '--script=none']) }
|
212
|
-
assert_match /Applying.*?testspec.*?test/, buffer
|
213
|
-
assert_match_in_file(/gem 'test\/spec'/, '/tmp/sample_app/Gemfile')
|
214
|
-
assert_match_in_file(/PADRINO_ENV = 'test' unless defined\?\(PADRINO_ENV\)/, '/tmp/sample_app/test/test_config.rb')
|
215
|
-
assert_match_in_file(/Test::Unit::TestCase/, '/tmp/sample_app/test/test_config.rb')
|
216
|
-
end
|
217
53
|
end
|
218
54
|
end
|
data/test/test_cli.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/helper'
|
2
|
+
require 'thor/group'
|
3
|
+
require 'fakeweb'
|
4
|
+
|
5
|
+
class TestCli < Test::Unit::TestCase
|
6
|
+
def setup
|
7
|
+
FakeWeb.allow_net_connect = false
|
8
|
+
`rm -rf /tmp/sample_project`
|
9
|
+
@cli = Padrino::Generators::Cli.dup
|
10
|
+
@project = Padrino::Generators::Project.dup
|
11
|
+
end
|
12
|
+
|
13
|
+
context 'the cli' do
|
14
|
+
|
15
|
+
should "fail without arguments" do
|
16
|
+
output = silence_logger { @cli.start }
|
17
|
+
assert_match "Please specify generator to use", output
|
18
|
+
end
|
19
|
+
|
20
|
+
should "work correctly if we have a project" do
|
21
|
+
silence_logger { @project.start(['sample_project', '--root=/tmp']) }
|
22
|
+
assert_nothing_raised { silence_logger { @cli.start(['--root=/tmp/sample_project']) } }
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -3,57 +3,64 @@ require 'thor/group'
|
|
3
3
|
|
4
4
|
class TestControllerGenerator < Test::Unit::TestCase
|
5
5
|
def setup
|
6
|
-
Padrino::Generators.
|
7
|
-
@
|
8
|
-
@
|
9
|
-
@
|
10
|
-
|
11
|
-
# @route_path = '/tmp/sample_app/config/urls.rb'
|
12
|
-
`rm -rf /tmp/sample_app`
|
6
|
+
@project = Padrino::Generators::Project.dup
|
7
|
+
@cont_gen = Padrino::Generators::Controller.dup
|
8
|
+
@controller_path = '/tmp/sample_project/app/controllers/demo_items.rb'
|
9
|
+
@controller_test_path = '/tmp/sample_project/test/controllers/demo_items_controller_test.rb'
|
10
|
+
`rm -rf /tmp/sample_project`
|
13
11
|
end
|
14
12
|
|
15
13
|
context 'the controller generator' do
|
16
14
|
should "fail outside app root" do
|
17
|
-
output = silence_logger { @
|
15
|
+
output = silence_logger { @cont_gen.start(['demo', '-r=/tmp']) }
|
18
16
|
assert_match(/not at the root/, output)
|
19
17
|
assert_no_file_exists('/tmp/app/controllers/demo.rb')
|
20
18
|
end
|
21
19
|
|
20
|
+
should 'not fail if we don\'t have test component' do
|
21
|
+
silence_logger { @project.start(['sample_project', '--root=/tmp', '--test=none']) }
|
22
|
+
silence_logger { @cont_gen.start(['demo_items', '-r=/tmp/sample_project']) }
|
23
|
+
assert_match_in_file(/SampleProject.controllers :demo_items do/m, @controller_path)
|
24
|
+
assert_match_in_file(/SampleProject.helpers do/m, '/tmp/sample_project/app/helpers/demo_items_helper.rb')
|
25
|
+
assert_file_exists('/tmp/sample_project/app/views/demo_items')
|
26
|
+
assert_no_file_exists("/tmp/sample_project/test")
|
27
|
+
end
|
28
|
+
|
22
29
|
should "generate controller within existing application" do
|
23
|
-
silence_logger { @
|
24
|
-
silence_logger { @
|
25
|
-
assert_match_in_file(/
|
26
|
-
assert_match_in_file(/
|
27
|
-
assert_file_exists('/tmp/
|
30
|
+
silence_logger { @project.start(['sample_project', '--root=/tmp', '--script=none', '-t=bacon']) }
|
31
|
+
silence_logger { @cont_gen.start(['demo_items', '-r=/tmp/sample_project']) }
|
32
|
+
assert_match_in_file(/SampleProject.controllers :demo_items do/m, @controller_path)
|
33
|
+
assert_match_in_file(/SampleProject.helpers do/m, '/tmp/sample_project/app/helpers/demo_items_helper.rb')
|
34
|
+
assert_file_exists('/tmp/sample_project/app/views/demo_items')
|
28
35
|
end
|
29
36
|
|
30
37
|
should "generate controller test for bacon" do
|
31
|
-
silence_logger { @
|
32
|
-
silence_logger { @
|
38
|
+
silence_logger { @project.start(['sample_project', '--root=/tmp', '--script=none', '-t=bacon']) }
|
39
|
+
silence_logger { @cont_gen.start(['demo_items', '-r=/tmp/sample_project']) }
|
33
40
|
assert_match_in_file(/describe "DemoItemsController" do/m, @controller_test_path)
|
34
41
|
end
|
35
42
|
|
36
43
|
should "generate controller test for riot" do
|
37
|
-
silence_logger { @
|
38
|
-
silence_logger { @
|
44
|
+
silence_logger { @project.start(['sample_project', '--root=/tmp', '--script=none', '-t=riot']) }
|
45
|
+
silence_logger { @cont_gen.start(['demo_items', '-r=/tmp/sample_project']) }
|
39
46
|
assert_match_in_file(/context "DemoItemsController" do/m, @controller_test_path)
|
40
47
|
end
|
41
48
|
|
42
49
|
should "generate controller test for testspec" do
|
43
|
-
silence_logger { @
|
44
|
-
silence_logger { @
|
50
|
+
silence_logger { @project.start(['sample_project', '--root=/tmp', '--script=none', '-t=testspec']) }
|
51
|
+
silence_logger { @cont_gen.start(['demo_items', '-r=/tmp/sample_project']) }
|
45
52
|
assert_match_in_file(/context "DemoItemsController" do/m, @controller_test_path)
|
46
53
|
end
|
47
54
|
|
48
55
|
should "generate controller test for rspec" do
|
49
|
-
silence_logger { @
|
50
|
-
silence_logger { @
|
51
|
-
assert_match_in_file(/describe "DemoItemsController" do/m, '/tmp/
|
56
|
+
silence_logger { @project.start(['sample_project', '--root=/tmp', '--script=none', '-t=rspec']) }
|
57
|
+
silence_logger { @cont_gen.start(['demo_items', '-r=/tmp/sample_project']) }
|
58
|
+
assert_match_in_file(/describe "DemoItemsController" do/m, '/tmp/sample_project/test/controllers/demo_items_controller_spec.rb')
|
52
59
|
end
|
53
60
|
|
54
61
|
should "generate controller test for shoulda" do
|
55
|
-
silence_logger { @
|
56
|
-
silence_logger { @
|
62
|
+
silence_logger { @project.start(['sample_project', '--root=/tmp', '--script=none', '-t=shoulda']) }
|
63
|
+
silence_logger { @cont_gen.start(['demo_items', '-r=/tmp/sample_project']) }
|
57
64
|
expected_pattern = /class DemoItemsControllerTest < Test::Unit::TestCase/m
|
58
65
|
assert_match_in_file(expected_pattern, @controller_test_path)
|
59
66
|
end
|
@@ -61,45 +68,38 @@ class TestControllerGenerator < Test::Unit::TestCase
|
|
61
68
|
# Controller action generation
|
62
69
|
|
63
70
|
should "generate actions for get:test post:yada" do
|
64
|
-
silence_logger { @
|
65
|
-
silence_logger { @
|
71
|
+
silence_logger { @project.start(['sample_project', '--root=/tmp', '--script=none', '-t=shoulda'])}
|
72
|
+
silence_logger { @cont_gen.start(['demo_items', "get:test", "post:yada",'-r=/tmp/sample_project']) }
|
66
73
|
assert_match_in_file(/get :test do\n end\n/m,@controller_path)
|
67
74
|
assert_match_in_file(/post :yada do\n end\n/m,@controller_path)
|
68
75
|
end
|
69
76
|
|
70
|
-
should "generate url routes for get:yoda post:yada" do
|
71
|
-
silence_logger { @app.start(['sample_app', '--root=/tmp', '--script=none', '-t=shoulda'])}
|
72
|
-
silence_logger { @contgen.start(['demo_items', "get:yoda","post:yada",'-r=/tmp/sample_app']) }
|
73
|
-
# assert_match_in_file(/map\(\:yoda\).to\(\"\/demo_items\/yoda\"\)/m,@route_path)
|
74
|
-
# assert_match_in_file(/map\(\:yada\).to\(\"\/demo_items\/yada\"\)/m,@route_path)
|
75
|
-
end
|
76
|
-
|
77
77
|
end
|
78
78
|
|
79
79
|
context "the controller destroy option" do
|
80
80
|
|
81
81
|
should "destroy controller files" do
|
82
|
-
silence_logger { @
|
83
|
-
silence_logger { @
|
84
|
-
silence_logger { @
|
82
|
+
silence_logger { @project.start(['sample_project', '--root=/tmp', '--script=none', '-t=bacon'])}
|
83
|
+
silence_logger { @cont_gen.start(['demo_items','-r=/tmp/sample_project']) }
|
84
|
+
silence_logger { @cont_gen.start(['demo_items','-r=/tmp/sample_project','-d'])}
|
85
85
|
assert_no_file_exists(@controller_path)
|
86
86
|
assert_no_file_exists(@controller_test_path)
|
87
|
-
assert_no_file_exists('/tmp/
|
87
|
+
assert_no_file_exists('/tmp/sample_project/app/helpers/demo_items_helper.rb')
|
88
88
|
end
|
89
89
|
|
90
90
|
should "destroy controller files with rspec" do
|
91
|
-
silence_logger { @
|
92
|
-
silence_logger { @
|
93
|
-
silence_logger { @
|
91
|
+
silence_logger { @project.start(['sample_project', '--root=/tmp', '--script=none', '-t=rspec'])}
|
92
|
+
silence_logger { @cont_gen.start(['demo_items','-r=/tmp/sample_project']) }
|
93
|
+
silence_logger { @cont_gen.start(['demo_items','-r=/tmp/sample_project','-d'])}
|
94
94
|
assert_no_file_exists(@controller_path)
|
95
|
-
assert_no_file_exists('/tmp/
|
96
|
-
assert_no_file_exists('/tmp/
|
95
|
+
assert_no_file_exists('/tmp/sample_project/app/helpers/demo_items_helper.rb')
|
96
|
+
assert_no_file_exists('/tmp/sample_project/test/controllers/demo_items_controller_spec.rb')
|
97
97
|
end
|
98
98
|
|
99
99
|
should "remove url routes" do
|
100
|
-
silence_logger { @
|
101
|
-
silence_logger { @
|
102
|
-
silence_logger { @
|
100
|
+
silence_logger { @project.start(['sample_project', '--root=/tmp', '--script=none', '-t=bacon'])}
|
101
|
+
silence_logger { @cont_gen.start(['demo_items', "get:yoda","post:yada",'-r=/tmp/sample_project']) }
|
102
|
+
silence_logger { @cont_gen.start(['demo_items','-r=/tmp/sample_project','-d'])}
|
103
103
|
# assert_no_match_in_file(/map\(\:yoda\).to\(\"\/demo_items\/yoda\"\)/m,@route_path)
|
104
104
|
# assert_no_match_in_file(/map\(\:yada\).to\(\"\/demo_items\/yada\"\)/m,@route_path)
|
105
105
|
end
|