padrino-gen 0.9.1 → 0.9.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.rdoc +20 -90
- data/VERSION +1 -1
- data/lib/padrino-gen/generators/cli.rb +2 -2
- data/lib/padrino-gen/generators/components/actions.rb +1 -7
- data/lib/padrino-gen/generators/components/orms/couchrest_gen.rb +4 -4
- data/lib/padrino-gen/generators/components/orms/mongoid_gen.rb +81 -0
- data/lib/padrino-gen/generators/components/orms/mongomapper_gen.rb +5 -4
- data/lib/padrino-gen/generators/components/renderers/haml_gen.rb +8 -0
- data/lib/padrino-gen/generators/components/scripts/mootools_gen.rb +16 -0
- data/lib/padrino-gen/generators/components/tests/bacon_test_gen.rb +3 -0
- data/lib/padrino-gen/generators/components/tests/cucumber_test_gen.rb +77 -0
- data/lib/padrino-gen/generators/components/tests/riot_test_gen.rb +3 -0
- data/lib/padrino-gen/generators/components/tests/rspec_test_gen.rb +46 -35
- data/lib/padrino-gen/generators/components/tests/shoulda_test_gen.rb +3 -0
- data/lib/padrino-gen/generators/components/tests/testspec_test_gen.rb +3 -0
- data/lib/padrino-gen/generators/project.rb +3 -3
- data/lib/padrino-gen/generators/templates/scripts/mootools-core.js +357 -0
- data/lib/padrino-gen/padrino-tasks/seed.rb +5 -7
- data/lib/padrino-gen.rb +6 -2
- data/padrino-gen.gemspec +10 -6
- data/test/helper.rb +1 -1
- data/test/test_model_generator.rb +19 -1
- data/test/test_project_generator.rb +27 -0
- metadata +38 -69
data/README.rdoc
CHANGED
|
@@ -7,7 +7,8 @@ Padrino comes preloaded with flexible code generators powered in part by the exc
|
|
|
7
7
|
both in creating new applications and building on existing ones. The generators have been built to be as library agnostic
|
|
8
8
|
as possible, supporting a myriad of test frameworks, js libraries, mocking libraries, etc.
|
|
9
9
|
|
|
10
|
-
See the
|
|
10
|
+
See the guide for {Padrino Generators}[http://wiki.github.com/padrino/padrino-framework/generators] for a
|
|
11
|
+
more in-depth look at the system.
|
|
11
12
|
|
|
12
13
|
=== Application Generator
|
|
13
14
|
|
|
@@ -19,14 +20,6 @@ to using Padrino.
|
|
|
19
20
|
One important feature of the generators is that they were built from the ground up to support a wide variety
|
|
20
21
|
of tools, libraries and gems for use within your padrino application.
|
|
21
22
|
|
|
22
|
-
This means that Padrino generators do *not* lock you into using any particular database, ORM, testing framework,
|
|
23
|
-
templating engine or javascript library. In fact, when generating an application you can actually tell
|
|
24
|
-
Padrino which components you would like to use!
|
|
25
|
-
|
|
26
|
-
The usage for the project generator is quite simple:
|
|
27
|
-
|
|
28
|
-
$ padrino-gen project <the_app_name> </path/to/create/app> --<component-name> <value>
|
|
29
|
-
|
|
30
23
|
The simplest possible command to generate a base application would be:
|
|
31
24
|
|
|
32
25
|
$ padrino-gen project demo_project
|
|
@@ -35,11 +28,7 @@ This would construct a Padrino application DemoApp (which extends from Padrino::
|
|
|
35
28
|
inside the folder 'demo_project' at our current path. Inside the application there would be configuration and
|
|
36
29
|
setup performed for the default components.
|
|
37
30
|
|
|
38
|
-
You can
|
|
39
|
-
|
|
40
|
-
$ padrino-gen project demo_project --test rspec --renderer haml --mock rr --script jquery --orm datamapper
|
|
41
|
-
|
|
42
|
-
There is also support for aliases for each component within the command:
|
|
31
|
+
You can define specific components to be used:
|
|
43
32
|
|
|
44
33
|
$ padrino-gen project demo_project -t rspec -r haml -m rr -s jquery -d datamapper
|
|
45
34
|
|
|
@@ -49,25 +38,14 @@ You can also instruct the generator to skip a certain component to avoid using o
|
|
|
49
38
|
|
|
50
39
|
The available components and their default options are listed below:
|
|
51
40
|
|
|
52
|
-
test:: rspec (default), bacon, shoulda, testspec, riot
|
|
41
|
+
test:: rspec (default), bacon, shoulda, cucumber, testspec, riot
|
|
53
42
|
renderer:: haml (default), erb
|
|
54
|
-
mock:: none (default), rr
|
|
55
|
-
script:: none (default), prototype, rightjs
|
|
56
|
-
orm:: none (default), mongomapper, activerecord, sequel, couchrest
|
|
57
|
-
|
|
58
|
-
The generator uses the <tt>bundler</tt> gem to resolve any application dependencies when the application is newly created.
|
|
59
|
-
The necessary bundler command can be executed automatically through the generator with
|
|
43
|
+
mock:: none (default), mocha, rr
|
|
44
|
+
script:: none (default), jquery, prototype, mootools, rightjs
|
|
45
|
+
orm:: none (default), mongomapper, mongoid, activerecord, sequel, couchrest
|
|
60
46
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
or this can be done manually through executing command <tt>gem bundle</tt> in the terminal at the root of the generated application.
|
|
64
|
-
If not executed manually, the bundling will be performed automatically the first time the application attempts to boot.
|
|
65
|
-
Note that this command only has to be performed when the application is first generated or when the Gemfile is modified.
|
|
66
|
-
|
|
67
|
-
The generator framework within padrino is extensible and additional components and tools can be added easily.
|
|
68
|
-
This would be achieved through forking our project and reading through the code in <tt>lib/generators/App.rb</tt> and
|
|
69
|
-
the setup instructions inside the relevant files within <tt>lib/generators/components/</tt>. We are happy to accept pull requests
|
|
70
|
-
for additional component types not originally included (although helping us maintain them would also be appreciated).
|
|
47
|
+
To learn more about the project generator, check out the guide to
|
|
48
|
+
{Padrino Generators}[http://wiki.github.com/padrino/padrino-framework/generators].
|
|
71
49
|
|
|
72
50
|
=== Sub App Generator
|
|
73
51
|
|
|
@@ -90,6 +68,9 @@ By default these apps are mounted under:
|
|
|
90
68
|
|
|
91
69
|
but you can edit config/apps.rb and change it.
|
|
92
70
|
|
|
71
|
+
To learn more about the subapp generator, check out the guide to
|
|
72
|
+
{Padrino Generators}[http://wiki.github.com/padrino/padrino-framework/generators].
|
|
73
|
+
|
|
93
74
|
=== Model Generator
|
|
94
75
|
|
|
95
76
|
Padrino provides generator support for quickly creating new models within your Padrino application. Note that
|
|
@@ -108,20 +89,8 @@ You can also specify desired fields to be contained within your User model:
|
|
|
108
89
|
|
|
109
90
|
$ padrino-gen model User name:string age:integer email:string
|
|
110
91
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
* model definition file [app/models/user.rb]
|
|
115
|
-
* migration declaration [db/migrate/xxx_create_users.rb]
|
|
116
|
-
* model unit test file [test/models/user_test.rb]
|
|
117
|
-
|
|
118
|
-
You can define as many models as you would like in a Padrino application using this generator.
|
|
119
|
-
|
|
120
|
-
You can destroy models that you created via the destroy option and setting it to true. default is false.
|
|
121
|
-
|
|
122
|
-
$ padrino-gen model User -d
|
|
123
|
-
|
|
124
|
-
This remove all created model files.
|
|
92
|
+
To learn more about the model generator, check out the guide to
|
|
93
|
+
{Padrino Generators}[http://wiki.github.com/padrino/padrino-framework/generators].
|
|
125
94
|
|
|
126
95
|
=== Migration Generator
|
|
127
96
|
|
|
@@ -137,19 +106,8 @@ Using the migration generator is as simple as:
|
|
|
137
106
|
$ padrino-gen migration AddFieldsToUsers
|
|
138
107
|
$ padrino-gen migration RemoveFieldsFromUsers
|
|
139
108
|
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
$ padrino-gen migration AddFieldsToUsers last_login:datetime crypted_password:string
|
|
143
|
-
$ padrino-gen migration RemoveFieldsFromUsers password:string ip_address:string
|
|
144
|
-
|
|
145
|
-
The migration generator will then construct the migration file according to your ORM component chosen
|
|
146
|
-
within <tt>db/migrate/xxx_add_fields_to_users.rb</tt> including the columns specified in the command.
|
|
147
|
-
|
|
148
|
-
You can destroy migrations that you created via the destroy option and setting it to true. default is false.
|
|
149
|
-
|
|
150
|
-
$ padrino-gen migration AddFieldsToUsers -d
|
|
151
|
-
|
|
152
|
-
This removes the migration file.
|
|
109
|
+
To learn more about the migration generator, check out the guide to
|
|
110
|
+
{Padrino Generators}[http://wiki.github.com/padrino/padrino-framework/generators].
|
|
153
111
|
|
|
154
112
|
=== Controller Generator
|
|
155
113
|
|
|
@@ -163,28 +121,13 @@ created through the Padrino application generator and that follow Padrino conven
|
|
|
163
121
|
Using the controller generator is as simple as:
|
|
164
122
|
|
|
165
123
|
$ padrino-gen controller Admin
|
|
166
|
-
|
|
167
|
-
If you want create a controller for a specified sub app you can:
|
|
168
|
-
|
|
169
|
-
$ padrino-gen controller Admin -a my_sub_app
|
|
170
124
|
|
|
171
125
|
You can also specify desired actions to be added to your controller:
|
|
172
126
|
|
|
173
127
|
$ padrino-gen controller Admin get:index get:new post:create
|
|
174
128
|
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
test framework chosen during app generation. A default route will also be generated mapping to name of the controller and the route name. For example:
|
|
178
|
-
|
|
179
|
-
$ padrino-gen controller User get:index
|
|
180
|
-
|
|
181
|
-
will create a url route for :index mapping to "/user/index"
|
|
182
|
-
|
|
183
|
-
You can destroy controllers that you created via the destroy option and setting it to true. default is false.
|
|
184
|
-
|
|
185
|
-
$ padrino-gen controller User -d
|
|
186
|
-
|
|
187
|
-
This removes all created controller files.
|
|
129
|
+
To learn more about the controller generator, check out the guide to
|
|
130
|
+
{Padrino Generators}[http://wiki.github.com/padrino/padrino-framework/generators].
|
|
188
131
|
|
|
189
132
|
=== Mailer Generator
|
|
190
133
|
|
|
@@ -196,21 +139,8 @@ Using the mailer generator is as simple as:
|
|
|
196
139
|
|
|
197
140
|
$ padrino-gen mailer UserNotifier
|
|
198
141
|
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
$ padrino-gen mailer UserNotifier -a my_sub_app
|
|
202
|
-
|
|
203
|
-
You can also specify desired delivery actions to be added to the mailer:
|
|
204
|
-
|
|
205
|
-
$ padrino-gen mailer UserNotifier confirm_account welcome inactive_account
|
|
206
|
-
|
|
207
|
-
The mailer generator will then construct the mailer file within <tt>app/mailers/user_notifier.rb</tt>
|
|
208
|
-
|
|
209
|
-
You can destroy mailer that you created via the destroy option and setting it to true. default is false.
|
|
210
|
-
|
|
211
|
-
$ padrino-gen mailer UserNotifer -d
|
|
212
|
-
|
|
213
|
-
This remove all created mailer files.
|
|
142
|
+
To learn more about the mailer generator, check out the guide to
|
|
143
|
+
{Padrino Generators}[http://wiki.github.com/padrino/padrino-framework/generators].
|
|
214
144
|
|
|
215
145
|
== Copyright
|
|
216
146
|
|
data/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
0.9.
|
|
1
|
+
0.9.2
|
|
@@ -4,7 +4,7 @@ require 'padrino-core/support_lite'
|
|
|
4
4
|
module Padrino
|
|
5
5
|
module Generators
|
|
6
6
|
##
|
|
7
|
-
# This class bootstrap +config/boot+ and perform +Padrino::Generators.
|
|
7
|
+
# This class bootstrap +config/boot+ and perform +Padrino::Generators.load_components!+ for handle
|
|
8
8
|
# 3rd party generators
|
|
9
9
|
#
|
|
10
10
|
class Cli < Thor::Group
|
|
@@ -31,7 +31,7 @@ module Padrino
|
|
|
31
31
|
end
|
|
32
32
|
|
|
33
33
|
def setup
|
|
34
|
-
Padrino::Generators.
|
|
34
|
+
Padrino::Generators.load_components!
|
|
35
35
|
|
|
36
36
|
generator_kind = ARGV.delete_at(0).to_s.downcase.to_sym if ARGV[0].present?
|
|
37
37
|
generator_class = Padrino::Generators.mappings[generator_kind]
|
|
@@ -2,11 +2,6 @@ module Padrino
|
|
|
2
2
|
module Generators
|
|
3
3
|
module Components
|
|
4
4
|
module Actions
|
|
5
|
-
BASE_TEST_HELPER = (<<-TEST).gsub(/^ {8}/, '')
|
|
6
|
-
PADRINO_ENV = 'test' unless defined?(PADRINO_ENV)
|
|
7
|
-
require File.dirname(__FILE__) + "/../config/boot"
|
|
8
|
-
TEST
|
|
9
|
-
|
|
10
5
|
# For orm database components
|
|
11
6
|
# Generates the model migration file created when generating a new model
|
|
12
7
|
# options => { :base => "....text...", :up => "..text...",
|
|
@@ -89,9 +84,8 @@ module Padrino
|
|
|
89
84
|
# insert_test_suite_setup('...CLASS_NAME...')
|
|
90
85
|
# => inject_into_file("test/test_config.rb", TEST.gsub(/CLASS_NAME/, @class_name), :after => "set :environment, :test")
|
|
91
86
|
def insert_test_suite_setup(suite_text, options={})
|
|
92
|
-
test_helper_text = [BASE_TEST_HELPER, suite_text.gsub(/CLASS_NAME/, @class_name)].join("\n")
|
|
93
87
|
options.reverse_merge!(:path => "test/test_config.rb")
|
|
94
|
-
create_file(options[:path],
|
|
88
|
+
create_file(options[:path], suite_text.gsub(/CLASS_NAME/, @class_name))
|
|
95
89
|
end
|
|
96
90
|
|
|
97
91
|
# For mocking components
|
|
@@ -7,16 +7,16 @@ module Padrino
|
|
|
7
7
|
|
|
8
8
|
COUCHREST = (<<-COUCHREST).gsub(/^ {10}/, '')
|
|
9
9
|
case Padrino.env
|
|
10
|
-
when :development then COUCHDB =
|
|
11
|
-
when :production then COUCHDB =
|
|
12
|
-
when :test then COUCHDB =
|
|
10
|
+
when :development then COUCHDB = '!NAME!_name_development'
|
|
11
|
+
when :production then COUCHDB = '!NAME!_name_production'
|
|
12
|
+
when :test then COUCHDB = '!NAME!_name_test'
|
|
13
13
|
end
|
|
14
14
|
CouchRest.database!(COUCHDB)
|
|
15
15
|
COUCHREST
|
|
16
16
|
|
|
17
17
|
def setup_orm
|
|
18
18
|
require_dependencies 'couchrest'
|
|
19
|
-
create_file("config/database.rb", COUCHREST)
|
|
19
|
+
create_file("config/database.rb", COUCHREST.gsub(/!NAME!/, name.underscore))
|
|
20
20
|
empty_directory('app/models')
|
|
21
21
|
end
|
|
22
22
|
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
module Padrino
|
|
2
|
+
module Generators
|
|
3
|
+
module Components
|
|
4
|
+
module Orms
|
|
5
|
+
|
|
6
|
+
module MongoidGen
|
|
7
|
+
|
|
8
|
+
MONGOID = (<<-MONGO).gsub(/^ {10}/, '')
|
|
9
|
+
|
|
10
|
+
# Connection.new takes host, port
|
|
11
|
+
host = 'localhost'
|
|
12
|
+
port = Mongo::Connection::DEFAULT_PORT
|
|
13
|
+
|
|
14
|
+
database_name = case Padrino.env
|
|
15
|
+
when :development then '!NAME!_development'
|
|
16
|
+
when :production then '!NAME!_production'
|
|
17
|
+
when :test then '!NAME!_test'
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
Mongoid.database = Mongo::Connection.new(host, port).db(database_name)
|
|
21
|
+
|
|
22
|
+
# You can also configure Mongoid this way
|
|
23
|
+
# Mongoid.configure do |config|
|
|
24
|
+
# name = @settings["database"]
|
|
25
|
+
# host = @settings["host"]
|
|
26
|
+
# config.master = Mongo::Connection.new.db(name)
|
|
27
|
+
# config.slaves = [
|
|
28
|
+
# Mongo::Connection.new(host, @settings["slave_one"]["port"], :slave_ok => true).db(name),
|
|
29
|
+
# Mongo::Connection.new(host, @settings["slave_two"]["port"], :slave_ok => true).db(name)
|
|
30
|
+
# ]
|
|
31
|
+
# end
|
|
32
|
+
#
|
|
33
|
+
# More installation and setup notes are on http://mongoid.org/docs/
|
|
34
|
+
MONGO
|
|
35
|
+
|
|
36
|
+
def setup_orm
|
|
37
|
+
require_dependencies 'mongo_ext', :require => 'mongo'
|
|
38
|
+
require_dependencies 'mongoid'
|
|
39
|
+
create_file("config/database.rb", MONGOID.gsub(/!NAME!/, name.underscore))
|
|
40
|
+
empty_directory('app/models')
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
MONGOID_MODEL = (<<-MODEL).gsub(/^ {10}/, '')
|
|
44
|
+
class !NAME!
|
|
45
|
+
include Mongoid::Document
|
|
46
|
+
include Mongoid::Timestamps # adds created_at and updated_at fields
|
|
47
|
+
|
|
48
|
+
# field <name>, :type => <type>, :default => <value>
|
|
49
|
+
!FIELDS!
|
|
50
|
+
|
|
51
|
+
# You can define indexes on documents using the index macro:
|
|
52
|
+
# index :field <, :unique => true>
|
|
53
|
+
|
|
54
|
+
# You can create a composite key in mongoid to replace the default id using the key macro:
|
|
55
|
+
# key :field <, :another_field, :one_more ....>
|
|
56
|
+
|
|
57
|
+
end
|
|
58
|
+
MODEL
|
|
59
|
+
|
|
60
|
+
def create_model_file(name, fields)
|
|
61
|
+
model_path = destination_root('app/models/', "#{name.to_s.underscore}.rb")
|
|
62
|
+
field_tuples = fields.collect { |value| value.split(":") }
|
|
63
|
+
column_declarations = field_tuples.collect { |field, kind| "field :#{field}, :type => #{kind.camelize}" }.join("\n ")
|
|
64
|
+
model_contents = MONGOID_MODEL.gsub(/!NAME!/, name.to_s.camelize)
|
|
65
|
+
model_contents.gsub!(/!FIELDS!/, column_declarations)
|
|
66
|
+
create_file(model_path, model_contents)
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
def create_model_migration(filename, name, fields)
|
|
70
|
+
# NO MIGRATION NEEDED
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def create_migration_file(migration_name, name, columns)
|
|
74
|
+
# NO MIGRATION NEEDED
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
end
|
|
@@ -9,15 +9,16 @@ module Padrino
|
|
|
9
9
|
MongoMapper.connection = Mongo::Connection.new('localhost', nil, :logger => logger)
|
|
10
10
|
|
|
11
11
|
case Padrino.env
|
|
12
|
-
when :development then MongoMapper.database = '
|
|
13
|
-
when :production then MongoMapper.database = '
|
|
14
|
-
when :test then MongoMapper.database = '
|
|
12
|
+
when :development then MongoMapper.database = '!NAME!_development'
|
|
13
|
+
when :production then MongoMapper.database = '!NAME!_production'
|
|
14
|
+
when :test then MongoMapper.database = '!NAME!_test'
|
|
15
15
|
end
|
|
16
16
|
MONGO
|
|
17
17
|
|
|
18
18
|
def setup_orm
|
|
19
|
+
require_dependencies 'mongo_ext', :require => 'mongo'
|
|
19
20
|
require_dependencies 'mongo_mapper'
|
|
20
|
-
create_file("config/database.rb", MONGO)
|
|
21
|
+
create_file("config/database.rb", MONGO.gsub(/!NAME!/, name.underscore))
|
|
21
22
|
empty_directory('app/models')
|
|
22
23
|
end
|
|
23
24
|
|
|
@@ -7,19 +7,27 @@ module Padrino
|
|
|
7
7
|
|
|
8
8
|
SASS_INIT = (<<-SASS).gsub(/^ {10}/, '')
|
|
9
9
|
# Enables support for SASS template reloading for rack.
|
|
10
|
+
# Store SASS files by default within 'public/stylesheets/sass'
|
|
10
11
|
# See http://nex-3.com/posts/88-sass-supports-rack for more details.
|
|
11
12
|
|
|
12
13
|
module SassInitializer
|
|
13
14
|
def self.registered(app)
|
|
14
15
|
require 'sass/plugin/rack'
|
|
16
|
+
Sass::Plugin.options[:template_location] = File.join(Padrino.root, "app/stylesheets")
|
|
17
|
+
Sass::Plugin.options[:css_location] = File.join(Padrino.root, "public/stylesheets")
|
|
15
18
|
app.use Sass::Plugin::Rack
|
|
16
19
|
end
|
|
17
20
|
end
|
|
18
21
|
SASS
|
|
19
22
|
|
|
23
|
+
SASS_REGISTER = (<<-SASSR).gsub(/^ {10}/, '')
|
|
24
|
+
register SassInitializer # Remove if not using SASS\n
|
|
25
|
+
SASSR
|
|
26
|
+
|
|
20
27
|
def setup_renderer
|
|
21
28
|
require_dependencies 'haml'
|
|
22
29
|
create_file destination_root('/lib/sass.rb'), SASS_INIT
|
|
30
|
+
inject_into_file destination_root('/app/app.rb'), SASS_REGISTER, :after => "configure do\n"
|
|
23
31
|
end
|
|
24
32
|
end
|
|
25
33
|
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
module Padrino
|
|
2
|
+
module Generators
|
|
3
|
+
module Components
|
|
4
|
+
module Scripts
|
|
5
|
+
|
|
6
|
+
module MootoolsGen
|
|
7
|
+
def setup_script
|
|
8
|
+
copy_file('templates/scripts/mootools-core.js', destination_root("/public/javascripts/mootools-core.js"))
|
|
9
|
+
create_file(destination_root('/public/javascripts/application.js'), "// Put your application scripts here")
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
require 'padrino-gen/generators/components/tests/rspec_test_gen'
|
|
2
|
+
|
|
3
|
+
module Padrino
|
|
4
|
+
module Generators
|
|
5
|
+
module Components
|
|
6
|
+
module Tests
|
|
7
|
+
module CucumberGen
|
|
8
|
+
include Padrino::Generators::Components::Tests::RspecGen
|
|
9
|
+
|
|
10
|
+
CUCUMBER_SETUP = (<<-TEST).gsub(/^ {10}/, '')
|
|
11
|
+
PADRINO_ENV = 'test' unless defined?(PADRINO_ENV)
|
|
12
|
+
require File.dirname(__FILE__) + "/../../config/boot"
|
|
13
|
+
|
|
14
|
+
require 'capybara/cucumber'
|
|
15
|
+
require 'spec/expectations'
|
|
16
|
+
|
|
17
|
+
# Sinatra < 1.0 always disable sessions for test env
|
|
18
|
+
# so if you need them it's necessary to force the use
|
|
19
|
+
# of Rack::Session::Cookie
|
|
20
|
+
Capybara.app = CLASS_NAME.tap { |app| app.use Rack::Session::Cookie }
|
|
21
|
+
# You can handle all padrino applications instead using:
|
|
22
|
+
# Capybara.app = Padrino.application
|
|
23
|
+
TEST
|
|
24
|
+
|
|
25
|
+
CUCUMBER_YML = (<<-TEST).gsub(/^ {10}/, '')
|
|
26
|
+
default: --tags ~@wip --strict features
|
|
27
|
+
html_report: --tags ~@wip --strict --format html --out=features_report.html features
|
|
28
|
+
TEST
|
|
29
|
+
|
|
30
|
+
CUCUMBER_FEATURE = (<<-TEST).gsub(/^ {10}/, '')
|
|
31
|
+
Feature: Addition
|
|
32
|
+
In order to avoid silly mistakes
|
|
33
|
+
As a math idiot
|
|
34
|
+
I want to be told the sum of two numbers
|
|
35
|
+
|
|
36
|
+
Scenario: Add two numbers
|
|
37
|
+
Given I visit the calculator page
|
|
38
|
+
And I fill in '50' for 'first'
|
|
39
|
+
And I fill in '70' for 'second'
|
|
40
|
+
When I press 'Add'
|
|
41
|
+
Then I should see 'Answer: 120'
|
|
42
|
+
TEST
|
|
43
|
+
|
|
44
|
+
CUCUMBER_STEP = (<<-TEST).gsub(/^ {10}/, '')
|
|
45
|
+
Given /^I visit the calculator page$/ do
|
|
46
|
+
visit '/add'
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
Given /^I fill in '(.*)' for '(.*)'$/ do |value, field|
|
|
50
|
+
fill_in(field, :with => value)
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
When /^I press '(.*)'$/ do |name|
|
|
54
|
+
click_button(name)
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
Then /^I should see '(.*)'$/ do |text|
|
|
58
|
+
response_body.should contain(/#\{text}/m)
|
|
59
|
+
end
|
|
60
|
+
TEST
|
|
61
|
+
|
|
62
|
+
def setup_test_with_cucumber
|
|
63
|
+
require_dependencies 'cucumber', :group => 'test'
|
|
64
|
+
require_dependencies 'capybara', :group => 'test'
|
|
65
|
+
insert_test_suite_setup CUCUMBER_SETUP, :path => "features/support/env.rb"
|
|
66
|
+
create_file destination_root("features/add.feature"), CUCUMBER_FEATURE
|
|
67
|
+
create_file destination_root("features/step_definitions/add_steps.rb"), CUCUMBER_STEP
|
|
68
|
+
create_file destination_root("cucumber.yml"), CUCUMBER_YML
|
|
69
|
+
setup_test_without_cucumber
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
alias_method_chain :setup_test, :cucumber
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
end
|
|
@@ -2,56 +2,67 @@ module Padrino
|
|
|
2
2
|
module Generators
|
|
3
3
|
module Components
|
|
4
4
|
module Tests
|
|
5
|
-
|
|
6
5
|
module RspecGen
|
|
7
|
-
RSPEC_SETUP = (<<-TEST).gsub(/^ {10}/, '')
|
|
8
|
-
Spec::Runner.configure do |conf|
|
|
9
|
-
conf.include Rack::Test::Methods
|
|
10
|
-
end
|
|
11
6
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
CLASS_NAME.tap { |app| app.use Rack::Session::Cookie }
|
|
17
|
-
# You can hanlde all padrino applications using instead:
|
|
18
|
-
# Padrino.application
|
|
19
|
-
end
|
|
20
|
-
TEST
|
|
7
|
+
unless defined?(RSPEC_SETUP)
|
|
8
|
+
RSPEC_SETUP = (<<-TEST).gsub(/^ {12}/, '')
|
|
9
|
+
PADRINO_ENV = 'test' unless defined?(PADRINO_ENV)
|
|
10
|
+
require File.dirname(__FILE__) + "/../config/boot"
|
|
21
11
|
|
|
22
|
-
|
|
23
|
-
|
|
12
|
+
Spec::Runner.configure do |conf|
|
|
13
|
+
conf.include Rack::Test::Methods
|
|
14
|
+
end
|
|
24
15
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
16
|
+
def app
|
|
17
|
+
# Sinatra < 1.0 always disable sessions for test env
|
|
18
|
+
# so if you need them it's necessary force the use
|
|
19
|
+
# of Rack::Session::Cookie
|
|
20
|
+
CLASS_NAME.tap { |app| app.use Rack::Session::Cookie }
|
|
21
|
+
# You can hanlde all padrino applications using instead:
|
|
22
|
+
# Padrino.application
|
|
28
23
|
end
|
|
24
|
+
TEST
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
unless defined?(RSPEC_CONTROLLER_TEST)
|
|
28
|
+
RSPEC_CONTROLLER_TEST = (<<-TEST).gsub(/^ {12}/, '')
|
|
29
|
+
require File.dirname(__FILE__) + '/../spec_helper.rb'
|
|
29
30
|
|
|
30
|
-
|
|
31
|
-
|
|
31
|
+
describe "!NAME!Controller" do
|
|
32
|
+
before do
|
|
33
|
+
get "/"
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
it "returns hello world" do
|
|
37
|
+
last_response.body.should == "Hello World"
|
|
38
|
+
end
|
|
32
39
|
end
|
|
40
|
+
TEST
|
|
33
41
|
end
|
|
34
|
-
TEST
|
|
35
42
|
|
|
36
|
-
|
|
37
|
-
|
|
43
|
+
unless defined?(RSPEC_RAKE)
|
|
44
|
+
RSPEC_RAKE = (<<-TEST).gsub(/^ {12}/, '')
|
|
45
|
+
require 'spec/rake/spectask'
|
|
38
46
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
47
|
+
Spec::Rake::SpecTask.new(:spec) do |t|
|
|
48
|
+
t.spec_opts = ['--options', "spec/spec.opts"]
|
|
49
|
+
t.spec_files = Dir['**/*_spec.rb']
|
|
50
|
+
end
|
|
51
|
+
TEST
|
|
42
52
|
end
|
|
43
|
-
TEST
|
|
44
53
|
|
|
45
|
-
|
|
46
|
-
|
|
54
|
+
unless defined?(RSPEC_MODEL_TEST)
|
|
55
|
+
RSPEC_MODEL_TEST = (<<-TEST).gsub(/^ {12}/, '')
|
|
56
|
+
require File.dirname(__FILE__) + '/../spec_helper.rb'
|
|
47
57
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
58
|
+
describe "!NAME! Model" do
|
|
59
|
+
it 'can be created' do
|
|
60
|
+
@!DNAME! = !NAME!.new
|
|
61
|
+
@!DNAME!.should_not be_nil
|
|
62
|
+
end
|
|
52
63
|
end
|
|
64
|
+
TEST
|
|
53
65
|
end
|
|
54
|
-
TEST
|
|
55
66
|
|
|
56
67
|
def setup_test
|
|
57
68
|
require_dependencies 'rspec', :require => 'spec', :group => 'test'
|
|
@@ -25,10 +25,10 @@ module Padrino
|
|
|
25
25
|
class_option :dev, :desc => "Use padrino from a git checkout", :default => false, :type => :boolean
|
|
26
26
|
|
|
27
27
|
# Definitions for the available customizable components
|
|
28
|
-
component_option :orm, "database engine", :aliases => '-d', :choices => [:datamapper, :mongomapper, :
|
|
29
|
-
component_option :test, "testing framework", :aliases => '-t', :choices => [:rspec, :shoulda, :bacon, :testspec, :riot]
|
|
28
|
+
component_option :orm, "database engine", :aliases => '-d', :choices => [:activerecord, :datamapper, :mongomapper, :mongoid, :sequel, :couchrest], :default => :none
|
|
29
|
+
component_option :test, "testing framework", :aliases => '-t', :choices => [:rspec, :shoulda, :cucumber, :bacon, :testspec, :riot]
|
|
30
30
|
component_option :mock, "mocking library", :aliases => '-m', :choices => [:mocha, :rr], :default => :none
|
|
31
|
-
component_option :script, "javascript library", :aliases => '-s', :choices => [:jquery, :prototype, :rightjs], :default => :none
|
|
31
|
+
component_option :script, "javascript library", :aliases => '-s', :choices => [:jquery, :prototype, :rightjs, :mootools], :default => :none
|
|
32
32
|
component_option :renderer, "template engine", :aliases => '-e', :choices => [:haml, :erb]
|
|
33
33
|
|
|
34
34
|
# Show help if no argv given
|