sinatra_more 0.2.9 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. data/.gitignore +2 -1
  2. data/README.rdoc +48 -4
  3. data/Rakefile +2 -1
  4. data/TODO +2 -1
  5. data/VERSION +1 -1
  6. data/bin/sinatra_gen +5 -0
  7. data/generators/base_app/app/.empty_directory +0 -0
  8. data/generators/base_app/app/helpers/.empty_directory +0 -0
  9. data/generators/base_app/app/helpers/view_helpers.rb +3 -0
  10. data/generators/base_app/app/models/.empty_directory +0 -0
  11. data/generators/base_app/app/routes/.empty_directory +0 -0
  12. data/generators/base_app/app.rb.tt +5 -0
  13. data/generators/base_app/config/boot.rb.tt +37 -0
  14. data/generators/base_app/config/dependencies.rb.tt +26 -0
  15. data/generators/base_app/config.ru.tt +13 -0
  16. data/generators/base_app/lib/.empty_directory +0 -0
  17. data/generators/base_app/log/.empty_directory +0 -0
  18. data/generators/base_app/public/images/.empty_directory +0 -0
  19. data/generators/base_app/public/images/.gitignore +0 -0
  20. data/generators/base_app/public/javascripts/.empty_directory +0 -0
  21. data/generators/base_app/public/stylesheets/.empty_directory +0 -0
  22. data/generators/base_app/test/models/.empty_directory +0 -0
  23. data/generators/base_app/test/routes/.empty_directory +0 -0
  24. data/generators/base_app/test/test_config.rb.tt +6 -0
  25. data/generators/base_app/tmp/.empty_directory +0 -0
  26. data/generators/base_app/vendor/gems/.empty_directory +0 -0
  27. data/generators/components/component_actions.rb +37 -0
  28. data/generators/components/mocks/mocha_mock_gen.rb +8 -0
  29. data/generators/components/mocks/rr_mock_gen.rb +8 -0
  30. data/generators/components/orms/activerecord_orm_gen.rb +60 -0
  31. data/generators/components/orms/datamapper_orm_gen.rb +44 -0
  32. data/generators/components/orms/mongomapper_orm_gen.rb +94 -0
  33. data/generators/components/orms/sequel_orm_gen.rb +48 -0
  34. data/generators/components/renderers/erb_renderer_gen.rb +7 -0
  35. data/generators/components/renderers/haml_renderer_gen.rb +17 -0
  36. data/generators/components/scripts/jquery_script_gen.rb +9 -0
  37. data/generators/components/scripts/prototype_script_gen.rb +10 -0
  38. data/generators/components/scripts/rightjs_script_gen.rb +9 -0
  39. data/generators/components/tests/bacon_test_gen.rb +21 -0
  40. data/generators/components/tests/riot_test_gen.rb +19 -0
  41. data/generators/components/tests/rspec_test_gen.rb +19 -0
  42. data/generators/components/tests/shoulda_test_gen.rb +19 -0
  43. data/generators/components/tests/testspec_test_gen.rb +19 -0
  44. data/generators/generator_actions.rb +77 -0
  45. data/generators/skeleton_generator.rb +41 -0
  46. data/sinatra_more.gemspec +52 -5
  47. data/test/generators/test_skeleton_generator.rb +172 -0
  48. data/test/helper.rb +16 -0
  49. metadata +59 -7
@@ -0,0 +1,19 @@
1
+ module SinatraMore
2
+ module RspecTestGen
3
+ RSPEC_SETUP = <<-TEST
4
+ \nSpec::Runner.configure do |conf|
5
+ conf.include Rack::Test::Methods
6
+ end
7
+
8
+ def app
9
+ CLASS_NAME
10
+ end
11
+ TEST
12
+
13
+ def setup_test
14
+ insert_require 'spec', :path => "test/test_config.rb"
15
+ insert_test_suite_setup RSPEC_SETUP
16
+ end
17
+
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ module SinatraMore
2
+ module ShouldaTestGen
3
+ SHOULDA_SETUP = <<-TEST
4
+ \nclass Test::Unit::TestCase
5
+ include Rack::Test::Methods
6
+
7
+ def app
8
+ CLASS_NAME
9
+ end
10
+ end
11
+ TEST
12
+
13
+ def setup_test
14
+ insert_require 'test/unit', 'shoulda', :path => "test/test_config.rb"
15
+ insert_test_suite_setup SHOULDA_SETUP
16
+ end
17
+
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ module SinatraMore
2
+ module TestspecTestGen
3
+ TESTSPEC_SETUP = <<-TEST
4
+ \nclass Test::Unit::TestCase
5
+ include Rack::Test::Methods
6
+
7
+ def app
8
+ CLASS_NAME
9
+ end
10
+ end
11
+ TEST
12
+
13
+ def setup_test
14
+ insert_require 'test/spec', :path => "test/test_config.rb"
15
+ insert_test_suite_setup TESTSPEC_SETUP
16
+ end
17
+
18
+ end
19
+ end
@@ -0,0 +1,77 @@
1
+ module SinatraMore
2
+ module GeneratorActions
3
+
4
+ def self.included(base)
5
+ base.extend(ClassMethods)
6
+ end
7
+
8
+ # Performs the necessary generator for a given component choice
9
+ # execute_component_setup(:mock, 'rr')
10
+ def execute_component_setup(component, choice)
11
+ return true && say("Skipping generator for #{component} component...", :yellow) if choice.to_s == 'none'
12
+ say "Applying '#{choice}' (#{component})...", :yellow
13
+ self.class.send(:include, generator_module_for(choice, component))
14
+ send("setup_#{component}") if respond_to?("setup_#{component}")
15
+ end
16
+
17
+ # Prompts the user if necessary until a valid choice is returned for the component
18
+ # resolve_valid_choice(:mock) => 'rr'
19
+ def resolve_valid_choice(component)
20
+ available_string = self.class.available_choices_for(component).join(", ")
21
+ choice = options[component]
22
+ until valid_choice?(component, choice)
23
+ say("Option for --#{component} '#{choice}' is not available.", :red)
24
+ choice = ask("Please enter a valid option for #{component} (#{available_string}):")
25
+ end
26
+ choice
27
+ end
28
+
29
+ # Returns true if the option passed is a valid choice for component
30
+ # valid_option?(:mock, 'rr')
31
+ def valid_choice?(component, choice)
32
+ self.class.available_choices_for(component).include? choice.to_sym
33
+ end
34
+
35
+ # Returns the related module for a given component and option
36
+ # generator_module_for('rr', :mock)
37
+ def generator_module_for(choice, component)
38
+ "SinatraMore::#{choice.to_s.capitalize}#{component.to_s.capitalize}Gen".constantize
39
+ end
40
+
41
+ # Creates a component_config file at the destination containing all component options
42
+ # Content is a yamlized version of a hash containing component name mapping to chosen value
43
+ def store_component_config(destination)
44
+ create_file(destination) do
45
+ self.class.component_types.inject({}) { |result, component|
46
+ result[component] = options[component].to_s; result
47
+ }.to_yaml
48
+ end
49
+ end
50
+
51
+ # Loads the component config back into a hash
52
+ # i.e retrieve_component_config(...) => { :mock => 'rr', :test => 'riot', ... }
53
+ def retrieve_component_config(target)
54
+ YAML.load_file(target)
55
+ end
56
+
57
+ module ClassMethods
58
+ # Defines a class option to allow a component to be chosen and add to component type list
59
+ # Also builds the available_choices hash of which component choices are supported
60
+ # component_option :test, "Testing framework", :aliases => '-t', :choices => [:bacon, :shoulda]
61
+ def component_option(name, description, options = {})
62
+ (@available_choices ||= Hash.new({}))[name] = options[:choices]
63
+ class_option name, :default => options[:choices].first, :aliases => options[:aliases]
64
+ end
65
+
66
+ # Returns the compiled list of component types which can be specified
67
+ def component_types
68
+ @available_choices.keys
69
+ end
70
+
71
+ # Returns the list of available choices for the given component (including none)
72
+ def available_choices_for(component)
73
+ @available_choices[component] + [:none]
74
+ end
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,41 @@
1
+ require File.dirname(__FILE__) + '/generator_actions'
2
+ require File.dirname(__FILE__) + '/components/component_actions'
3
+ Dir[File.dirname(__FILE__) + "/{base_app,components}/**/*.rb"].each { |lib| require lib }
4
+
5
+ module SinatraMore
6
+ class SkeletonGenerator < Thor::Group
7
+ # Define the source template root
8
+ def self.source_root; File.dirname(__FILE__); end
9
+
10
+ # Include related modules
11
+ include Thor::Actions
12
+ include SinatraMore::GeneratorActions
13
+ include SinatraMore::ComponentActions
14
+
15
+ argument :name, :desc => "The name of your sinatra app"
16
+ argument :path, :desc => "The path to create your app"
17
+
18
+ # Definitions for the available customizable components
19
+ component_option :orm, "Database engine", :aliases => '-d', :choices => [:sequel, :datamapper, :mongomapper, :activerecord]
20
+ component_option :test, "Testing framework", :aliases => '-t', :choices => [:bacon, :shoulda, :rspec, :testspec, :riot]
21
+ component_option :mock, "Mocking library", :aliases => '-m', :choices => [:mocha, :rr]
22
+ component_option :script, "Javascript library", :aliases => '-s', :choices => [:jquery, :prototype, :rightjs]
23
+ component_option :renderer, "Template Engine", :aliases => '-r', :choices => [:erb, :haml]
24
+
25
+ # Copies over the base sinatra starting application
26
+ def setup_skeleton
27
+ self.destination_root = File.join(path, name)
28
+ @class_name = name.classify
29
+ directory("base_app/", self.destination_root)
30
+ store_component_config('.components')
31
+ end
32
+
33
+ # For each component, retrieve a valid choice and then execute the associated generator
34
+ def setup_components
35
+ self.class.component_types.each do |comp|
36
+ choice = resolve_valid_choice(comp)
37
+ execute_component_setup(comp, choice)
38
+ end
39
+ end
40
+ end
41
+ end
data/sinatra_more.gemspec CHANGED
@@ -5,13 +5,15 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{sinatra_more}
8
- s.version = "0.2.9"
8
+ s.version = "0.3.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Nathan Esquenazi"]
12
- s.date = %q{2009-11-06}
12
+ s.date = %q{2009-11-08}
13
+ s.default_executable = %q{sinatra_gen}
13
14
  s.description = %q{Expands sinatra with standard helpers and tools to allow for complex applications}
14
15
  s.email = %q{nesquena@gmail.com}
16
+ s.executables = ["sinatra_gen"]
15
17
  s.extra_rdoc_files = [
16
18
  "LICENSE",
17
19
  "README.rdoc"
@@ -24,6 +26,46 @@ Gem::Specification.new do |s|
24
26
  "Rakefile",
25
27
  "TODO",
26
28
  "VERSION",
29
+ "bin/sinatra_gen",
30
+ "generators/base_app/app.rb.tt",
31
+ "generators/base_app/app/.empty_directory",
32
+ "generators/base_app/app/helpers/.empty_directory",
33
+ "generators/base_app/app/helpers/view_helpers.rb",
34
+ "generators/base_app/app/models/.empty_directory",
35
+ "generators/base_app/app/routes/.empty_directory",
36
+ "generators/base_app/config.ru.tt",
37
+ "generators/base_app/config/boot.rb.tt",
38
+ "generators/base_app/config/dependencies.rb.tt",
39
+ "generators/base_app/lib/.empty_directory",
40
+ "generators/base_app/log/.empty_directory",
41
+ "generators/base_app/public/images/.empty_directory",
42
+ "generators/base_app/public/images/.gitignore",
43
+ "generators/base_app/public/javascripts/.empty_directory",
44
+ "generators/base_app/public/stylesheets/.empty_directory",
45
+ "generators/base_app/test/models/.empty_directory",
46
+ "generators/base_app/test/routes/.empty_directory",
47
+ "generators/base_app/test/test_config.rb.tt",
48
+ "generators/base_app/tmp/.empty_directory",
49
+ "generators/base_app/vendor/gems/.empty_directory",
50
+ "generators/components/component_actions.rb",
51
+ "generators/components/mocks/mocha_mock_gen.rb",
52
+ "generators/components/mocks/rr_mock_gen.rb",
53
+ "generators/components/orms/activerecord_orm_gen.rb",
54
+ "generators/components/orms/datamapper_orm_gen.rb",
55
+ "generators/components/orms/mongomapper_orm_gen.rb",
56
+ "generators/components/orms/sequel_orm_gen.rb",
57
+ "generators/components/renderers/erb_renderer_gen.rb",
58
+ "generators/components/renderers/haml_renderer_gen.rb",
59
+ "generators/components/scripts/jquery_script_gen.rb",
60
+ "generators/components/scripts/prototype_script_gen.rb",
61
+ "generators/components/scripts/rightjs_script_gen.rb",
62
+ "generators/components/tests/bacon_test_gen.rb",
63
+ "generators/components/tests/riot_test_gen.rb",
64
+ "generators/components/tests/rspec_test_gen.rb",
65
+ "generators/components/tests/shoulda_test_gen.rb",
66
+ "generators/components/tests/testspec_test_gen.rb",
67
+ "generators/generator_actions.rb",
68
+ "generators/skeleton_generator.rb",
27
69
  "lib/sinatra_more.rb",
28
70
  "lib/sinatra_more/mailer_plugin.rb",
29
71
  "lib/sinatra_more/mailer_plugin/mail_object.rb",
@@ -66,6 +108,7 @@ Gem::Specification.new do |s|
66
108
  "test/fixtures/render_app/views/template/some_template.haml",
67
109
  "test/fixtures/warden_app/app.rb",
68
110
  "test/fixtures/warden_app/views/dashboard.haml",
111
+ "test/generators/test_skeleton_generator.rb",
69
112
  "test/helper.rb",
70
113
  "test/mailer_plugin/test_mail_object.rb",
71
114
  "test/mailer_plugin/test_mailer_base.rb",
@@ -93,6 +136,7 @@ Gem::Specification.new do |s|
93
136
  "test/fixtures/markup_app/app.rb",
94
137
  "test/fixtures/render_app/app.rb",
95
138
  "test/fixtures/warden_app/app.rb",
139
+ "test/generators/test_skeleton_generator.rb",
96
140
  "test/helper.rb",
97
141
  "test/mailer_plugin/test_mail_object.rb",
98
142
  "test/mailer_plugin/test_mailer_base.rb",
@@ -112,8 +156,9 @@ Gem::Specification.new do |s|
112
156
  s.specification_version = 3
113
157
 
114
158
  if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
115
- s.add_runtime_dependency(%q<tilt>, [">= 0.2"])
116
159
  s.add_runtime_dependency(%q<sinatra>, [">= 0.9.2"])
160
+ s.add_runtime_dependency(%q<tilt>, [">= 0.2"])
161
+ s.add_runtime_dependency(%q<thor>, [">= 0.11.8"])
117
162
  s.add_runtime_dependency(%q<activesupport>, [">= 2.2.2"])
118
163
  s.add_development_dependency(%q<haml>, [">= 2.2.1"])
119
164
  s.add_development_dependency(%q<shoulda>, [">= 2.10.2"])
@@ -121,8 +166,9 @@ Gem::Specification.new do |s|
121
166
  s.add_development_dependency(%q<rack-test>, [">= 0.5.0"])
122
167
  s.add_development_dependency(%q<webrat>, [">= 0.5.1"])
123
168
  else
124
- s.add_dependency(%q<tilt>, [">= 0.2"])
125
169
  s.add_dependency(%q<sinatra>, [">= 0.9.2"])
170
+ s.add_dependency(%q<tilt>, [">= 0.2"])
171
+ s.add_dependency(%q<thor>, [">= 0.11.8"])
126
172
  s.add_dependency(%q<activesupport>, [">= 2.2.2"])
127
173
  s.add_dependency(%q<haml>, [">= 2.2.1"])
128
174
  s.add_dependency(%q<shoulda>, [">= 2.10.2"])
@@ -131,8 +177,9 @@ Gem::Specification.new do |s|
131
177
  s.add_dependency(%q<webrat>, [">= 0.5.1"])
132
178
  end
133
179
  else
134
- s.add_dependency(%q<tilt>, [">= 0.2"])
135
180
  s.add_dependency(%q<sinatra>, [">= 0.9.2"])
181
+ s.add_dependency(%q<tilt>, [">= 0.2"])
182
+ s.add_dependency(%q<thor>, [">= 0.11.8"])
136
183
  s.add_dependency(%q<activesupport>, [">= 2.2.2"])
137
184
  s.add_dependency(%q<haml>, [">= 2.2.1"])
138
185
  s.add_dependency(%q<shoulda>, [">= 2.10.2"])
@@ -0,0 +1,172 @@
1
+ require 'helper'
2
+ require 'thor'
3
+ require File.dirname(__FILE__) + "/../../generators/skeleton_generator"
4
+
5
+ class TestSkeletonGenerator < Test::Unit::TestCase
6
+ def setup
7
+ `rm -rf /tmp/sample_app`
8
+ end
9
+
10
+ context 'the skeleton generator' do
11
+ should "allow simple generator to run and create base_app with no options" do
12
+ assert_nothing_raised { silence_logger { SinatraMore::SkeletonGenerator.start(['sample_app', '/tmp', '--script=none']) } }
13
+ assert File.exist?('/tmp/sample_app')
14
+ assert File.exist?('/tmp/sample_app/config/dependencies.rb')
15
+ assert File.exist?('/tmp/sample_app/test/test_config.rb')
16
+ end
17
+ should "create components file containing options chosen with defaults" do
18
+ silence_logger { SinatraMore::SkeletonGenerator.start(['sample_app', '/tmp']) }
19
+ components_chosen = YAML.load_file('/tmp/sample_app/.components')
20
+ assert_equal 'sequel', components_chosen[:orm]
21
+ assert_equal 'bacon', components_chosen[:test]
22
+ assert_equal 'mocha', components_chosen[:mock]
23
+ assert_equal 'jquery', components_chosen[:script]
24
+ assert_equal 'erb', components_chosen[:renderer]
25
+ end
26
+ should "create components file containing options chosen" do
27
+ component_options = ['--orm=datamapper', '--test=riot', '--mock=mocha', '--script=prototype', '--renderer=erb']
28
+ silence_logger { SinatraMore::SkeletonGenerator.start(['sample_app', '/tmp', *component_options]) }
29
+ components_chosen = YAML.load_file('/tmp/sample_app/.components')
30
+ assert_equal 'datamapper', components_chosen[:orm]
31
+ assert_equal 'riot', components_chosen[:test]
32
+ assert_equal 'mocha', components_chosen[:mock]
33
+ assert_equal 'prototype', components_chosen[:script]
34
+ assert_equal 'erb', components_chosen[:renderer]
35
+ end
36
+ should "output to log components being applied" do
37
+ component_options = ['--orm=datamapper', '--test=riot', '--mock=mocha', '--script=prototype', '--renderer=erb']
38
+ buffer = silence_logger { SinatraMore::SkeletonGenerator.start(['sample_app', '/tmp', *component_options]) }
39
+ assert_match /Applying.*?datamapper.*?orm/, buffer
40
+ assert_match /Applying.*?riot.*?test/, buffer
41
+ assert_match /Applying.*?mocha.*?mock/, buffer
42
+ assert_match /Applying.*?prototype.*?script/, buffer
43
+ assert_match /Applying.*?erb.*?renderer/, buffer
44
+ end
45
+ end
46
+
47
+ context "the generator for mock component" do
48
+ should "properly generate for rr" do
49
+ buffer = silence_logger { SinatraMore::SkeletonGenerator.start(['sample_app', '/tmp', '--mock=rr', '--script=none']) }
50
+ assert_match /Applying.*?rr.*?mock/, buffer
51
+ assert_match_in_file(/require 'rr'/, '/tmp/sample_app/test/test_config.rb')
52
+ assert_match_in_file(/class.*?include RR::Adapters::RRMethods/m, '/tmp/sample_app/test/test_config.rb')
53
+ end
54
+
55
+ should "properly generate default for mocha" do
56
+ buffer = silence_logger { SinatraMore::SkeletonGenerator.start(['sample_app', '/tmp', '--mock=mocha', '--script=none']) }
57
+ assert_match /Applying.*?mocha.*?mock/, buffer
58
+ assert_match_in_file(/require 'mocha'/, '/tmp/sample_app/test/test_config.rb')
59
+ assert_match_in_file(/class.*?include Mocha::API/m, '/tmp/sample_app/test/test_config.rb')
60
+ end
61
+ end
62
+
63
+
64
+ context "the generator for orm components" do
65
+ should "properly generate default for sequel" do
66
+ SinatraMore::SkeletonGenerator.instance_eval("undef setup_orm if respond_to?('setup_orm')")
67
+ buffer = silence_logger { SinatraMore::SkeletonGenerator.start(['sample_app', '/tmp', '--orm=sequel', '--script=none']) }
68
+ assert_match /Applying.*?sequel.*?orm/, buffer
69
+ assert_match_in_file(/require 'sequel'/, '/tmp/sample_app/config/dependencies.rb')
70
+ assert_match_in_file(/SequelInitializer/, '/tmp/sample_app/config/initializers/sequel.rb')
71
+ assert_match_in_file(/class User < Sequel::Model/, '/tmp/sample_app/app/models/user.rb')
72
+ end
73
+
74
+ should "properly generate for activerecord" do
75
+ buffer = silence_logger { SinatraMore::SkeletonGenerator.start(['sample_app', '/tmp', '--orm=activerecord', '--script=none']) }
76
+ assert_match /Applying.*?activerecord.*?orm/, buffer
77
+ assert_match_in_file(/require 'active_record'/, '/tmp/sample_app/config/dependencies.rb')
78
+ assert_match_in_file(/ActiveRecordInitializer/, '/tmp/sample_app/config/initializers/activerecord.rb')
79
+ assert_match_in_file(/CreateUsers < ActiveRecord::Migration/, '/tmp/sample_app/db/migrate/001_create_users.rb')
80
+ assert_match_in_file(/class User < ActiveRecord::Base/, '/tmp/sample_app/app/models/user.rb')
81
+ end
82
+
83
+ should "properly generate for datamapper" do
84
+ buffer = silence_logger { SinatraMore::SkeletonGenerator.start(['sample_app', '/tmp', '--orm=datamapper', '--script=none']) }
85
+ assert_match /Applying.*?datamapper.*?orm/, buffer
86
+ assert_match_in_file(/require 'dm-core'/, '/tmp/sample_app/config/dependencies.rb')
87
+ assert_match_in_file(/DatamapperInitializer/, '/tmp/sample_app/config/initializers/datamapper.rb')
88
+ assert_match_in_file(/class User.*?include DataMapper::Resource/m, '/tmp/sample_app/app/models/user.rb')
89
+ end
90
+
91
+ should "properly generate for mongomapper" do
92
+ buffer = silence_logger { SinatraMore::SkeletonGenerator.start(['sample_app', '/tmp', '--orm=mongomapper', '--script=none']) }
93
+ assert_match /Applying.*?mongomapper.*?orm/, buffer
94
+ assert_match_in_file(/require 'mongo_mapper'/, '/tmp/sample_app/config/dependencies.rb')
95
+ assert_match_in_file(/MongoDBInitializer/, '/tmp/sample_app/config/initializers/mongodb.rb')
96
+ assert_match_in_file(/class User.*?include MongoMapper::Document/m, '/tmp/sample_app/app/models/user.rb')
97
+ end
98
+ end
99
+
100
+ context "the generator for renderer component" do
101
+ should "properly generate default for erb" do
102
+ buffer = silence_logger { SinatraMore::SkeletonGenerator.start(['sample_app', '/tmp', '--renderer=erb', '--script=none']) }
103
+ assert_match /Applying.*?erb.*?renderer/, buffer
104
+ assert_match_in_file(/require 'erb'/, '/tmp/sample_app/config/dependencies.rb')
105
+ end
106
+
107
+ should "properly generate for haml" do
108
+ buffer = silence_logger { SinatraMore::SkeletonGenerator.start(['sample_app', '/tmp', '--renderer=haml','--script=none']) }
109
+ assert_match /Applying.*?haml.*?renderer/, buffer
110
+ assert_match_in_file(/haml.*sass.*hassle.*require/, '/tmp/sample_app/config/dependencies.rb')
111
+ assert_match_in_file(/HassleInitializer/, '/tmp/sample_app/config/initializers/hassle.rb')
112
+ end
113
+ end
114
+
115
+ context "the generator for script component" do
116
+ should "properly generate for jquery" do
117
+ buffer = silence_logger { SinatraMore::SkeletonGenerator.start(['sample_app', '/tmp', '--script=jquery']) }
118
+ assert_match /Applying.*?jquery.*?script/, buffer
119
+ assert File.exist?('/tmp/sample_app/public/javascripts/jquery.min.js')
120
+ end
121
+
122
+ should "properly generate for prototype" do
123
+ buffer = silence_logger { SinatraMore::SkeletonGenerator.start(['sample_app', '/tmp', '--script=prototype']) }
124
+ assert_match /Applying.*?prototype.*?script/, buffer
125
+ assert File.exist?('/tmp/sample_app/public/javascripts/prototype.js')
126
+ assert File.exist?('/tmp/sample_app/public/javascripts/lowpro.js')
127
+ end
128
+
129
+ should "properly generate for rightjs" do
130
+ buffer = silence_logger { SinatraMore::SkeletonGenerator.start(['sample_app', '/tmp', '--script=rightjs']) }
131
+ assert_match /Applying.*?rightjs.*?script/, buffer
132
+ assert File.exist?('/tmp/sample_app/public/javascripts/right-min.js')
133
+ end
134
+ end
135
+
136
+ context "the generator for test component" do
137
+ should "properly default generate for bacon" do
138
+ buffer = silence_logger { SinatraMore::SkeletonGenerator.start(['sample_app', '/tmp', '--test=bacon', '--script=none']) }
139
+ assert_match /Applying.*?bacon.*?test/, buffer
140
+ assert_match_in_file(/require 'bacon'/, '/tmp/sample_app/test/test_config.rb')
141
+ assert_match_in_file(/Bacon::Context/, '/tmp/sample_app/test/test_config.rb')
142
+ end
143
+
144
+ should "properly generate for riot" do
145
+ buffer = silence_logger { SinatraMore::SkeletonGenerator.start(['sample_app', '/tmp', '--test=riot', '--script=none']) }
146
+ assert_match /Applying.*?riot.*?test/, buffer
147
+ assert_match_in_file(/require 'riot'/, '/tmp/sample_app/test/test_config.rb')
148
+ assert_match_in_file(/Riot::Context/, '/tmp/sample_app/test/test_config.rb')
149
+ end
150
+
151
+ should "properly generate for rspec" do
152
+ buffer = silence_logger { SinatraMore::SkeletonGenerator.start(['sample_app', '/tmp', '--test=rspec', '--script=none']) }
153
+ assert_match /Applying.*?rspec.*?test/, buffer
154
+ assert_match_in_file(/require 'spec'/, '/tmp/sample_app/test/test_config.rb')
155
+ assert_match_in_file(/Spec::Runner/, '/tmp/sample_app/test/test_config.rb')
156
+ end
157
+
158
+ should "properly generate for shoulda" do
159
+ buffer = silence_logger { SinatraMore::SkeletonGenerator.start(['sample_app', '/tmp', '--test=shoulda', '--script=none']) }
160
+ assert_match /Applying.*?shoulda.*?test/, buffer
161
+ assert_match_in_file(/test\/unit.*shoulda.*require/, '/tmp/sample_app/test/test_config.rb')
162
+ assert_match_in_file(/Test::Unit::TestCase/, '/tmp/sample_app/test/test_config.rb')
163
+ end
164
+
165
+ should "properly generate for testspec" do
166
+ buffer = silence_logger { SinatraMore::SkeletonGenerator.start(['sample_app', '/tmp', '--test=testspec', '--script=none']) }
167
+ assert_match /Applying.*?testspec.*?test/, buffer
168
+ assert_match_in_file(/require 'test\/spec'/, '/tmp/sample_app/test/test_config.rb')
169
+ assert_match_in_file(/Test::Unit::TestCase/, '/tmp/sample_app/test/test_config.rb')
170
+ end
171
+ end
172
+ end
data/test/helper.rb CHANGED
@@ -46,6 +46,22 @@ class Test::Unit::TestCase
46
46
  raise "Please specify a block!" if html.blank?
47
47
  assert matcher.matches?(html), matcher.failure_message
48
48
  end
49
+
50
+ # Silences the output by redirecting to stringIO
51
+ # silence_logger { ...commands... } => "...output..."
52
+ def silence_logger(&block)
53
+ orig_stdout = $stdout
54
+ $stdout = log_buffer = StringIO.new
55
+ block.call
56
+ $stdout = orig_stdout
57
+ log_buffer.rewind && log_buffer.read
58
+ end
59
+
60
+ # Asserts that a file matches the pattern
61
+ def assert_match_in_file(pattern, file)
62
+ assert File.exist?(file), "File '#{file}' does not exist!"
63
+ assert_match pattern, File.read(file)
64
+ end
49
65
  end
50
66
 
51
67
  module Webrat
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sinatra_more
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.9
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nathan Esquenazi
@@ -9,9 +9,19 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-11-06 00:00:00 -08:00
13
- default_executable:
12
+ date: 2009-11-08 00:00:00 -08:00
13
+ default_executable: sinatra_gen
14
14
  dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: sinatra
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 0.9.2
24
+ version:
15
25
  - !ruby/object:Gem::Dependency
16
26
  name: tilt
17
27
  type: :runtime
@@ -23,14 +33,14 @@ dependencies:
23
33
  version: "0.2"
24
34
  version:
25
35
  - !ruby/object:Gem::Dependency
26
- name: sinatra
36
+ name: thor
27
37
  type: :runtime
28
38
  version_requirement:
29
39
  version_requirements: !ruby/object:Gem::Requirement
30
40
  requirements:
31
41
  - - ">="
32
42
  - !ruby/object:Gem::Version
33
- version: 0.9.2
43
+ version: 0.11.8
34
44
  version:
35
45
  - !ruby/object:Gem::Dependency
36
46
  name: activesupport
@@ -94,8 +104,8 @@ dependencies:
94
104
  version:
95
105
  description: Expands sinatra with standard helpers and tools to allow for complex applications
96
106
  email: nesquena@gmail.com
97
- executables: []
98
-
107
+ executables:
108
+ - sinatra_gen
99
109
  extensions: []
100
110
 
101
111
  extra_rdoc_files:
@@ -109,6 +119,46 @@ files:
109
119
  - Rakefile
110
120
  - TODO
111
121
  - VERSION
122
+ - bin/sinatra_gen
123
+ - generators/base_app/app.rb.tt
124
+ - generators/base_app/app/.empty_directory
125
+ - generators/base_app/app/helpers/.empty_directory
126
+ - generators/base_app/app/helpers/view_helpers.rb
127
+ - generators/base_app/app/models/.empty_directory
128
+ - generators/base_app/app/routes/.empty_directory
129
+ - generators/base_app/config.ru.tt
130
+ - generators/base_app/config/boot.rb.tt
131
+ - generators/base_app/config/dependencies.rb.tt
132
+ - generators/base_app/lib/.empty_directory
133
+ - generators/base_app/log/.empty_directory
134
+ - generators/base_app/public/images/.empty_directory
135
+ - generators/base_app/public/images/.gitignore
136
+ - generators/base_app/public/javascripts/.empty_directory
137
+ - generators/base_app/public/stylesheets/.empty_directory
138
+ - generators/base_app/test/models/.empty_directory
139
+ - generators/base_app/test/routes/.empty_directory
140
+ - generators/base_app/test/test_config.rb.tt
141
+ - generators/base_app/tmp/.empty_directory
142
+ - generators/base_app/vendor/gems/.empty_directory
143
+ - generators/components/component_actions.rb
144
+ - generators/components/mocks/mocha_mock_gen.rb
145
+ - generators/components/mocks/rr_mock_gen.rb
146
+ - generators/components/orms/activerecord_orm_gen.rb
147
+ - generators/components/orms/datamapper_orm_gen.rb
148
+ - generators/components/orms/mongomapper_orm_gen.rb
149
+ - generators/components/orms/sequel_orm_gen.rb
150
+ - generators/components/renderers/erb_renderer_gen.rb
151
+ - generators/components/renderers/haml_renderer_gen.rb
152
+ - generators/components/scripts/jquery_script_gen.rb
153
+ - generators/components/scripts/prototype_script_gen.rb
154
+ - generators/components/scripts/rightjs_script_gen.rb
155
+ - generators/components/tests/bacon_test_gen.rb
156
+ - generators/components/tests/riot_test_gen.rb
157
+ - generators/components/tests/rspec_test_gen.rb
158
+ - generators/components/tests/shoulda_test_gen.rb
159
+ - generators/components/tests/testspec_test_gen.rb
160
+ - generators/generator_actions.rb
161
+ - generators/skeleton_generator.rb
112
162
  - lib/sinatra_more.rb
113
163
  - lib/sinatra_more/mailer_plugin.rb
114
164
  - lib/sinatra_more/mailer_plugin/mail_object.rb
@@ -151,6 +201,7 @@ files:
151
201
  - test/fixtures/render_app/views/template/some_template.haml
152
202
  - test/fixtures/warden_app/app.rb
153
203
  - test/fixtures/warden_app/views/dashboard.haml
204
+ - test/generators/test_skeleton_generator.rb
154
205
  - test/helper.rb
155
206
  - test/mailer_plugin/test_mail_object.rb
156
207
  - test/mailer_plugin/test_mailer_base.rb
@@ -200,6 +251,7 @@ test_files:
200
251
  - test/fixtures/markup_app/app.rb
201
252
  - test/fixtures/render_app/app.rb
202
253
  - test/fixtures/warden_app/app.rb
254
+ - test/generators/test_skeleton_generator.rb
203
255
  - test/helper.rb
204
256
  - test/mailer_plugin/test_mail_object.rb
205
257
  - test/mailer_plugin/test_mailer_base.rb