padrino-gen 0.8.1 → 0.8.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.
Files changed (32) hide show
  1. data/README.rdoc +5 -5
  2. data/VERSION +1 -1
  3. data/bin/padrino-gen +2 -1
  4. data/lib/padrino-gen/generators/actions.rb +12 -3
  5. data/lib/padrino-gen/generators/app.rb +1 -4
  6. data/lib/padrino-gen/{generators.rb → generators/cli.rb} +13 -34
  7. data/lib/padrino-gen/generators/components/actions.rb +2 -2
  8. data/lib/padrino-gen/generators/components/mocks/mocha_gen.rb +11 -7
  9. data/lib/padrino-gen/generators/components/mocks/rr_gen.rb +12 -10
  10. data/lib/padrino-gen/generators/components/orms/activerecord_gen.rb +3 -3
  11. data/lib/padrino-gen/generators/components/orms/datamapper_gen.rb +3 -3
  12. data/lib/padrino-gen/generators/components/orms/sequel_gen.rb +3 -3
  13. data/lib/padrino-gen/generators/components/tests/bacon_test_gen.rb +27 -12
  14. data/lib/padrino-gen/generators/components/tests/riot_test_gen.rb +33 -12
  15. data/lib/padrino-gen/generators/components/tests/rspec_test_gen.rb +33 -16
  16. data/lib/padrino-gen/generators/components/tests/shoulda_test_gen.rb +25 -10
  17. data/lib/padrino-gen/generators/components/tests/testspec_test_gen.rb +25 -10
  18. data/lib/padrino-gen/generators/controller.rb +1 -4
  19. data/lib/padrino-gen/generators/mailer.rb +1 -4
  20. data/lib/padrino-gen/generators/migration.rb +7 -6
  21. data/lib/padrino-gen/generators/model.rb +5 -5
  22. data/lib/padrino-gen/generators/project.rb +22 -9
  23. data/lib/padrino-gen/padrino-tasks/seed.rb +7 -0
  24. data/lib/padrino-gen.rb +63 -3
  25. data/padrino-gen.gemspec +7 -6
  26. data/test/helper.rb +0 -1
  27. data/test/test_cli.rb +1 -3
  28. data/test/test_controller_generator.rb +2 -12
  29. data/test/test_migration_generator.rb +5 -0
  30. data/test/test_model_generator.rb +9 -4
  31. data/test/test_project_generator.rb +21 -8
  32. metadata +5 -4
data/README.rdoc CHANGED
@@ -49,11 +49,11 @@ You can also instruct the generator to skip a certain component to avoid using o
49
49
 
50
50
  The available components and their default options are listed below:
51
51
 
52
- * test: <tt>bacon</tt> (default), <tt>shoulda</tt>, <tt>rspec</tt>, <tt>testspec</tt>, <tt>riot</tt>
53
- * renderer: <tt>haml</tt> (default), <tt>erb</tt>
54
- * mock: <tt>mocha</tt> (default), <tt>rr</tt>
55
- * script: <tt>jquery</tt> (default), <tt>prototype</tt>, <tt>rightjs</tt>
56
- * orm: <tt>datamapper</tt> (default), <tt>mongomapper</tt>, <tt>activerecord</tt>, <tt>sequel</tt>, <tt>couchrest</tt>
52
+ test:: rspec (default), bacon, shoulda, testspec, riot
53
+ renderer:: haml (default), erb
54
+ mock:: none (default), rr
55
+ script:: none (default), prototype, rightjs
56
+ orm:: none (default), mongomapper, activerecord, sequel, couchrest
57
57
 
58
58
  The generator uses the <tt>bundler</tt> gem to resolve any application dependencies when the application is newly created.
59
59
  The necessary bundler command can be executed automatically through the generator with
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.8.1
1
+ 0.8.2
data/bin/padrino-gen CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
- %w[rubygems thor/group].each { |gem| require gem }
2
+ require 'rubygems'
3
3
  $:.unshift File.dirname(__FILE__) + "/../lib"
4
4
 
5
5
  # We try to load the vendored padrino-core if exist
@@ -8,6 +8,7 @@ if File.exist?(File.dirname(__FILE__) + "/../../padrino-core/lib")
8
8
  end
9
9
 
10
10
  require 'padrino-gen'
11
+ require 'padrino-gen/generators/cli'
11
12
 
12
13
  # We need our config boot because we need to load registered generators so:
13
14
  Padrino::Generators::Cli.start(ARGV)
@@ -28,7 +28,7 @@ module Padrino
28
28
  # include_component_module_for(:mock, 'rr')
29
29
  def include_component_module_for(component, choice=nil)
30
30
  choice = fetch_component_choice(component) unless choice
31
- return if choice.to_s == 'none'
31
+ return false if choice.to_s == 'none'
32
32
  self.class.send(:include, generator_module_for(choice, component))
33
33
  end
34
34
 
@@ -130,7 +130,6 @@ module Padrino
130
130
  end
131
131
 
132
132
  module ClassMethods
133
-
134
133
  # Defines a class option to allow a component to be chosen and add to component type list
135
134
  # Also builds the available_choices hash of which component choices are supported
136
135
  # component_option :test, "Testing framework", :aliases => '-t', :choices => [:bacon, :shoulda]
@@ -141,6 +140,16 @@ module Padrino
141
140
  class_option name, :default => options[:default] || options[:choices].first, :aliases => options[:aliases], :desc => description
142
141
  end
143
142
 
143
+ # Tell to padrino that for this Thor::Group is necessary a task to run
144
+ def require_arguments!
145
+ @_require_arguments = true
146
+ end
147
+
148
+ # Return true if we need an arguments for our Thor::Group
149
+ def require_arguments?
150
+ @_require_arguments
151
+ end
152
+
144
153
  # Returns the compiled list of component types which can be specified
145
154
  def component_types
146
155
  @component_types
@@ -153,4 +162,4 @@ module Padrino
153
162
  end
154
163
  end
155
164
  end
156
- end
165
+ end
@@ -22,10 +22,7 @@ module Padrino
22
22
  class_option :destroy, :aliases => '-d', :default => false, :type => :boolean
23
23
 
24
24
  # Show help if no argv given
25
- def self.start(given_args=ARGV, config={})
26
- given_args = ["-h"] if given_args.empty?
27
- super
28
- end
25
+ require_arguments!
29
26
 
30
27
  # Copies over the Padrino base admin application
31
28
  def create_app
@@ -1,31 +1,12 @@
1
+ require 'thor/group'
2
+ require 'padrino-core/support_lite'
3
+
1
4
  module Padrino
2
5
  module Generators
3
-
4
- DEV_PATH = File.expand_path("../../../", File.dirname(__FILE__))
5
-
6
- class << self
7
- def load_paths
8
- @load_paths ||= Dir[File.dirname(__FILE__) + '/generators/{project,app,mailer,controller,model,migration}.rb']
9
- end
10
-
11
- def mappings
12
- @mappings ||= SupportLite::OrderedHash.new
13
- end
14
-
15
- def add_generator(name, klass)
16
- mappings[name] = klass
17
- end
18
-
19
- def setup!
20
- require 'padrino-gen/generators/actions'
21
- Dir[File.dirname(__FILE__) + '/generators/{components}/**/*.rb'].each { |lib| require lib }
22
- end
23
-
24
- def lockup!
25
- load_paths.each { |lib| require lib }
26
- end
27
- end
28
-
6
+ ##
7
+ # This class bootstrap +config/boot+ and perform +Padrino::Generators.lockup!+ for handle
8
+ # 3rd party generators
9
+ #
29
10
  class Cli < Thor::Group
30
11
 
31
12
  # Include related modules
@@ -36,8 +17,6 @@ module Padrino
36
17
  # We need to TRY to load boot because some of our app dependencies maybe have
37
18
  # custom generators, so is necessary know who are.
38
19
  def load_boot
39
- Padrino::Generators.setup!
40
-
41
20
  begin
42
21
  ENV['PADRINO_LOG_LEVEL'] ||= "test"
43
22
  if options[:root]
@@ -47,6 +26,7 @@ module Padrino
47
26
  end
48
27
  rescue Exception => e
49
28
  puts "=> Problem loading config/boot.rb"
29
+ puts ["=> #{e.message}", *e.backtrace].join("\n ")
50
30
  end
51
31
  end
52
32
 
@@ -57,13 +37,12 @@ module Padrino
57
37
  generator_class = Padrino::Generators.mappings[generator_kind]
58
38
 
59
39
  if generator_class
60
- generator_class.start(ARGV)
40
+ args = ARGV.empty? && generator_class.require_arguments? ? ["-h"] : ARGV
41
+ generator_class.start(args)
61
42
  else
62
43
  puts "Please specify generator to use (#{Padrino::Generators.mappings.keys.join(", ")})"
63
44
  end
64
45
  end
65
-
66
- end
67
-
68
- end
69
- end
46
+ end # Cli
47
+ end # Generators
48
+ end # Padrino
@@ -33,8 +33,8 @@ module Padrino
33
33
  # For orm database components
34
34
  # Generates a standalone migration file based on the given options and columns
35
35
  # options => { :base "...text...", :change_format => "...text...",
36
- # :add => lambda { |field, kind| "add_column :#{table_name}, :#{field}, :#{kind}" },
37
- # :remove => lambda { |field, kind| "remove_column :#{table_name}, :#{field}" }
36
+ # :add => proc { |field, kind| "add_column :#{table_name}, :#{field}, :#{kind}" },
37
+ # :remove => proc { |field, kind| "remove_column :#{table_name}, :#{field}" }
38
38
  def output_migration_file(filename, name, columns, options={})
39
39
  if behavior == :revoke
40
40
  remove_migration(name)
@@ -6,11 +6,15 @@ module Padrino
6
6
  module MochaGen
7
7
  def setup_mock
8
8
  require_dependencies 'mocha', :group => 'test'
9
- insert_mocking_include "Mocha::API", :path => "test/test_config.rb"
9
+ case options[:test].to_s
10
+ when 'rspec'
11
+ inject_into_file 'spec/spec_helper.rb', " conf.mock_with :mocha\n", :after => "Spec::Runner.configure do |conf|\n"
12
+ else
13
+ insert_mocking_include "Mocha::API"
14
+ end
10
15
  end
11
- end
12
-
13
- end
14
- end
15
- end
16
- end
16
+ end # MochaGen
17
+ end # Mocks
18
+ end # Components
19
+ end # Generators
20
+ end # Padrino
@@ -6,15 +6,17 @@ module Padrino
6
6
  module RrGen
7
7
  def setup_mock
8
8
  require_dependencies 'rr', :group => 'test'
9
- if options[:test] == 'riot'
10
- inject_into_file "test/test_config.rb"," Riot.rr\n", :after => "class Riot::Situation\n"
11
- else
12
- insert_mocking_include "RR::Adapters::RRMethods", :path => "test/test_config.rb"
9
+ case options[:test].to_s
10
+ when 'rspec'
11
+ inject_into_file 'spec/spec_helper.rb', " conf.mock_with :rr\n", :after => "Spec::Runner.configure do |conf|\n"
12
+ when 'riot'
13
+ inject_into_file "test/test_config.rb"," Riot.rr\n", :after => "class Riot::Situation\n"
14
+ else
15
+ insert_mocking_include "RR::Adapters::RRMethods", :path => "test/test_config.rb"
13
16
  end
14
17
  end
15
- end
16
-
17
- end
18
- end
19
- end
20
- end
18
+ end # RrGen
19
+ end # Mocks
20
+ end # Components
21
+ end # Generators
22
+ end # Padrino
@@ -100,7 +100,7 @@ module Padrino
100
100
  def create_model_migration(migration_name, name, columns)
101
101
  output_model_migration(migration_name, name, columns,
102
102
  :base => AR_MIGRATION,
103
- :column_format => lambda { |field, kind| "t.#{kind.underscore.gsub(/_/, '')} :#{field}" },
103
+ :column_format => Proc.new { |field, kind| "t.#{kind.underscore.gsub(/_/, '')} :#{field}" },
104
104
  :up => AR_MODEL_UP_MG, :down => AR_MODEL_DOWN_MG)
105
105
  end
106
106
 
@@ -113,8 +113,8 @@ module Padrino
113
113
  def create_migration_file(migration_name, name, columns)
114
114
  output_migration_file(migration_name, name, columns,
115
115
  :base => AR_MIGRATION, :change_format => AR_CHANGE_MG,
116
- :add => lambda { |field, kind| "t.#{kind.underscore.gsub(/_/, '')} :#{field}" },
117
- :remove => lambda { |field, kind| "t.remove :#{field}" })
116
+ :add => Proc.new { |field, kind| "t.#{kind.underscore.gsub(/_/, '')} :#{field}" },
117
+ :remove => Proc.new { |field, kind| "t.remove :#{field}" })
118
118
  end
119
119
 
120
120
  end
@@ -73,7 +73,7 @@ module Padrino
73
73
 
74
74
  def create_model_migration(migration_name, name, columns)
75
75
  output_model_migration(migration_name, name, columns,
76
- :column_format => lambda { |field, kind| "column :#{field}, #{kind.camelize}" },
76
+ :column_format => Proc.new { |field, kind| "column :#{field}, #{kind.camelize}" },
77
77
  :base => DM_MIGRATION, :up => DM_MODEL_UP_MG, :down => DM_MODEL_DOWN_MG)
78
78
  end
79
79
 
@@ -86,8 +86,8 @@ module Padrino
86
86
  def create_migration_file(migration_name, name, columns)
87
87
  output_migration_file(migration_name, name, columns,
88
88
  :base => DM_MIGRATION, :change_format => DM_CHANGE_MG,
89
- :add => lambda { |field, kind| "add_column :#{field}, #{kind.camelize}" },
90
- :remove => lambda { |field, kind| "drop_column :#{field}" }
89
+ :add => Proc.new { |field, kind| "add_column :#{field}, #{kind.camelize}" },
90
+ :remove => Proc.new { |field, kind| "drop_column :#{field}" }
91
91
  )
92
92
  end
93
93
  end
@@ -59,7 +59,7 @@ module Padrino
59
59
 
60
60
  def create_model_migration(migration_name, name, columns)
61
61
  output_model_migration(migration_name, name, columns,
62
- :column_format => lambda { |field, kind| "#{kind.camelize} :#{field}" },
62
+ :column_format => Proc.new { |field, kind| "#{kind.camelize} :#{field}" },
63
63
  :base => SQ_MIGRATION, :up => SQ_MODEL_UP_MG, :down => SQ_MODEL_DOWN_MG)
64
64
  end
65
65
 
@@ -72,8 +72,8 @@ module Padrino
72
72
  def create_migration_file(migration_name, name, columns)
73
73
  output_migration_file(migration_name, name, columns,
74
74
  :base => SQ_MIGRATION, :change_format => SQ_CHANGE_MG,
75
- :add => lambda { |field, kind| "add_column :#{field}, #{kind.camelize}" },
76
- :remove => lambda { |field, kind| "drop_column :#{field}" }
75
+ :add => Proc.new { |field, kind| "add_column :#{field}, #{kind.camelize}" },
76
+ :remove => Proc.new { |field, kind| "drop_column :#{field}" }
77
77
  )
78
78
  end
79
79
  end
@@ -10,32 +10,34 @@ module Padrino
10
10
  end
11
11
 
12
12
  def app
13
- CLASS_NAME.tap { |app| app.set :environment, :test }
13
+ # Sinatra < 1.0 always disable sessions for test env
14
+ # so if you need them it's necessary force the use
15
+ # of Rack::Session::Cookie
16
+ CLASS_NAME.tap { |app| app.use Rack::Session::Cookie }
17
+ # You can hanlde all padrino applications using instead:
18
+ # Padrino.application
14
19
  end
15
20
  TEST
16
21
 
17
- # Setup the testing configuration helper and dependencies
18
- def setup_test
19
- require_dependencies 'bacon', :group => 'test'
20
- insert_test_suite_setup BACON_SETUP
21
- end
22
-
23
22
  BACON_CONTROLLER_TEST = (<<-TEST).gsub(/^ {10}/, '')
24
23
  require File.dirname(__FILE__) + '/../test_config.rb'
25
24
 
26
25
  describe "!NAME!Controller" do
27
26
  it 'returns text at root' do
28
- get '/'
27
+ get "/"
29
28
  last_response.body.should == "some text"
30
29
  end
31
30
  end
32
31
  TEST
33
32
 
34
- # Generates a controller test given the controllers name
35
- def generate_controller_test(name)
36
- bacon_contents = BACON_CONTROLLER_TEST.gsub(/!NAME!/, name.to_s.camelize)
37
- create_file destination_root("test/controllers/","#{name}_controller_test.rb"), bacon_contents, :skip => true
33
+ BACON_RAKE = (<<-TEST).gsub(/^ {10}/, '')
34
+ require 'rake/testtask'
35
+
36
+ Rake::TestTask.new(:test) do |test|
37
+ test.pattern = '**/*_test.rb'
38
+ test.verbose = true
38
39
  end
40
+ TEST
39
41
 
40
42
  BACON_MODEL_TEST = (<<-TEST).gsub(/^ {10}/, '')
41
43
  require File.dirname(__FILE__) + '/../test_config.rb'
@@ -48,6 +50,19 @@ module Padrino
48
50
  end
49
51
  TEST
50
52
 
53
+ # Setup the testing configuration helper and dependencies
54
+ def setup_test
55
+ require_dependencies 'bacon', :group => 'test'
56
+ insert_test_suite_setup BACON_SETUP, :path => 'test/test_config.rb'
57
+ create_file destination_root("test/test.rake"), BACON_RAKE
58
+ end
59
+
60
+ # Generates a controller test given the controllers name
61
+ def generate_controller_test(name)
62
+ bacon_contents = BACON_CONTROLLER_TEST.gsub(/!NAME!/, name.to_s.camelize)
63
+ create_file destination_root("test/controllers/","#{name}_controller_test.rb"), bacon_contents, :skip => true
64
+ end
65
+
51
66
  def generate_model_test(name)
52
67
  bacon_contents = BACON_MODEL_TEST.gsub(/!NAME!/, name.to_s.camelize).gsub(/!DNAME!/, name.downcase.underscore)
53
68
  create_file destination_root("test/models/#{name.to_s.downcase}_test.rb"), bacon_contents, :skip => true
@@ -9,44 +9,65 @@ module Padrino
9
9
  include Rack::Test::Methods
10
10
 
11
11
  def app
12
- CLASS_NAME.tap { |app| app.set :environment, :test }
12
+ # Sinatra < 1.0 always disable sessions for test env
13
+ # so if you need them it's necessary force the use
14
+ # of Rack::Session::Cookie
15
+ CLASS_NAME.tap { |app| app.use Rack::Session::Cookie }
16
+ # You can hanlde all padrino applications using instead:
17
+ # Padrino.application
13
18
  end
14
19
  end
15
20
  TEST
16
21
 
17
- def setup_test
18
- require_dependencies 'riot', :group => 'test'
19
- insert_test_suite_setup RIOT_SETUP
20
- end
21
-
22
22
  RIOT_CONTROLLER_TEST = (<<-TEST).gsub(/^ {10}/, '')
23
23
  require File.dirname(__FILE__) + '/../test_config.rb'
24
24
 
25
25
  context "!NAME!Controller" do
26
26
  context "description here" do
27
- setup { get '/' }
27
+ setup do
28
+ get "/"
29
+ end
30
+
28
31
  asserts("the response body") { last_response.body }.equals "Hello World"
29
32
  end
30
33
  end
31
34
  TEST
32
35
 
33
- # Generates a controller test given the controllers name
34
- def generate_controller_test(name)
35
- riot_contents = RIOT_CONTROLLER_TEST.gsub(/!NAME!/, name.to_s.camelize)
36
- create_file destination_root("test/controllers/#{name}_controller_test.rb"), riot_contents, :skip => true
36
+ RIOT_RAKE = (<<-TEST).gsub(/^ {10}/, '')
37
+ require 'rake/testtask'
38
+
39
+ Rake::TestTask.new(:test) do |test|
40
+ test.pattern = '**/*_test.rb'
41
+ test.verbose = true
37
42
  end
43
+ TEST
38
44
 
39
45
  RIOT_MODEL_TEST = (<<-TEST).gsub(/^ {10}/, '')
40
46
  require File.dirname(__FILE__) + '/../test_config.rb'
41
47
 
42
48
  context "!NAME! Model" do
43
49
  context 'can be created' do
44
- setup { @!DNAME! = !NAME!.new }
50
+ setup do
51
+ @!DNAME! = !NAME!.new
52
+ end
53
+
45
54
  asserts("that record is not nil") { !@!DNAME!.nil? }
46
55
  end
47
56
  end
48
57
  TEST
49
58
 
59
+ def setup_test
60
+ require_dependencies 'riot', :group => 'test'
61
+ insert_test_suite_setup RIOT_SETUP
62
+ create_file destination_root("test/test.rake"), RIOT_RAKE
63
+ end
64
+
65
+ # Generates a controller test given the controllers name
66
+ def generate_controller_test(name)
67
+ riot_contents = RIOT_CONTROLLER_TEST.gsub(/!NAME!/, name.to_s.camelize)
68
+ create_file destination_root("test/controllers/#{name}_controller_test.rb"), riot_contents, :skip => true
69
+ end
70
+
50
71
  def generate_model_test(name)
51
72
  riot_contents = RIOT_MODEL_TEST.gsub(/!NAME!/, name.to_s.camelize).gsub(/!DNAME!/, name.downcase.underscore)
52
73
  create_file destination_root("test/models/#{name.to_s.downcase}_test.rb"), riot_contents, :skip => true
@@ -10,36 +10,40 @@ module Padrino
10
10
  end
11
11
 
12
12
  def app
13
- CLASS_NAME.tap { |app| app.set :environment, :test }
13
+ # Sinatra < 1.0 always disable sessions for test env
14
+ # so if you need them it's necessary force the use
15
+ # of Rack::Session::Cookie
16
+ CLASS_NAME.tap { |app| app.use Rack::Session::Cookie }
17
+ # You can hanlde all padrino applications using instead:
18
+ # Padrino.application
14
19
  end
15
20
  TEST
16
21
 
17
- # TODO move to spec directory to follow convention
18
- def setup_test
19
- require_dependencies 'rspec', :group => 'test', :require => 'spec'
20
- insert_test_suite_setup RSPEC_SETUP
21
- end
22
-
23
22
  RSPEC_CONTROLLER_TEST = (<<-TEST).gsub(/^ {10}/, '')
24
- require File.dirname(__FILE__) + '/../test_config.rb'
23
+ require File.dirname(__FILE__) + '/../spec_helper.rb'
25
24
 
26
25
  describe "!NAME!Controller" do
27
- setup { get('/') }
26
+ before do
27
+ get "/"
28
+ end
29
+
28
30
  it "returns hello world" do
29
31
  last_response.body.should == "Hello World"
30
32
  end
31
33
  end
32
34
  TEST
33
35
 
34
- # TODO move to spec directory to follow convention
35
- # Generates a controller test given the controllers name
36
- def generate_controller_test(name)
37
- rspec_contents = RSPEC_CONTROLLER_TEST.gsub(/!NAME!/, name.to_s.camelize)
38
- create_file destination_root("test/controllers/#{name}_controller_spec.rb"), rspec_contents, :skip => true
36
+ RSPEC_RAKE = (<<-TEST).gsub(/^ {10}/, '')
37
+ require 'spec/rake/spectask'
38
+
39
+ Spec::Rake::SpecTask.new(:spec) do |t|
40
+ t.spec_opts = ['--options', "spec/spec.opts"]
41
+ t.spec_files = Dir['**/*_spec.rb']
39
42
  end
43
+ TEST
40
44
 
41
45
  RSPEC_MODEL_TEST = (<<-TEST).gsub(/^ {10}/, '')
42
- require File.dirname(__FILE__) + '/../test_config.rb'
46
+ require File.dirname(__FILE__) + '/../spec_helper.rb'
43
47
 
44
48
  describe "!NAME! Model" do
45
49
  it 'can be created' do
@@ -49,9 +53,22 @@ module Padrino
49
53
  end
50
54
  TEST
51
55
 
56
+ def setup_test
57
+ require_dependencies 'rspec', :require => 'spec', :group => 'test'
58
+ insert_test_suite_setup RSPEC_SETUP, :path => "spec/spec_helper.rb"
59
+ create_file destination_root("spec/spec.rake"), RSPEC_RAKE
60
+ create_file destination_root("spec/spec.opts"), "--color"
61
+ end
62
+
63
+ # Generates a controller test given the controllers name
64
+ def generate_controller_test(name)
65
+ rspec_contents = RSPEC_CONTROLLER_TEST.gsub(/!NAME!/, name.to_s.camelize)
66
+ create_file destination_root("spec/controllers/#{name}_controller_spec.rb"), rspec_contents, :skip => true
67
+ end
68
+
52
69
  def generate_model_test(name)
53
70
  rspec_contents = RSPEC_MODEL_TEST.gsub(/!NAME!/, name.to_s.camelize).gsub(/!DNAME!/, name.downcase.underscore)
54
- create_file destination_root("test/models/#{name.to_s.downcase}_spec.rb"), rspec_contents, :skip => true
71
+ create_file destination_root("spec/models/#{name.to_s.downcase}_spec.rb"), rspec_contents, :skip => true
55
72
  end
56
73
 
57
74
  end
@@ -9,16 +9,16 @@ module Padrino
9
9
  include Rack::Test::Methods
10
10
 
11
11
  def app
12
- CLASS_NAME.tap { |app| app.set :environment, :test }
12
+ # Sinatra < 1.0 always disable sessions for test env
13
+ # so if you need them it's necessary force the use
14
+ # of Rack::Session::Cookie
15
+ CLASS_NAME.tap { |app| app.use Rack::Session::Cookie }
16
+ # You can hanlde all padrino applications using instead:
17
+ # Padrino.application
13
18
  end
14
19
  end
15
20
  TEST
16
21
 
17
- def setup_test
18
- require_dependencies 'shoulda', :group => 'test'
19
- insert_test_suite_setup SHOULDA_SETUP
20
- end
21
-
22
22
  SHOULDA_CONTROLLER_TEST = (<<-TEST).gsub(/^ {10}/, '')
23
23
  require File.dirname(__FILE__) + '/../test_config.rb'
24
24
 
@@ -35,11 +35,14 @@ module Padrino
35
35
  end
36
36
  TEST
37
37
 
38
- # Generates a controller test given the controllers name
39
- def generate_controller_test(name)
40
- shoulda_contents = SHOULDA_CONTROLLER_TEST.gsub(/!NAME!/, name.to_s.camelize)
41
- create_file destination_root("test/controllers/#{name}_controller_test.rb"), shoulda_contents, :skip => true
38
+ SHOULDA_RAKE = (<<-TEST).gsub(/^ {10}/, '')
39
+ require 'rake/testtask'
40
+
41
+ Rake::TestTask.new(:test) do |test|
42
+ test.pattern = '**/*_test.rb'
43
+ test.verbose = true
42
44
  end
45
+ TEST
43
46
 
44
47
  SHOULDA_MODEL_TEST = (<<-TEST).gsub(/^ {10}/, '')
45
48
  require File.dirname(__FILE__) + '/../test_config.rb'
@@ -54,6 +57,18 @@ module Padrino
54
57
  end
55
58
  TEST
56
59
 
60
+ def setup_test
61
+ require_dependencies 'shoulda', :group => 'test'
62
+ insert_test_suite_setup SHOULDA_SETUP
63
+ create_file destination_root("test/test.rake"), SHOULDA_RAKE
64
+ end
65
+
66
+ # Generates a controller test given the controllers name
67
+ def generate_controller_test(name)
68
+ shoulda_contents = SHOULDA_CONTROLLER_TEST.gsub(/!NAME!/, name.to_s.camelize)
69
+ create_file destination_root("test/controllers/#{name}_controller_test.rb"), shoulda_contents, :skip => true
70
+ end
71
+
57
72
  def generate_model_test(name)
58
73
  shoulda_contents = SHOULDA_MODEL_TEST.gsub(/!NAME!/, name.to_s.camelize).gsub(/!DNAME!/, name.downcase.underscore)
59
74
  create_file destination_root("test/models/#{name.to_s.downcase}_test.rb"), shoulda_contents, :skip => true
@@ -9,16 +9,16 @@ module Padrino
9
9
  include Rack::Test::Methods
10
10
 
11
11
  def app
12
- CLASS_NAME.tap { |app| app.set :environment, :test }
12
+ # Sinatra < 1.0 always disable sessions for test env
13
+ # so if you need them it's necessary force the use
14
+ # of Rack::Session::Cookie
15
+ CLASS_NAME.tap { |app| app.use Rack::Session::Cookie }
16
+ # You can hanlde all padrino applications using instead:
17
+ # Padrino.application
13
18
  end
14
19
  end
15
20
  TEST
16
21
 
17
- def setup_test
18
- require_dependencies 'test/spec', :group => 'test'
19
- insert_test_suite_setup TESTSPEC_SETUP
20
- end
21
-
22
22
  TESTSPEC_CONTROLLER_TEST = (<<-TEST).gsub(/^ {10}/, '')
23
23
  require File.dirname(__FILE__) + '/../test_config.rb'
24
24
 
@@ -30,11 +30,14 @@ module Padrino
30
30
  end
31
31
  TEST
32
32
 
33
- # Generates a controller test given the controllers name
34
- def generate_controller_test(name)
35
- testspec_contents = TESTSPEC_CONTROLLER_TEST.gsub(/!NAME!/, name.to_s.camelize)
36
- create_file destination_root("test/controllers/#{name}_controller_test.rb"), testspec_contents, :skip => true
33
+ TESTSPEC_RAKE = (<<-TEST).gsub(/^ {10}/, '')
34
+ require 'rake/testtask'
35
+
36
+ Rake::TestTask.new(:test) do |test|
37
+ test.pattern = '**/*_test.rb'
38
+ test.verbose = true
37
39
  end
40
+ TEST
38
41
 
39
42
  TESTSPEC_MODEL_TEST = (<<-TEST).gsub(/^ {10}/, '')
40
43
  require File.dirname(__FILE__) + '/../test_config.rb'
@@ -47,6 +50,18 @@ module Padrino
47
50
  end
48
51
  TEST
49
52
 
53
+ def setup_test
54
+ require_dependencies 'test-spec', :require => 'test/spec', :group => 'test'
55
+ insert_test_suite_setup TESTSPEC_SETUP
56
+ create_file destination_root("test/test.rake"), TESTSPEC_RAKE
57
+ end
58
+
59
+ # Generates a controller test given the controllers name
60
+ def generate_controller_test(name)
61
+ testspec_contents = TESTSPEC_CONTROLLER_TEST.gsub(/!NAME!/, name.to_s.camelize)
62
+ create_file destination_root("test/controllers/#{name}_controller_test.rb"), testspec_contents, :skip => true
63
+ end
64
+
50
65
  def generate_model_test(name)
51
66
  tests_contents = TESTSPEC_MODEL_TEST.gsub(/!NAME!/, name.to_s.camelize).gsub(/!DNAME!/, name.downcase.underscore)
52
67
  create_file destination_root("test/models/#{name.to_s.downcase}_test.rb"), tests_contents, :skip => true
@@ -24,10 +24,7 @@ module Padrino
24
24
  class_option :destroy, :aliases => '-d', :default => false, :type => :boolean
25
25
 
26
26
  # Show help if no argv given
27
- def self.start(given_args=ARGV, config={})
28
- given_args = ["-h"] if given_args.empty?
29
- super
30
- end
27
+ require_arguments!
31
28
 
32
29
  def create_controller
33
30
  self.destination_root = options[:root]
@@ -23,10 +23,7 @@ module Padrino
23
23
  class_option :destroy, :aliases => '-d', :default => false, :type => :boolean
24
24
 
25
25
  # Show help if no argv given
26
- def self.start(given_args=ARGV, config={})
27
- given_args = ["-h"] if given_args.empty?
28
- super
29
- end
26
+ require_arguments!
30
27
 
31
28
  def create_mailer
32
29
  self.destination_root = options[:root]
@@ -23,17 +23,18 @@ module Padrino
23
23
  class_option :destroy, :aliases => '-d', :default => false, :type => :boolean
24
24
 
25
25
  # Show help if no argv given
26
- def self.start(given_args=ARGV, config={})
27
- given_args = ["-h"] if given_args.empty?
28
- super
29
- end
26
+ require_arguments!
30
27
 
31
28
  def create_migration
32
29
  self.destination_root = options[:root]
33
30
  if in_app_root?
34
31
  self.behavior = :revoke if options[:destroy]
35
- include_component_module_for(:orm)
36
- create_migration_file(name, name, columns)
32
+ if include_component_module_for(:orm)
33
+ create_migration_file(name, name, columns)
34
+ else
35
+ say "<= You need an ORM adapter for run this generator. Sorry!"
36
+ raise SystemExit
37
+ end
37
38
  else
38
39
  say "You are not at the root of a Padrino application! (config/boot.rb not found)" and return unless in_app_root?
39
40
  end
@@ -24,16 +24,16 @@ module Padrino
24
24
  class_option :skip_migration, :aliases => "-s", :default => false, :type => :boolean
25
25
 
26
26
  # Show help if no argv given
27
- def self.start(given_args=ARGV, config={})
28
- given_args = ["-h"] if given_args.empty?
29
- super
30
- end
27
+ require_arguments!
31
28
 
32
29
  def create_model
33
30
  self.destination_root = options[:root]
34
31
  if in_app_root?
35
32
  self.behavior = :revoke if options[:destroy]
36
- include_component_module_for(:orm)
33
+ unless include_component_module_for(:orm)
34
+ say "<= You need an ORM adapter for run this generator. Sorry!"
35
+ raise SystemExit
36
+ end
37
37
  include_component_module_for(:test)
38
38
  migration_name = "create_#{name.pluralize.underscore}"
39
39
  create_model_file(name, fields)
@@ -1,3 +1,5 @@
1
+ require 'padrino-core/version'
2
+
1
3
  module Padrino
2
4
  module Generators
3
5
  class Project < Thor::Group
@@ -18,22 +20,19 @@ module Padrino
18
20
 
19
21
  argument :name, :desc => "The name of your padrino project"
20
22
 
21
- class_option :run_bundler, :desc => "Run 'bundle install'", :aliases => '-b', :default => false, :type => :boolean
22
- class_option :root, :desc => "The root destination", :aliases => '-r', :default => ".", :type => :string
23
- class_option :dev, :desc => "Use padrino from a git checkout", :default => false, :type => :boolean
23
+ class_option :run_bundler, :desc => "Run bundle install", :aliases => '-b', :default => false, :type => :boolean
24
+ class_option :root, :desc => "The root destination", :aliases => '-r', :default => ".", :type => :string
25
+ class_option :dev, :desc => "Use padrino from a git checkout", :default => false, :type => :boolean
24
26
 
25
27
  # Definitions for the available customizable components
26
28
  component_option :orm, "database engine", :aliases => '-d', :choices => [:datamapper, :mongomapper, :activerecord, :sequel, :couchrest], :default => :none
27
- component_option :test, "testing framework", :aliases => '-t', :choices => [:bacon, :shoulda, :rspec, :testspec, :riot]
28
- component_option :mock, "mocking library", :aliases => '-m', :choices => [:mocha, :rr]
29
+ component_option :test, "testing framework", :aliases => '-t', :choices => [:rspec, :shoulda, :bacon, :testspec, :riot]
30
+ component_option :mock, "mocking library", :aliases => '-m', :choices => [:mocha, :rr], :default => :none
29
31
  component_option :script, "javascript library", :aliases => '-s', :choices => [:jquery, :prototype, :rightjs], :default => :none
30
32
  component_option :renderer, "template engine", :aliases => '-e', :choices => [:haml, :erb]
31
33
 
32
34
  # Show help if no argv given
33
- def self.start(given_args=ARGV, config={})
34
- given_args = ["-h"] if given_args.empty?
35
- super
36
- end
35
+ require_arguments!
37
36
 
38
37
  # Copies over the Padrino base application App
39
38
  def setup_project
@@ -59,6 +58,20 @@ module Padrino
59
58
  in_root { run 'bundle install' }
60
59
  end
61
60
  end
61
+
62
+ # Finish message
63
+ def finish
64
+ say (<<-TEXT).gsub(/ {8}/,'')
65
+
66
+ =================================================================
67
+ #{name} has been successfully created, now follow this steps:
68
+ =================================================================
69
+ 1) cd #{name}
70
+ 2) bundle install
71
+ =================================================================
72
+
73
+ TEXT
74
+ end
62
75
  end
63
76
  end
64
77
  end
@@ -0,0 +1,7 @@
1
+ if defined?(ActiveRecord) || defined?(DataMapper)
2
+ desc 'Load the seed data from db/seeds.rb'
3
+ task :seed => :environment do
4
+ seed_file = Padrino.root('db', 'seeds.rb')
5
+ load(seed_file) if File.exist?(seed_file)
6
+ end
7
+ end
data/lib/padrino-gen.rb CHANGED
@@ -1,6 +1,66 @@
1
- require 'thor/group'
2
1
  require 'padrino-core/support_lite'
3
- require 'padrino-core/version'
4
- require 'padrino-gen/generators'
5
2
  require 'padrino-core/tasks'
3
+
4
+ module Padrino
5
+ ##
6
+ # This module it's used for register generators
7
+ #
8
+ # Can be useful for 3rd party generators:
9
+ #
10
+ # # custom_generator.rb
11
+ # class CustomGenerator < Thor::Group
12
+ # Padrino::Generators.add_generator(:custom_generator, self)
13
+ # end
14
+ #
15
+ # Now for handle generators in padrino you need to add it to into +load_paths+
16
+ #
17
+ # Padrino::Generators.load_paths << "custom_generator.rb"
18
+ #
19
+ module Generators
20
+
21
+ DEV_PATH = File.expand_path("../../", File.dirname(__FILE__))
22
+
23
+ class << self
24
+
25
+ ##
26
+ # Here we store our generators paths
27
+ #
28
+ def load_paths
29
+ @_files ||= []
30
+ end
31
+
32
+ ##
33
+ # Return a ordered list of task with their class
34
+ #
35
+ def mappings
36
+ @_mappings ||= SupportLite::OrderedHash.new
37
+ end
38
+
39
+ ##
40
+ # Gloabl add a new generator class to +padrino-gen+
41
+ #
42
+ def add_generator(name, klass)
43
+ mappings[name] = klass
44
+ end
45
+
46
+ ##
47
+ # Load Global Actions and Component Actions then all files in +load_path+.
48
+ #
49
+ def lockup!
50
+ require 'padrino-gen/generators/actions'
51
+ Dir[File.dirname(__FILE__) + '/padrino-gen/generators/components/**/*.rb'].each { |lib| require lib }
52
+ load_paths.flatten.each { |file| require file }
53
+ end
54
+ end
55
+ end # Generators
56
+ end # Padrino
57
+
58
+ ##
59
+ # We add our generators to Padrino::Genererator
60
+ #
61
+ Padrino::Generators.load_paths << Dir[File.dirname(__FILE__) + '/padrino-gen/generators/{project,app,mailer,controller,model,migration}.rb']
62
+
63
+ ##
64
+ # We add our tasks to padrino-core
65
+ #
6
66
  Padrino::Tasks.files << Dir[File.dirname(__FILE__) + "/padrino-gen/padrino-tasks/**/*.rb"]
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.1"
8
+ s.version = "0.8.2"
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-14}
12
+ s.date = %q{2010-02-17}
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}
@@ -26,13 +26,13 @@ Gem::Specification.new do |s|
26
26
  "VERSION",
27
27
  "bin/padrino-gen",
28
28
  "lib/padrino-gen.rb",
29
- "lib/padrino-gen/generators.rb",
30
29
  "lib/padrino-gen/generators/actions.rb",
31
30
  "lib/padrino-gen/generators/app.rb",
32
31
  "lib/padrino-gen/generators/app/app.rb.tt",
33
32
  "lib/padrino-gen/generators/app/controllers/.empty_directory",
34
33
  "lib/padrino-gen/generators/app/helpers/.empty_directory",
35
34
  "lib/padrino-gen/generators/app/views/.empty_directory",
35
+ "lib/padrino-gen/generators/cli.rb",
36
36
  "lib/padrino-gen/generators/components/actions.rb",
37
37
  "lib/padrino-gen/generators/components/mocks/mocha_gen.rb",
38
38
  "lib/padrino-gen/generators/components/mocks/rr_gen.rb",
@@ -83,6 +83,7 @@ Gem::Specification.new do |s|
83
83
  "lib/padrino-gen/padrino-tasks/activerecord.rb",
84
84
  "lib/padrino-gen/padrino-tasks/datamapper.rb",
85
85
  "lib/padrino-gen/padrino-tasks/locale.rb",
86
+ "lib/padrino-gen/padrino-tasks/seed.rb",
86
87
  "padrino-gen.gemspec",
87
88
  "test/helper.rb",
88
89
  "test/test_app_generator.rb",
@@ -107,7 +108,7 @@ Gem::Specification.new do |s|
107
108
 
108
109
  if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
109
110
  s.add_runtime_dependency(%q<sinatra>, [">= 0.9.2"])
110
- s.add_runtime_dependency(%q<padrino-core>, ["= 0.8.1"])
111
+ s.add_runtime_dependency(%q<padrino-core>, ["= 0.8.2"])
111
112
  s.add_runtime_dependency(%q<thor>, [">= 0.13.0"])
112
113
  s.add_runtime_dependency(%q<bundler>, [">= 0.9.3"])
113
114
  s.add_development_dependency(%q<haml>, [">= 2.2.1"])
@@ -118,7 +119,7 @@ Gem::Specification.new do |s|
118
119
  s.add_development_dependency(%q<fakeweb>, [">= 1.2.3"])
119
120
  else
120
121
  s.add_dependency(%q<sinatra>, [">= 0.9.2"])
121
- s.add_dependency(%q<padrino-core>, ["= 0.8.1"])
122
+ s.add_dependency(%q<padrino-core>, ["= 0.8.2"])
122
123
  s.add_dependency(%q<thor>, [">= 0.13.0"])
123
124
  s.add_dependency(%q<bundler>, [">= 0.9.3"])
124
125
  s.add_dependency(%q<haml>, [">= 2.2.1"])
@@ -130,7 +131,7 @@ Gem::Specification.new do |s|
130
131
  end
131
132
  else
132
133
  s.add_dependency(%q<sinatra>, [">= 0.9.2"])
133
- s.add_dependency(%q<padrino-core>, ["= 0.8.1"])
134
+ s.add_dependency(%q<padrino-core>, ["= 0.8.2"])
134
135
  s.add_dependency(%q<thor>, [">= 0.13.0"])
135
136
  s.add_dependency(%q<bundler>, [">= 0.9.3"])
136
137
  s.add_dependency(%q<haml>, [">= 2.2.1"])
data/test/helper.rb CHANGED
@@ -15,7 +15,6 @@ end
15
15
 
16
16
  require 'padrino-gen'
17
17
 
18
- Padrino::Generators.setup!
19
18
  Padrino::Generators.lockup!
20
19
 
21
20
  class Test::Unit::TestCase
data/test/test_cli.rb CHANGED
@@ -1,10 +1,8 @@
1
1
  require File.dirname(__FILE__) + '/helper'
2
- require 'thor/group'
3
- require 'fakeweb'
2
+ require 'padrino-gen/generators/cli'
4
3
 
5
4
  class TestCli < Test::Unit::TestCase
6
5
  def setup
7
- FakeWeb.allow_net_connect = false
8
6
  `rm -rf /tmp/sample_project`
9
7
  @cli = Padrino::Generators::Cli.dup
10
8
  @project = Padrino::Generators::Project.dup
@@ -55,7 +55,7 @@ class TestControllerGenerator < Test::Unit::TestCase
55
55
  should "generate controller test for rspec" do
56
56
  silence_logger { @project.start(['sample_project', '--root=/tmp', '--script=none', '-t=rspec']) }
57
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')
58
+ assert_match_in_file(/describe "DemoItemsController" do/m, '/tmp/sample_project/spec/controllers/demo_items_controller_spec.rb')
59
59
  end
60
60
 
61
61
  should "generate controller test for shoulda" do
@@ -93,18 +93,8 @@ class TestControllerGenerator < Test::Unit::TestCase
93
93
  silence_logger { @cont_gen.start(['demo_items','-r=/tmp/sample_project','-d'])}
94
94
  assert_no_file_exists(@controller_path)
95
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
- end
98
-
99
- should "remove url routes" do
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
- # assert_no_match_in_file(/map\(\:yoda\).to\(\"\/demo_items\/yoda\"\)/m,@route_path)
104
- # assert_no_match_in_file(/map\(\:yada\).to\(\"\/demo_items\/yada\"\)/m,@route_path)
96
+ assert_no_file_exists('/tmp/sample_project/spec/controllers/demo_items_controller_spec.rb')
105
97
  end
106
98
 
107
99
  end
108
-
109
-
110
100
  end
@@ -15,6 +15,11 @@ class TestMigrationGenerator < Test::Unit::TestCase
15
15
  assert_no_file_exists('/tmp/db/migration')
16
16
  end
17
17
 
18
+ 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']) } }
21
+ end
22
+
18
23
  should "generate migration inside app root" do
19
24
  silence_logger { @project.start(['sample_project', '--root=/tmp', '--script=none', '-t=bacon', '-d=activerecord']) }
20
25
  response_success = silence_logger { @mig_gen.start(['AddEmailToUsers', '-r=/tmp/sample_project']) }
@@ -15,6 +15,11 @@ class TestModelGenerator < Test::Unit::TestCase
15
15
  assert_no_file_exists('/tmp/app/models/user.rb')
16
16
  end
17
17
 
18
+ 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']) } }
21
+ end
22
+
18
23
  should 'not fail if we don\'t have test component' do
19
24
  silence_logger { @project.start(['sample_project', '--root=/tmp', '--test=none', '-d=activerecord']) }
20
25
  response_success = silence_logger { @model_gen.start(['user', '-r=/tmp/sample_project']) }
@@ -199,9 +204,9 @@ class TestModelGenerator < Test::Unit::TestCase
199
204
  should "generate test file for rspec" do
200
205
  silence_logger { @project.start(['sample_project', '--root=/tmp', '--script=none', '-t=rspec', '-d=activerecord']) }
201
206
  silence_logger { @model_gen.start(['User', '-r=/tmp/sample_project']) }
202
- assert_match_in_file(/describe "User Model"/m, '/tmp/sample_project/test/models/user_spec.rb')
203
- assert_match_in_file(/@user = User.new/m, '/tmp/sample_project/test/models/user_spec.rb')
204
- assert_match_in_file(/@user\.should\.not\.be\snil/m, '/tmp/sample_project/test/models/user_spec.rb')
207
+ assert_match_in_file(/describe "User Model"/m, '/tmp/sample_project/spec/models/user_spec.rb')
208
+ assert_match_in_file(/@user = User.new/m, '/tmp/sample_project/spec/models/user_spec.rb')
209
+ assert_match_in_file(/@user\.should\.not\.be\snil/m, '/tmp/sample_project/spec/models/user_spec.rb')
205
210
  end
206
211
 
207
212
  # SHOULDA
@@ -239,7 +244,7 @@ class TestModelGenerator < Test::Unit::TestCase
239
244
  silence_logger { @project.start(['sample_project', '--root=/tmp', '--script=none', '-t=rspec', '-d=activerecord']) }
240
245
  silence_logger { @model_gen.start(['User', '-r=/tmp/sample_project']) }
241
246
  silence_logger { @model_gen.start(['User', '-r=/tmp/sample_project', '-d']) }
242
- assert_no_file_exists('/tmp/sample_project/test/models/user_spec.rb')
247
+ assert_no_file_exists('/tmp/sample_project/spec/models/user_spec.rb')
243
248
  end
244
249
 
245
250
  should "destroy the model migration" do
@@ -15,7 +15,7 @@ class TestProjectGenerator < Test::Unit::TestCase
15
15
  assert_file_exists('/tmp/sample_project')
16
16
  assert_file_exists('/tmp/sample_project/app')
17
17
  assert_file_exists('/tmp/sample_project/config/boot.rb')
18
- assert_file_exists('/tmp/sample_project/test/test_config.rb')
18
+ assert_file_exists('/tmp/sample_project/spec/spec_helper.rb')
19
19
  end
20
20
 
21
21
  should "not create models folder if no orm is chosen" do
@@ -38,8 +38,8 @@ class TestProjectGenerator < Test::Unit::TestCase
38
38
  silence_logger { @project.start(['sample_project', '--root=/tmp']) }
39
39
  components_chosen = YAML.load_file('/tmp/sample_project/.components')
40
40
  assert_equal 'none', components_chosen[:orm]
41
- assert_equal 'bacon', components_chosen[:test]
42
- assert_equal 'mocha', components_chosen[:mock]
41
+ assert_equal 'rspec', components_chosen[:test]
42
+ assert_equal 'none', components_chosen[:mock]
43
43
  assert_equal 'none', components_chosen[:script]
44
44
  assert_equal 'haml', components_chosen[:renderer]
45
45
  end
@@ -88,12 +88,20 @@ class TestProjectGenerator < Test::Unit::TestCase
88
88
  assert_match_in_file(/RR::Adapters::RRMethods/m, '/tmp/sample_project/test/test_config.rb')
89
89
  end
90
90
 
91
- should "properly generate default for mocha" do
91
+ should "properly generate for mocha and rspec" do
92
92
  buffer = silence_logger { @project.start(['sample_project', '--root=/tmp', '--mock=mocha', '--script=none']) }
93
93
  assert_match /Applying.*?mocha.*?mock/, buffer
94
94
  assert_match_in_file(/gem 'mocha'/, '/tmp/sample_project/Gemfile')
95
- assert_match_in_file(/include Mocha::API/m, '/tmp/sample_project/test/test_config.rb')
95
+ assert_match_in_file(/conf.mock_with :mocha/m, '/tmp/sample_project/spec/spec_helper.rb')
96
96
  end
97
+
98
+ should "properly generate for rr and rspec" do
99
+ buffer = silence_logger { @project.start(['sample_project', '--root=/tmp', '--mock=rr', '--script=none']) }
100
+ assert_match /Applying.*?rr.*?mock/, buffer
101
+ assert_match_in_file(/gem 'rr'/, '/tmp/sample_project/Gemfile')
102
+ assert_match_in_file(/conf.mock_with :rr/m, '/tmp/sample_project/spec/spec_helper.rb')
103
+ end
104
+
97
105
  end
98
106
 
99
107
  context "the generator for orm components" do
@@ -185,6 +193,7 @@ class TestProjectGenerator < Test::Unit::TestCase
185
193
  assert_match_in_file(/gem 'bacon'/, '/tmp/sample_project/Gemfile')
186
194
  assert_match_in_file(/PADRINO_ENV = 'test' unless defined\?\(PADRINO_ENV\)/, '/tmp/sample_project/test/test_config.rb')
187
195
  assert_match_in_file(/Bacon::Context/, '/tmp/sample_project/test/test_config.rb')
196
+ assert_file_exists('/tmp/sample_project/test/test.rake')
188
197
  end
189
198
 
190
199
  should "properly generate for riot" do
@@ -193,14 +202,16 @@ class TestProjectGenerator < Test::Unit::TestCase
193
202
  assert_match_in_file(/gem 'riot'/, '/tmp/sample_project/Gemfile')
194
203
  assert_match_in_file(/PADRINO_ENV = 'test' unless defined\?\(PADRINO_ENV\)/, '/tmp/sample_project/test/test_config.rb')
195
204
  assert_match_in_file(/Riot::Situation/, '/tmp/sample_project/test/test_config.rb')
205
+ assert_file_exists('/tmp/sample_project/test/test.rake')
196
206
  end
197
207
 
198
208
  should "properly generate for rspec" do
199
209
  buffer = silence_logger { @project.start(['sample_project', '--root=/tmp', '--test=rspec', '--script=none']) }
200
210
  assert_match /Applying.*?rspec.*?test/, buffer
201
211
  assert_match_in_file(/gem 'rspec'.*?:require => "spec"/, '/tmp/sample_project/Gemfile')
202
- assert_match_in_file(/PADRINO_ENV = 'test' unless defined\?\(PADRINO_ENV\)/, '/tmp/sample_project/test/test_config.rb')
203
- assert_match_in_file(/Spec::Runner/, '/tmp/sample_project/test/test_config.rb')
212
+ assert_match_in_file(/PADRINO_ENV = 'test' unless defined\?\(PADRINO_ENV\)/, '/tmp/sample_project/spec/spec_helper.rb')
213
+ assert_match_in_file(/Spec::Runner/, '/tmp/sample_project/spec/spec_helper.rb')
214
+ assert_file_exists('/tmp/sample_project/spec/spec.rake')
204
215
  end
205
216
 
206
217
  should "properly generate for shoulda" do
@@ -209,14 +220,16 @@ class TestProjectGenerator < Test::Unit::TestCase
209
220
  assert_match_in_file(/gem 'shoulda'/, '/tmp/sample_project/Gemfile')
210
221
  assert_match_in_file(/PADRINO_ENV = 'test' unless defined\?\(PADRINO_ENV\)/, '/tmp/sample_project/test/test_config.rb')
211
222
  assert_match_in_file(/Test::Unit::TestCase/, '/tmp/sample_project/test/test_config.rb')
223
+ assert_file_exists('/tmp/sample_project/test/test.rake')
212
224
  end
213
225
 
214
226
  should "properly generate for testspec" do
215
227
  buffer = silence_logger { @project.start(['sample_project', '--root=/tmp', '--test=testspec', '--script=none']) }
216
228
  assert_match /Applying.*?testspec.*?test/, buffer
217
- assert_match_in_file(/gem 'test\/spec'/, '/tmp/sample_project/Gemfile')
229
+ assert_match_in_file(/gem 'test-spec'.*?:require => "test\/spec"/, '/tmp/sample_project/Gemfile')
218
230
  assert_match_in_file(/PADRINO_ENV = 'test' unless defined\?\(PADRINO_ENV\)/, '/tmp/sample_project/test/test_config.rb')
219
231
  assert_match_in_file(/Test::Unit::TestCase/, '/tmp/sample_project/test/test_config.rb')
232
+ assert_file_exists('/tmp/sample_project/test/test.rake')
220
233
  end
221
234
  end
222
235
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: padrino-gen
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.1
4
+ version: 0.8.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Padrino Team
@@ -12,7 +12,7 @@ autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
14
 
15
- date: 2010-02-14 00:00:00 +01:00
15
+ date: 2010-02-17 00:00:00 +01:00
16
16
  default_executable: padrino-gen
17
17
  dependencies:
18
18
  - !ruby/object:Gem::Dependency
@@ -33,7 +33,7 @@ dependencies:
33
33
  requirements:
34
34
  - - "="
35
35
  - !ruby/object:Gem::Version
36
- version: 0.8.1
36
+ version: 0.8.2
37
37
  version:
38
38
  - !ruby/object:Gem::Dependency
39
39
  name: thor
@@ -132,13 +132,13 @@ files:
132
132
  - VERSION
133
133
  - bin/padrino-gen
134
134
  - lib/padrino-gen.rb
135
- - lib/padrino-gen/generators.rb
136
135
  - lib/padrino-gen/generators/actions.rb
137
136
  - lib/padrino-gen/generators/app.rb
138
137
  - lib/padrino-gen/generators/app/app.rb.tt
139
138
  - lib/padrino-gen/generators/app/controllers/.empty_directory
140
139
  - lib/padrino-gen/generators/app/helpers/.empty_directory
141
140
  - lib/padrino-gen/generators/app/views/.empty_directory
141
+ - lib/padrino-gen/generators/cli.rb
142
142
  - lib/padrino-gen/generators/components/actions.rb
143
143
  - lib/padrino-gen/generators/components/mocks/mocha_gen.rb
144
144
  - lib/padrino-gen/generators/components/mocks/rr_gen.rb
@@ -189,6 +189,7 @@ files:
189
189
  - lib/padrino-gen/padrino-tasks/activerecord.rb
190
190
  - lib/padrino-gen/padrino-tasks/datamapper.rb
191
191
  - lib/padrino-gen/padrino-tasks/locale.rb
192
+ - lib/padrino-gen/padrino-tasks/seed.rb
192
193
  - padrino-gen.gemspec
193
194
  - test/helper.rb
194
195
  - test/test_app_generator.rb