hoboken 0.0.1.beta2 → 0.0.1.beta3

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d93ed494dde1289a45fcfb75ffa80285d0995020
4
- data.tar.gz: cd9319eef83037bf07083d0cc0740fc94fc0b415
3
+ metadata.gz: 92e42c10869f91d6dd97bc1f6445bfc441ba7c3f
4
+ data.tar.gz: 28fdbb0fd176c28fce090ab5c08694f579cbe3d6
5
5
  SHA512:
6
- metadata.gz: 2b4f2c2ccccb2ac0fecd1e76236fe52669478facb48a61d0791ab574fac940001e0dfa7f3b9127d4436d3b323010968432a86e72cb4844df6bce31cb405bb2f0
7
- data.tar.gz: 6019310cb5cdb8005948b4ed8a9b5fc275a2c927ba40a771a9c3a72fa13881db4891339964b67f2f87c3a95aef779d308e743161d8959cf4437d3155bd19c645
6
+ metadata.gz: e9084680cea5d0f1a2cb8c9bb56187bfc16a6f769269aa7d196635fe94e49ada236894b74e3e69f3b94b10f3a3ccde046e262c16fdffbd702c83384f4e61eb65
7
+ data.tar.gz: d4e6120ee3d411dff96b3c6cf8374571d79e2175591fc3b2f7ce8166dc9dfa60ae477758c73198f87371ad15a1439bc8060a4c64314c46fde9b5e0330b9ef724
data/README.md CHANGED
@@ -1,12 +1,13 @@
1
1
  # Hoboken
2
2
 
3
+ [![Gem Version](https://badge.fury.io/rb/hoboken.png)](http://badge.fury.io/rb/hoboken)
3
4
  [![Dependency Status](https://gemnasium.com/bnadlerjr/hoboken.png)](https://gemnasium.com/bnadlerjr/hoboken)
4
5
 
5
6
  Generate Sinatra project templates.
6
7
 
7
8
  ## Installation
8
9
 
9
- $ gem install hoboken
10
+ $ gem install hoboken --pre
10
11
 
11
12
  ## Usage
12
13
 
@@ -42,6 +43,7 @@ Additional generators are available for existing projects generated using Hoboke
42
43
  $ hoboken add:i18n # Internationalization support using sinatra-r18n
43
44
  $ hoboken add:metrics # Add metrics (flog, flay, simplecov)
44
45
  $ hoboken add:omniauth # OmniAuth authentication (allows you to select a provider)
46
+ $ hoboken add:sequel # Database access via Sequel gem
45
47
  $ hoboken add:sprockets # Rack-based asset packaging system
46
48
 
47
49
  ## Contributing
data/Rakefile CHANGED
@@ -1,11 +1,18 @@
1
1
  require "bundler/gem_tasks"
2
2
  require "rake/testtask"
3
3
 
4
- task :default => "test:unit"
4
+ task :default => "test:all"
5
5
 
6
6
  namespace :test do
7
- Rake::TestTask.new(:unit) do |t|
8
- t.libs << 'test/unit'
9
- t.test_files = Dir["test/unit/**/*_test.rb"]
7
+ types = %w(unit integration)
8
+
9
+ types.each do |type|
10
+ Rake::TestTask.new(type.to_sym) do |t|
11
+ t.libs << "test/#{type}"
12
+ t.test_files = Dir["test/#{type}/**/*_test.rb"]
13
+ end
10
14
  end
15
+
16
+ desc "Run all tests"
17
+ task :all => types.map { |s| "test:#{s}" }
11
18
  end
@@ -6,6 +6,99 @@ require_relative "hoboken/generate"
6
6
  require_relative "hoboken/actions"
7
7
 
8
8
  module Hoboken
9
+ class Group < Thor::Group
10
+ include Thor::Actions
11
+ include Hoboken::Actions
12
+
13
+ def self.source_root
14
+ File.dirname(__FILE__)
15
+ end
16
+ end
17
+
18
+ class Sequel < Thor::Group
19
+ include Thor::Actions
20
+ include Hoboken::Actions
21
+
22
+ def self.source_root
23
+ File.dirname(__FILE__)
24
+ end
25
+
26
+ def add_gems
27
+ gem "sequel", "4.6.0"
28
+ gem "sqlite3", "1.3.8", group: [:development, :test]
29
+ end
30
+
31
+ def setup_directories
32
+ empty_directory("db/migrate")
33
+ empty_directory("tasks")
34
+ end
35
+
36
+ def copy_rake_task
37
+ copy_file("hoboken/templates/sequel.rake", "tasks/sequel.rake")
38
+ end
39
+
40
+ def setup_database_connection_in_rackup_file
41
+ insert_into_file("config.ru", after: /require "bundler\/setup"/) do
42
+ "\nrequire \"logger\"\nrequire \"sequel\""
43
+ end
44
+
45
+ app_name = File.open("config.ru").grep(/run.+/).first.chomp.gsub("run ", "")
46
+
47
+ gsub_file("config.ru", /run #{app_name}/) do
48
+ <<CODE
49
+
50
+ db = Sequel.connect(ENV["DATABASE_URL"], loggers: [Logger.new($stdout)])
51
+ Sequel.extension :migration
52
+ Sequel::Migrator.check_current(db, "db/migrate") if Dir.glob("db/migrate/*.rb").size > 0
53
+
54
+ app = #{app_name}
55
+ app.set :database, db
56
+ run app
57
+ CODE
58
+ end
59
+ end
60
+
61
+ def add_database_test_helper_class
62
+ insert_into_file("test/test_helper.rb", after: /require "test\/unit"/) do
63
+ "\nrequire \"sequel\""
64
+ end
65
+
66
+ append_file("test/test_helper.rb") do
67
+ <<CODE
68
+
69
+ module Test::Database
70
+ class TestCase < Test::Unit::TestCase
71
+ def run(*args, &block)
72
+ result = nil
73
+ database.transaction(rollback: :always) { result = super }
74
+ result
75
+ end
76
+
77
+ private
78
+
79
+ def database
80
+ @database ||= Sequel.sqlite.tap do |db|
81
+ Sequel.extension :migration
82
+ Sequel::Migrator.run(db, 'db/migrate') if Dir.glob("db/migrate/*.rb").size > 0
83
+ end
84
+ end
85
+ end
86
+ end
87
+ CODE
88
+ end
89
+ end
90
+
91
+ def reminders
92
+ say "\nGemfile updated... don't forget to 'bundle install'"
93
+ say <<TEXT
94
+
95
+ Notes:
96
+ * The sqlite3 gem has been installed for dev and test environments only. You will need to specify a gem to use for production.
97
+ * You will need to specify an environment variable 'DATABASE_URL' (either add it to .env or export it)
98
+ TEXT
99
+ end
100
+ end
101
+
9
102
  class OmniAuth < Thor::Group
10
103
  include Thor::Actions
11
104
  include Hoboken::Actions
@@ -116,223 +209,10 @@ CODE
116
209
  end
117
210
  end
118
211
 
119
- class Sprockets < Thor::Group
120
- include Thor::Actions
121
- include Hoboken::Actions
122
-
123
- def self.source_root
124
- File.dirname(__FILE__)
125
- end
126
-
127
- def create_assets_folder
128
- empty_directory("assets")
129
- FileUtils.cp("public/css/styles.css", "assets/styles.css")
130
- FileUtils.cp("public/js/app.js", "assets/app.js")
131
- end
132
-
133
- def add_gems
134
- gem "sprockets", "2.10.0", group: :assets
135
- gem "uglifier", "2.1.1", group: :assets
136
- gem "yui-compressor", "0.9.6", group: :assets
137
- end
138
-
139
- def copy_sprockets_helpers
140
- copy_file("hoboken/templates/sprockets.rake", "tasks/sprockets.rake")
141
- copy_file("hoboken/templates/sprockets_chain.rb", "middleware/sprockets_chain.rb")
142
- copy_file("hoboken/templates/sprockets_helper.rb", "helpers/sprockets.rb")
143
- end
144
-
145
- def update_app
146
- insert_into_file("app.rb", after: /configure :development do\n/) do
147
- <<CODE
148
- require File.expand_path('middleware/sprockets_chain', settings.root)
149
- use Middleware::SprocketsChain, %r{/assets} do |env|
150
- %w(assets vendor).each do |f|
151
- env.append_path File.expand_path("../\#{f}", __FILE__)
152
- end
153
- end
154
-
155
- CODE
156
- end
157
-
158
- insert_into_file("app.rb", after: /set :root, File.dirname\(__FILE__\)\n/) do
159
- " helpers Helpers::Sprockets"
160
- end
161
-
162
- gsub_file("app.rb", /require "sinatra\/reloader" if development\?/) do
163
- <<CODE
164
- if development?
165
- require "sinatra/reloader"
166
-
167
- require File.expand_path('middleware/sprockets_chain', settings.root)
168
- use Middleware::SprocketsChain, %r{/assets} do |env|
169
- %w(assets vendor).each do |f|
170
- env.append_path File.expand_path("../\#{f}", __FILE__)
171
- end
172
- end
173
- end
174
-
175
- helpers Helpers::Sprockets
176
- CODE
177
- end
178
- end
179
-
180
- def adjust_link_tags
181
- insert_into_file("views/layout.erb", before: /<\/head>/) do
182
- <<HTML
183
- <%= stylesheet_tag :styles %>
184
-
185
- <%= javascript_tag :app %>
186
- HTML
187
- end
188
-
189
- gsub_file("views/layout.erb", /<link rel="stylesheet" type="text\/css" href="css\/styles.css">/, "")
190
- gsub_file("views/layout.erb", /<script type="text\/javascript" src="js\/app.js"><\/script>/, "")
191
- end
192
-
193
- def directions
194
- text = <<TEXT
195
-
196
- Run `bundle install` to get the sprockets gem and its
197
- dependencies.
198
-
199
- Running the server in development mode will serve css
200
- and js files from /assets. In order to serve assets in
201
- production, you must run `rake assets:precompile`. Read
202
- the important note below before running this rake task.
203
- TEXT
204
-
205
- important = <<TEXT
206
-
207
- Important Note:
208
- Any css or js files from the /public folder have been copied
209
- to /assets, the original files remain intact in /public, but
210
- will be replaced the first time you run `rake assets:precompile`.
211
- You may want to backup those files if they are not under source
212
- control before running the Rake command.
213
- TEXT
214
-
215
- say text
216
- say important, :red
217
- end
218
- end
219
-
220
- class Heroku < Thor::Group
221
- include Thor::Actions
222
- include Hoboken::Actions
223
-
224
- def self.source_root
225
- File.dirname(__FILE__)
226
- end
227
-
228
- def add_gem
229
- gem "foreman", "0.63.0", group: :development
230
- end
231
-
232
- def procfile
233
- create_file("Procfile") do
234
- "web: bundle exec thin start -p $PORT -e $RACK_ENV"
235
- end
236
- end
237
-
238
- def env_file
239
- create_file(".env") do
240
- "RACK_ENV=development\nPORT=9292"
241
- end
242
- append_to_file(".gitignore", ".env") if File.exist?(".gitignore")
243
- end
244
-
245
- def slugignore
246
- create_file(".slugignore") do
247
- "tags\n/test\n/tmp"
248
- end
249
- end
250
-
251
- def fix_stdout_for_logging
252
- prepend_file("config.ru", "$stdout.sync = true\n")
253
- end
254
-
255
- def replace_server_rake_task
256
- gsub_file("Rakefile", /desc.*server.*{rack_env}"\)\nend$/m) do
257
- <<TASK
258
- desc "Start the development server with Foreman"
259
- task :server do
260
- exec("foreman start")
261
- end
262
- TASK
263
- end
264
- end
265
-
266
- def reminders
267
- say "\nGemfile updated... don't forget to 'bundle install'"
268
- end
269
- end
270
-
271
- class Internationalization < Thor::Group
272
- include Thor::Actions
273
- include Hoboken::Actions
274
-
275
- def self.source_root
276
- File.dirname(__FILE__)
277
- end
278
-
279
- def add_gem
280
- gem "sinatra-r18n", "1.1.5"
281
- insert_into_file("app.rb", after: /require "sinatra("|\/base")/) do
282
- "\nrequire \"sinatra/r18n\""
283
- end
284
- insert_into_file("app.rb", after: /Sinatra::Base/) do
285
- "\n register Sinatra::R18n"
286
- end
287
- end
288
-
289
- def translations
290
- empty_directory("i18n")
291
- template("hoboken/templates/en.yml.tt", "i18n/en.yml")
292
- end
293
-
294
- def reminders
295
- say "\nGemfile updated... don't forget to 'bundle install'"
296
- end
297
- end
298
-
299
- class Metrics < Thor::Group
300
- include Thor::Actions
301
- include Hoboken::Actions
302
-
303
- def self.source_root
304
- File.dirname(__FILE__)
305
- end
306
-
307
- def add_gems
308
- gem "flog", "2.5.3", group: :test
309
- gem "flay", "1.4.3", group: :test
310
- gem "simplecov", "0.7.1", require: false, group: :test
311
- end
312
-
313
- def copy_task_templates
314
- empty_directory("tasks")
315
- template("hoboken/templates/metrics.rake.tt", "tasks/metrics.rake")
316
- end
317
-
318
- def simplecov_snippet
319
- insert_into_file "test/unit/test_helper.rb", before: /require "test\/unit"/ do
320
- <<CODE
321
-
322
- require 'simplecov'
323
- SimpleCov.start do
324
- add_filter "/test/"
325
- coverage_dir 'tmp/coverage'
326
- end
327
-
328
- CODE
329
- end
330
- end
331
-
332
- def reminders
333
- say "\nGemfile updated... don't forget to 'bundle install'"
334
- end
335
- end
212
+ require_relative "hoboken/add_ons/metrics"
213
+ require_relative "hoboken/add_ons/internationalization"
214
+ require_relative "hoboken/add_ons/heroku"
215
+ require_relative "hoboken/add_ons/sprockets"
336
216
 
337
217
  class CLI < Thor
338
218
  desc "version", "Print version and quit"
@@ -343,10 +223,11 @@ CODE
343
223
  register(Generate, "generate", "generate [APP_NAME]", "Generate a new Sinatra app")
344
224
  tasks["generate"].options = Hoboken::Generate.class_options
345
225
 
346
- register(Metrics, "add:metrics", "add:metrics", "Add metrics (flog, flay, simplecov)")
347
- register(Internationalization, "add:i18n", "add:i18n", "Internationalization support using sinatra-r18n")
348
- register(Heroku, "add:heroku", "add:heroku", "Heroku deployment support")
226
+ register(AddOns::Metrics, "add:metrics", "add:metrics", "Add metrics (flog, flay, simplecov)")
227
+ register(AddOns::Internationalization, "add:i18n", "add:i18n", "Internationalization support using sinatra-r18n")
228
+ register(AddOns::Heroku, "add:heroku", "add:heroku", "Heroku deployment support")
349
229
  register(OmniAuth, "add:omniauth", "add:omniauth", "OmniAuth authentication (allows you to select a provider)")
350
- register(Sprockets, "add:sprockets", "add:sprockets", "Rack-based asset packaging system")
230
+ register(AddOns::Sprockets, "add:sprockets", "add:sprockets", "Rack-based asset packaging system")
231
+ register(Sequel, "add:sequel", "add:sequel", "Database access via Sequel gem")
351
232
  end
352
233
  end
@@ -0,0 +1,40 @@
1
+ module Hoboken
2
+ module AddOns
3
+ class Heroku < ::Hoboken::Group
4
+ def add_gem
5
+ gem "foreman", "0.63.0", group: :development
6
+ end
7
+
8
+ def procfile
9
+ create_file("Procfile") do
10
+ "web: bundle exec thin start -p $PORT -e $RACK_ENV"
11
+ end
12
+ end
13
+
14
+ def slugignore
15
+ create_file(".slugignore") do
16
+ "tags\n/test\n/tmp"
17
+ end
18
+ end
19
+
20
+ def fix_stdout_for_logging
21
+ prepend_file("config.ru", "$stdout.sync = true\n")
22
+ end
23
+
24
+ def replace_server_rake_task
25
+ gsub_file("Rakefile", /desc.*server.*{rack_env}"\)\nend$/m) do
26
+ <<TASK
27
+ desc "Start the development server with Foreman"
28
+ task :server do
29
+ exec("foreman start")
30
+ end
31
+ TASK
32
+ end
33
+ end
34
+
35
+ def reminders
36
+ say "\nGemfile updated... don't forget to 'bundle install'"
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,24 @@
1
+ module Hoboken
2
+ module AddOns
3
+ class Internationalization < ::Hoboken::Group
4
+ def add_gem
5
+ gem "sinatra-r18n", "1.1.5"
6
+ insert_into_file("app.rb", after: /require "sinatra("|\/base")/) do
7
+ "\nrequire \"sinatra/r18n\""
8
+ end
9
+ insert_into_file("app.rb", after: /Sinatra::Base/) do
10
+ "\n register Sinatra::R18n"
11
+ end
12
+ end
13
+
14
+ def translations
15
+ empty_directory("i18n")
16
+ template("hoboken/templates/en.yml.tt", "i18n/en.yml")
17
+ end
18
+
19
+ def reminders
20
+ say "\nGemfile updated... don't forget to 'bundle install'"
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,34 @@
1
+ module Hoboken
2
+ module AddOns
3
+ class Metrics < ::Hoboken::Group
4
+ def add_gems
5
+ gem "flog", "2.5.3", group: :test
6
+ gem "flay", "1.4.3", group: :test
7
+ gem "simplecov", "0.7.1", require: false, group: :test
8
+ end
9
+
10
+ def copy_task_templates
11
+ empty_directory("tasks")
12
+ template("hoboken/templates/metrics.rake.tt", "tasks/metrics.rake")
13
+ end
14
+
15
+ def simplecov_snippet
16
+ insert_into_file "test/test_helper.rb", before: /require "test\/unit"/ do
17
+ <<CODE
18
+
19
+ require 'simplecov'
20
+ SimpleCov.start do
21
+ add_filter "/test/"
22
+ coverage_dir 'tmp/coverage'
23
+ end
24
+
25
+ CODE
26
+ end
27
+ end
28
+
29
+ def reminders
30
+ say "\nGemfile updated... don't forget to 'bundle install'"
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,97 @@
1
+ module Hoboken
2
+ module AddOns
3
+ class Sprockets < ::Hoboken::Group
4
+ def create_assets_folder
5
+ empty_directory("assets")
6
+ FileUtils.cp("public/css/styles.css", "assets/styles.css")
7
+ FileUtils.cp("public/js/app.js", "assets/app.js")
8
+ end
9
+
10
+ def add_gems
11
+ gem "sprockets", "2.10.0", group: :assets
12
+ gem "uglifier", "2.1.1", group: :assets
13
+ gem "yui-compressor", "0.9.6", group: :assets
14
+ end
15
+
16
+ def copy_sprockets_helpers
17
+ copy_file("hoboken/templates/sprockets.rake", "tasks/sprockets.rake")
18
+ copy_file("hoboken/templates/sprockets_chain.rb", "middleware/sprockets_chain.rb")
19
+ copy_file("hoboken/templates/sprockets_helper.rb", "helpers/sprockets.rb")
20
+ end
21
+
22
+ def update_app
23
+ insert_into_file("app.rb", after: /configure :development do\n/) do
24
+ <<CODE
25
+ require File.expand_path('middleware/sprockets_chain', settings.root)
26
+ use Middleware::SprocketsChain, %r{/assets} do |env|
27
+ %w(assets vendor).each do |f|
28
+ env.append_path File.expand_path("../\#{f}", __FILE__)
29
+ end
30
+ end
31
+
32
+ CODE
33
+ end
34
+
35
+ insert_into_file("app.rb", after: /set :root, File.dirname\(__FILE__\)\n/) do
36
+ " helpers Helpers::Sprockets"
37
+ end
38
+
39
+ gsub_file("app.rb", /require "sinatra\/reloader" if development\?/) do
40
+ <<CODE
41
+ if development?
42
+ require "sinatra/reloader"
43
+
44
+ require File.expand_path('middleware/sprockets_chain', settings.root)
45
+ use Middleware::SprocketsChain, %r{/assets} do |env|
46
+ %w(assets vendor).each do |f|
47
+ env.append_path File.expand_path("../\#{f}", __FILE__)
48
+ end
49
+ end
50
+ end
51
+
52
+ helpers Helpers::Sprockets
53
+ CODE
54
+ end
55
+ end
56
+
57
+ def adjust_link_tags
58
+ insert_into_file("views/layout.erb", before: /<\/head>/) do
59
+ <<HTML
60
+ <%= stylesheet_tag :styles %>
61
+
62
+ <%= javascript_tag :app %>
63
+ HTML
64
+ end
65
+
66
+ gsub_file("views/layout.erb", /<link rel="stylesheet" type="text\/css" href="css\/styles.css">/, "")
67
+ gsub_file("views/layout.erb", /<script type="text\/javascript" src="js\/app.js"><\/script>/, "")
68
+ end
69
+
70
+ def directions
71
+ text = <<TEXT
72
+
73
+ Run `bundle install` to get the sprockets gem and its
74
+ dependencies.
75
+
76
+ Running the server in development mode will serve css
77
+ and js files from /assets. In order to serve assets in
78
+ production, you must run `rake assets:precompile`. Read
79
+ the important note below before running this rake task.
80
+ TEXT
81
+
82
+ important = <<TEXT
83
+
84
+ Important Note:
85
+ Any css or js files from the /public folder have been copied
86
+ to /assets, the original files remain intact in /public, but
87
+ will be replaced the first time you run `rake assets:precompile`.
88
+ You may want to backup those files if they are not under source
89
+ control before running the Rake command.
90
+ TEXT
91
+
92
+ say text
93
+ say important, :red
94
+ end
95
+ end
96
+ end
97
+ end
@@ -47,16 +47,6 @@ module Hoboken
47
47
  apply_template("views/index.erb.tt", "views/index.erb")
48
48
  end
49
49
 
50
- def inline_views
51
- return unless options[:tiny]
52
- combined_views = %w(layout index).map do |f|
53
- "@@#{f}\n" + File.read("#{snake_name}/views/#{f}.erb")
54
- end.join("\n")
55
-
56
- append_to_file("#{snake_name}/app.rb", "\n__END__\n\n#{combined_views}")
57
- remove_dir("#{snake_name}/views")
58
- end
59
-
60
50
  def public_folder
61
51
  return if options[:tiny]
62
52
  inside snake_name do
@@ -73,26 +63,45 @@ module Hoboken
73
63
 
74
64
  def test_folder
75
65
  empty_directory("#{snake_name}/test/unit")
66
+ empty_directory("#{snake_name}/test/integration")
76
67
  empty_directory("#{snake_name}/test/support")
77
- apply_template("test/unit/test_helper.rb.tt", "test/unit/test_helper.rb")
68
+ apply_template("test/test_helper.rb.tt", "test/test_helper.rb")
78
69
  apply_template("test/unit/app_test.rb.tt", "test/unit/app_test.rb")
79
70
  apply_template("test/support/rack_test_assertions.rb.tt", "test/support/rack_test_assertions.rb")
80
71
  end
81
72
 
73
+ def env_file
74
+ inside snake_name do
75
+ create_file(".env") do
76
+ "RACK_ENV=development\nPORT=9292"
77
+ end
78
+ end
79
+ end
80
+
82
81
  def make_modular
83
82
  return unless "modular" == options[:type]
84
83
  empty_directory("#{snake_name}/helpers")
85
84
  remove_file("#{snake_name}/app.rb")
86
85
  apply_template("modular.rb.tt", "app.rb")
87
- ["config.ru", "test/unit/test_helper.rb"].each do |f|
86
+ ["config.ru", "test/test_helper.rb"].each do |f|
88
87
  path = File.join(snake_name, f)
89
88
  gsub_file(path, /Sinatra::Application/, "#{camel_name}::App")
90
89
  end
91
90
  end
92
91
 
92
+ def inline_views
93
+ return unless options[:tiny]
94
+ combined_views = %w(layout index).map do |f|
95
+ "@@#{f}\n" + File.read("#{snake_name}/views/#{f}.erb")
96
+ end.join("\n")
97
+
98
+ append_to_file("#{snake_name}/app.rb", "\n__END__\n\n#{combined_views}")
99
+ remove_dir("#{snake_name}/views")
100
+ end
101
+
93
102
  def create_git_repository
94
103
  return unless options[:git]
95
- if system("git --version >#{NULL} 2>&1")
104
+ if has_git?
96
105
  copy_file("templates/gitignore", "#{snake_name}/.gitignore")
97
106
  inside snake_name do
98
107
  run("git init .")
@@ -115,7 +124,7 @@ module Hoboken
115
124
  end
116
125
 
117
126
  def camel_name
118
- Thor::Util.camel_case(name)
127
+ Thor::Util.camel_case(name.split("/").last)
119
128
  end
120
129
 
121
130
  def titleized_name
@@ -123,7 +132,16 @@ module Hoboken
123
132
  end
124
133
 
125
134
  def author
126
- `git config user.name`.chomp
135
+ if has_git?
136
+ `git config user.name`.chomp
137
+ else
138
+ say "\nNo Git executable found. Using result of `whoami` as author name."
139
+ `whoami`.chomp
140
+ end
141
+ end
142
+
143
+ def has_git?
144
+ system("git --version >#{NULL} 2>&1")
127
145
  end
128
146
 
129
147
  def apply_template(src, dest)
@@ -13,3 +13,5 @@ end
13
13
  group :test do
14
14
  gem "contest", "~> 0.1.3"
15
15
  end
16
+
17
+ gem "dotenv", "~> 0.9.0", group: :development
@@ -18,6 +18,11 @@ namespace :test do
18
18
  t.test_files = Dir["test/unit/**/*_test.rb"]
19
19
  end
20
20
 
21
+ Rake::TestTask.new(:integration) do |t|
22
+ t.libs << 'test/unit'
23
+ t.test_files = Dir["test/integration/**/*_test.rb"]
24
+ end
25
+
21
26
  desc "Run all tests"
22
- task :all => %w[test:unit]
27
+ task :all => %w[test:unit test:integration]
23
28
  end
@@ -1,3 +1,5 @@
1
1
  require "bundler/setup"
2
+ require "dotenv"
3
+ Dotenv.load
2
4
  require File.expand_path("../app", __FILE__)
3
5
  run Sinatra::Application
@@ -2,3 +2,4 @@
2
2
  .bundle
3
3
  /tmp
4
4
  tags
5
+ .env
@@ -0,0 +1,19 @@
1
+ namespace :db do
2
+ require 'sequel'
3
+
4
+ Sequel.extension :migration
5
+ DB = Sequel.connect(ENV['DATABASE_URL'] || "sqlite://db/development.db")
6
+
7
+ desc 'Migrate the database to latest version'
8
+ task :migrate do
9
+ Sequel::Migrator.run(DB, 'db/migrate')
10
+ puts '<= db:migrate executed'
11
+ end
12
+
13
+ desc 'Perform migration reset (full erase and migration up)'
14
+ task :reset do
15
+ Sequel::Migrator.run(DB, 'db/migrate', :target => 0)
16
+ Sequel::Migrator.run(DB, 'db/migrate')
17
+ puts '<= db:reset executed'
18
+ end
19
+ end
@@ -6,6 +6,11 @@ module Rack::Test::Assertions
6
6
  :redirect => 302
7
7
  }
8
8
 
9
+ CONTENT_TYPES = {
10
+ :json => "application/json;charset=utf-8",
11
+ :html => "text/html;charset=utf-8"
12
+ }
13
+
9
14
  def assert_body_contains(expected, message=nil)
10
15
  msg = build_message(message, "expected body to contain <?>\n#{last_response.body}", expected)
11
16
  assert_block(msg) do
@@ -13,6 +18,14 @@ module Rack::Test::Assertions
13
18
  end
14
19
  end
15
20
 
21
+ def assert_content_type(content_type)
22
+ unless CONTENT_TYPES.keys.include?(content_type)
23
+ raise ArgumentError, "unrecognized content_type (#{content_type})"
24
+ end
25
+
26
+ assert_equal CONTENT_TYPES[content_type], last_response.content_type
27
+ end
28
+
16
29
  def assert_flash(type=:notice, message=nil)
17
30
  msg = build_message(message, "expected <?> flash to exist, but was nil", type.to_s)
18
31
  assert_block(msg) do
@@ -40,13 +53,13 @@ module Rack::Test::Assertions
40
53
  assert_has_session
41
54
  msg = build_message(message, "expected session to have key named <?>", key)
42
55
  assert_block(msg) do
43
- last_request.env["rack.session"].keys.include?(key)
56
+ last_request.env["rack.session"].keys.include?(key.to_s)
44
57
  end
45
58
  end
46
59
 
47
60
  def assert_session(key, expected, message=nil)
48
61
  assert_session_has_key(key)
49
- actual = last_request.env["rack.session"][key]
62
+ actual = last_request.env["rack.session"][key.to_s]
50
63
  msg = build_message(message, "expected session key <?> to be <?>, but was <?>", key, expected, actual)
51
64
  assert_block(msg) do
52
65
  expected == actual
@@ -4,8 +4,11 @@ require "bundler/setup"
4
4
  require "test/unit"
5
5
  require "contest"
6
6
  require "rack/test"
7
- require_relative "../support/rack_test_assertions"
8
- require_relative "../../app"
7
+ require "dotenv"
8
+ require_relative "support/rack_test_assertions"
9
+ require_relative "../app"
10
+
11
+ Dotenv.load
9
12
 
10
13
  class Test::Unit::TestCase
11
14
  # Syntactic sugar for defining a memoized helper method.
@@ -1,4 +1,4 @@
1
- require_relative "test_helper"
1
+ require_relative "../test_helper"
2
2
 
3
3
  class AppTest < Rack::Test::TestCase
4
4
  test "GET /" do
@@ -1,3 +1,3 @@
1
1
  module Hoboken
2
- VERSION = "0.0.1.beta2"
2
+ VERSION = "0.0.1.beta3"
3
3
  end
@@ -0,0 +1,118 @@
1
+ require_relative "../test_helper"
2
+
3
+ class AddOnTest < IntegrationTestCase
4
+ def test_metrics_add_on
5
+ run_hoboken(:generate) do
6
+ bin_path = File.expand_path("../../../bin/hoboken", __FILE__)
7
+ execute("#{bin_path} add:metrics")
8
+ assert_file("Gemfile", /flog/, /flay/, /simplecov/)
9
+ assert_file("tasks/metrics.rake")
10
+ assert_file("test/test_helper.rb",
11
+ <<CODE
12
+
13
+ require 'simplecov'
14
+ SimpleCov.start do
15
+ add_filter "/test/"
16
+ coverage_dir 'tmp/coverage'
17
+ end
18
+
19
+ CODE
20
+ )
21
+ end
22
+ end
23
+
24
+ def test_internationalization_add_on_classic
25
+ run_hoboken(:generate) do
26
+ bin_path = File.expand_path("../../../bin/hoboken", __FILE__)
27
+ execute("#{bin_path} add:i18n")
28
+ assert_file("Gemfile", "sinatra-r18n")
29
+ assert_file("app.rb", 'require "sinatra/r18n"')
30
+ assert_file("i18n/en.yml")
31
+ end
32
+ end
33
+
34
+ def test_internationalization_add_on_modular
35
+ run_hoboken(:generate, type: :modular) do
36
+ bin_path = File.expand_path("../../../bin/hoboken", __FILE__)
37
+ execute("#{bin_path} add:i18n")
38
+ assert_file("Gemfile", "sinatra-r18n")
39
+ assert_file("app.rb", 'require "sinatra/r18n"', "register Sinatra::R18n")
40
+ assert_file("i18n/en.yml")
41
+ end
42
+ end
43
+
44
+ def test_heroku_add_on
45
+ run_hoboken(:generate) do
46
+ bin_path = File.expand_path("../../../bin/hoboken", __FILE__)
47
+ execute("#{bin_path} add:heroku")
48
+ assert_file("Gemfile", "foreman")
49
+ assert_file("Procfile")
50
+ assert_file(".slugignore")
51
+ assert_file("config.ru", /\$stdout.sync = true/)
52
+ assert_file("Rakefile", /exec\("foreman start"\)/)
53
+ end
54
+ end
55
+
56
+ def test_sprockets_add_on_classic
57
+ run_hoboken(:generate) do
58
+ bin_path = File.expand_path("../../../bin/hoboken", __FILE__)
59
+ execute("#{bin_path} add:sprockets")
60
+ assert_file("assets/styles.css")
61
+ assert_file("assets/app.js")
62
+ assert_file("Gemfile", "sprockets", "uglifier", "yui-compressor")
63
+ assert_file("tasks/sprockets.rake")
64
+ assert_file("middleware/sprockets_chain.rb")
65
+ assert_file("helpers/sprockets.rb")
66
+ assert_file("app.rb", <<CODE
67
+ if development?
68
+ require "sinatra/reloader"
69
+
70
+ require File.expand_path('middleware/sprockets_chain', settings.root)
71
+ use Middleware::SprocketsChain, %r{/assets} do |env|
72
+ %w(assets vendor).each do |f|
73
+ env.append_path File.expand_path("../\#{f}", __FILE__)
74
+ end
75
+ end
76
+ end
77
+
78
+ helpers Helpers::Sprockets
79
+ CODE
80
+ )
81
+ assert_file("views/layout.erb", <<CODE
82
+ <%= stylesheet_tag :styles %>
83
+
84
+ <%= javascript_tag :app %>
85
+ CODE
86
+ )
87
+ end
88
+ end
89
+
90
+ def test_sprockets_add_on_modular
91
+ run_hoboken(:generate, type: :modular) do
92
+ bin_path = File.expand_path("../../../bin/hoboken", __FILE__)
93
+ execute("#{bin_path} add:sprockets")
94
+ assert_file("assets/styles.css")
95
+ assert_file("assets/app.js")
96
+ assert_file("Gemfile", "sprockets", "uglifier", "yui-compressor")
97
+ assert_file("tasks/sprockets.rake")
98
+ assert_file("middleware/sprockets_chain.rb")
99
+ assert_file("helpers/sprockets.rb")
100
+ assert_file("app.rb", <<CODE
101
+ configure :development do
102
+ require File.expand_path('middleware/sprockets_chain', settings.root)
103
+ use Middleware::SprocketsChain, %r{/assets} do |env|
104
+ %w(assets vendor).each do |f|
105
+ env.append_path File.expand_path("../\#{f}", __FILE__)
106
+ end
107
+ end
108
+ CODE
109
+ )
110
+ assert_file("views/layout.erb", <<CODE
111
+ <%= stylesheet_tag :styles %>
112
+
113
+ <%= javascript_tag :app %>
114
+ CODE
115
+ )
116
+ end
117
+ end
118
+ end
@@ -0,0 +1,71 @@
1
+ require_relative "../test_helper"
2
+
3
+ class GenerateTest < IntegrationTestCase
4
+ def test_generate_classic
5
+ run_hoboken(:generate) do
6
+ assert_file ".env"
7
+ assert_file "Gemfile"
8
+ assert_file "README.md"
9
+ assert_file "Rakefile"
10
+ assert_file "app.rb", /require "sinatra"/
11
+ assert_file "config.ru", /run Sinatra::Application/
12
+ assert_directory "public"
13
+ assert_directory "test"
14
+ assert_file "views/index.erb"
15
+ assert_file "views/layout.erb"
16
+ end
17
+ end
18
+
19
+ def test_generate_classic_tiny
20
+ run_hoboken(:generate, tiny: true) do
21
+ refute_directory("public")
22
+ assert_file "app.rb", /__END__/, /@@layout/, /@@index/
23
+ end
24
+ end
25
+
26
+ def test_generate_classic_can_run_tests
27
+ run_hoboken(:generate) do
28
+ assert_match /1 tests, 1 assertions, 0 failures, 0 errors, 0 skips/, execute("rake test:all")
29
+ end
30
+ end
31
+
32
+ def test_generate_modular
33
+ run_hoboken(:generate, type: :modular) do
34
+ assert_file ".env"
35
+ assert_file "Gemfile"
36
+ assert_file "README.md"
37
+ assert_file "Rakefile"
38
+ assert_file "app.rb", /require "sinatra\/base"/, /module Sample/, /class App < Sinatra::Base/
39
+ assert_file "config.ru", /run Sample::App/
40
+ assert_directory "public"
41
+ assert_file "test/test_helper.rb", /Sample::App/
42
+ assert_file "views/index.erb"
43
+ assert_file "views/layout.erb"
44
+ end
45
+ end
46
+
47
+ def test_generate_modular_tiny
48
+ run_hoboken(:generate, tiny: true, type: :modular) do
49
+ refute_directory("public")
50
+ assert_file "app.rb", /__END__/, /@@layout/, /@@index/
51
+ end
52
+ end
53
+
54
+ def test_generate_modular_can_run_tests
55
+ run_hoboken(:generate, type: :modular) do
56
+ assert_match /1 tests, 1 assertions, 0 failures, 0 errors, 0 skips/, execute("rake test:all")
57
+ end
58
+ end
59
+
60
+ def test_generate_with_ruby_version
61
+ run_hoboken(:generate, ruby_version: "2.1.0") do
62
+ assert_file "Gemfile", /ruby "2\.1\.0"/
63
+ end
64
+ end
65
+
66
+ def test_generate_with_git
67
+ run_hoboken(:generate, git: true) do
68
+ assert_directory ".git"
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,69 @@
1
+ require "test/unit"
2
+ require "fileutils"
3
+
4
+ $hoboken_counter = 0
5
+ DESTINATION = File.expand_path("../tmp", __FILE__)
6
+ FileUtils.rm_rf(DESTINATION)
7
+
8
+ class IntegrationTestCase < Test::Unit::TestCase
9
+ def teardown
10
+ if self.passed?
11
+ FileUtils.rm_rf("#{DESTINATION}/#{$hoboken_counter}")
12
+ else
13
+ puts "Left #{DESTINATION}/#{$hoboken_counter}/sample in place since test failed."
14
+ end
15
+ end
16
+
17
+ def run_hoboken(command, **opts)
18
+ options = Array.new.tap do |o|
19
+ o << "--git" if opts.fetch(:git) { false }
20
+ o << "--tiny" if opts.fetch(:tiny) { false }
21
+ o << "--type=#{opts[:type]}" if opts.has_key?(:type)
22
+ o << "--ruby-version=#{opts[:ruby_version]}" if opts.has_key?(:ruby_version)
23
+ end
24
+
25
+ $hoboken_counter += 1
26
+ bin_path = File.expand_path("../../bin/hoboken", __FILE__)
27
+
28
+ `#{bin_path} #{command} #{DESTINATION}/#{$hoboken_counter}/sample #{options.join(" ")}`
29
+ yield
30
+ end
31
+
32
+ def execute(command)
33
+ current_path = Dir.pwd
34
+ FileUtils.cd("#{DESTINATION}/#{$hoboken_counter}/sample")
35
+ `bundle install` unless File.exists?("Gemfile.lock")
36
+ `#{command}`
37
+ ensure
38
+ FileUtils.cd(current_path)
39
+ end
40
+
41
+ def assert_file(filename, *contents)
42
+ full_path = File.join(DESTINATION, $hoboken_counter.to_s, "sample", filename)
43
+ assert_block("expected #{filename.inspect} to exist") do
44
+ File.exists?(full_path)
45
+ end
46
+
47
+ unless contents.empty?
48
+ read = File.read(full_path)
49
+ contents.each do |content|
50
+ assert_block("expected #{filename.inspect} to contain #{content}:\n#{read}") do
51
+ pattern = content.is_a?(Regexp) ? content : /#{content}/
52
+ read =~ pattern
53
+ end
54
+ end
55
+ end
56
+ end
57
+
58
+ def assert_directory(name)
59
+ assert_block("expected #{name} directory to exist") do
60
+ File.directory?(File.join(DESTINATION, $hoboken_counter.to_s, "sample", name))
61
+ end
62
+ end
63
+
64
+ def refute_directory(name)
65
+ assert_block("did not expect directory #{name} to exist") do
66
+ !File.directory?(File.join(DESTINATION, $hoboken_counter.to_s, "sample", name))
67
+ end
68
+ end
69
+ end
@@ -1,4 +1,4 @@
1
- require "test/unit"
1
+ require_relative "../test_helper"
2
2
  require_relative "../../lib/hoboken/actions.rb"
3
3
 
4
4
  module Hoboken
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hoboken
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1.beta2
4
+ version: 0.0.1.beta3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bob Nadler
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-01-05 00:00:00.000000000 Z
11
+ date: 2014-03-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -69,6 +69,10 @@ files:
69
69
  - hoboken.gemspec
70
70
  - lib/hoboken.rb
71
71
  - lib/hoboken/actions.rb
72
+ - lib/hoboken/add_ons/heroku.rb
73
+ - lib/hoboken/add_ons/internationalization.rb
74
+ - lib/hoboken/add_ons/metrics.rb
75
+ - lib/hoboken/add_ons/sprockets.rb
72
76
  - lib/hoboken/generate.rb
73
77
  - lib/hoboken/templates/Gemfile.erb.tt
74
78
  - lib/hoboken/templates/README.md.tt
@@ -81,19 +85,23 @@ files:
81
85
  - lib/hoboken/templates/hoboken.png
82
86
  - lib/hoboken/templates/metrics.rake.tt
83
87
  - lib/hoboken/templates/modular.rb.tt
88
+ - lib/hoboken/templates/sequel.rake
84
89
  - lib/hoboken/templates/sinatra.png
85
90
  - lib/hoboken/templates/sprockets.rake
86
91
  - lib/hoboken/templates/sprockets_chain.rb
87
92
  - lib/hoboken/templates/sprockets_helper.rb
88
93
  - lib/hoboken/templates/styles.css.tt
89
94
  - lib/hoboken/templates/test/support/rack_test_assertions.rb.tt
95
+ - lib/hoboken/templates/test/test_helper.rb.tt
90
96
  - lib/hoboken/templates/test/unit/app_test.rb.tt
91
- - lib/hoboken/templates/test/unit/test_helper.rb.tt
92
97
  - lib/hoboken/templates/views/index.erb.tt
93
98
  - lib/hoboken/templates/views/layout.erb.tt
94
99
  - lib/hoboken/version.rb
95
100
  - test/fixtures/Gemfile
96
101
  - test/fixtures/Gemfile.pristine
102
+ - test/integration/add_on_test.rb
103
+ - test/integration/generate_test.rb
104
+ - test/test_helper.rb
97
105
  - test/unit/hoboken_actions_test.rb
98
106
  homepage: https://github.com/bnadlerjr/hoboken
99
107
  licenses:
@@ -122,4 +130,7 @@ summary: Sinatra project generator.
122
130
  test_files:
123
131
  - test/fixtures/Gemfile
124
132
  - test/fixtures/Gemfile.pristine
133
+ - test/integration/add_on_test.rb
134
+ - test/integration/generate_test.rb
135
+ - test/test_helper.rb
125
136
  - test/unit/hoboken_actions_test.rb