hoboken 0.0.1 → 0.9.0

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 (65) hide show
  1. checksums.yaml +5 -5
  2. data/.github/dependabot.yml +7 -0
  3. data/.github/workflows/ruby.yml +28 -0
  4. data/.rubocop.yml +33 -0
  5. data/.ruby-version +1 -0
  6. data/Gemfile +2 -0
  7. data/IDEAS.md +57 -0
  8. data/LICENSE.txt +1 -1
  9. data/README.md +21 -10
  10. data/Rakefile +14 -6
  11. data/bin/hoboken +2 -1
  12. data/hoboken.gemspec +53 -16
  13. data/lib/hoboken.rb +110 -23
  14. data/lib/hoboken/actions.rb +10 -6
  15. data/lib/hoboken/add_ons/github_action.rb +14 -0
  16. data/lib/hoboken/add_ons/heroku.rb +8 -23
  17. data/lib/hoboken/add_ons/internationalization.rb +10 -6
  18. data/lib/hoboken/add_ons/metrics.rb +39 -14
  19. data/lib/hoboken/add_ons/omniauth.rb +114 -47
  20. data/lib/hoboken/add_ons/rubocop.rb +40 -0
  21. data/lib/hoboken/add_ons/sequel.rb +76 -47
  22. data/lib/hoboken/add_ons/sprockets.rb +67 -65
  23. data/lib/hoboken/add_ons/travis.rb +6 -2
  24. data/lib/hoboken/add_ons/twbs.rb +80 -0
  25. data/lib/hoboken/generate.rb +112 -38
  26. data/lib/hoboken/templates/Gemfile.erb.tt +33 -10
  27. data/lib/hoboken/templates/README.md.tt +105 -35
  28. data/lib/hoboken/templates/Rakefile.tt +10 -22
  29. data/lib/hoboken/templates/classic.rb.tt +35 -8
  30. data/lib/hoboken/templates/config.ru.tt +5 -3
  31. data/lib/hoboken/templates/console.sh +5 -0
  32. data/lib/hoboken/templates/db.rb.tt +24 -0
  33. data/lib/hoboken/templates/github_action.tt +28 -0
  34. data/lib/hoboken/templates/gitignore +8 -1
  35. data/lib/hoboken/templates/metrics.rake.tt +10 -9
  36. data/lib/hoboken/templates/modular.rb.tt +40 -11
  37. data/lib/hoboken/templates/puma.rb.tt +21 -0
  38. data/lib/hoboken/templates/rspec.rake.tt +5 -0
  39. data/lib/hoboken/templates/rubocop.yml.tt +31 -0
  40. data/lib/hoboken/templates/sequel.rake +6 -4
  41. data/lib/hoboken/templates/server.sh +12 -0
  42. data/lib/hoboken/templates/setup.sh +7 -0
  43. data/lib/hoboken/templates/spec/app_spec.rb.tt +15 -0
  44. data/lib/hoboken/templates/spec/rack_matchers.rb.tt +56 -0
  45. data/lib/hoboken/templates/spec/spec_helper.rb.tt +41 -0
  46. data/lib/hoboken/templates/sprockets.rake +13 -7
  47. data/lib/hoboken/templates/sprockets_chain.rb +7 -3
  48. data/lib/hoboken/templates/sprockets_helper.rb +14 -10
  49. data/lib/hoboken/templates/support/rack_helpers.rb.tt +55 -0
  50. data/lib/hoboken/templates/support/rack_test_assertions.rb.tt +111 -0
  51. data/lib/hoboken/templates/test/test_helper.rb.tt +38 -27
  52. data/lib/hoboken/templates/test/unit/app_test.rb.tt +11 -3
  53. data/lib/hoboken/templates/test_unit.rake.tt +18 -0
  54. data/lib/hoboken/templates/views/index.erb.tt +10 -3
  55. data/lib/hoboken/templates/views/layout.erb.tt +4 -1
  56. data/lib/hoboken/version.rb +3 -1
  57. data/test/fixtures/Gemfile +3 -3
  58. data/test/fixtures/Gemfile.pristine +3 -2
  59. data/test/integration/add_on_test.rb +399 -136
  60. data/test/integration/generate_test.rb +170 -38
  61. data/test/test_helper.rb +54 -23
  62. data/test/unit/hoboken_actions_test.rb +70 -61
  63. metadata +441 -16
  64. data/.travis.yml +0 -5
  65. data/lib/hoboken/templates/test/support/rack_test_assertions.rb.tt +0 -92
@@ -1,39 +1,50 @@
1
- ENV["RACK_ENV"] = "test"
1
+ # frozen_string_literal: true
2
2
 
3
- require "bundler/setup"
4
- require "test/unit"
5
- require "contest"
6
- require "rack/test"
7
- require "dotenv"
8
- require_relative "support/rack_test_assertions"
9
- require_relative "../app"
3
+ ENV['RACK_ENV'] = 'test'
4
+
5
+ require 'bundler/setup'
6
+
7
+ require 'warning'
8
+
9
+ # Ignore all warnings in Gem dependencies
10
+ Gem.path.each { |path| Warning.ignore(//, path) }
11
+
12
+ require 'dotenv'
13
+ require 'test/unit'
14
+ require 'contest'
15
+ require 'rack/test'
16
+
17
+ require_relative 'support/rack_helpers'
18
+ require_relative '../app'
10
19
 
11
20
  Dotenv.load
12
21
 
13
- class Test::Unit::TestCase
14
- # Syntactic sugar for defining a memoized helper method.
15
- def self.let(name, &block)
16
- ivar = "@#{name}"
17
- self.class_eval do
18
- define_method(name) do
19
- if instance_variable_defined?(ivar)
20
- instance_variable_get(ivar)
21
- else
22
- value = self.instance_eval(&block)
23
- instance_variable_set(ivar, value)
22
+ module Test
23
+ module Unit
24
+ class TestCase
25
+ # Syntactic sugar for defining a memoized helper method.
26
+ #
27
+ def self.let(name, &block)
28
+ ivar = "@#{name}"
29
+ class_eval do
30
+ define_method(name) do
31
+ if instance_variable_defined?(ivar)
32
+ instance_variable_get(ivar)
33
+ else
34
+ value = instance_eval(&block)
35
+ instance_variable_set(ivar, value)
36
+ end
37
+ end
24
38
  end
25
39
  end
26
40
  end
27
41
  end
28
42
  end
29
43
 
30
- class Rack::Test::TestCase < Test::Unit::TestCase
31
- include Rack::Test::Methods
32
- include Rack::Test::Assertions
33
-
34
- private
35
-
36
- def app
37
- Sinatra::Application
44
+ module Rack
45
+ module Test
46
+ class TestCase < ::Test::Unit::TestCase
47
+ include RackHelpers
48
+ end
38
49
  end
39
50
  end
@@ -1,8 +1,16 @@
1
- require_relative "../test_helper"
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../test_helper'
2
4
 
3
5
  class AppTest < Rack::Test::TestCase
4
- test "GET /" do
5
- get "/"
6
+ test 'GET /' do
7
+ get '/'
6
8
  assert_response :ok
9
+ <% if options[:api_only] -%>
10
+ assert_content_type(:json)
11
+ <% else -%>
12
+ assert_content_type(:html)
13
+ <% end -%>
14
+ assert_body_contains('Smoke test successful!')
7
15
  end
8
16
  end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rake/testtask'
4
+
5
+ namespace :test do
6
+ Rake::TestTask.new(:unit) do |t|
7
+ t.libs << 'test/unit'
8
+ t.test_files = Dir['test/unit/**/*_test.rb']
9
+ end
10
+
11
+ Rake::TestTask.new(:integration) do |t|
12
+ t.libs << 'test/unit'
13
+ t.test_files = Dir['test/integration/**/*_test.rb']
14
+ end
15
+
16
+ desc 'Run all tests'
17
+ task all: %w[test:unit test:integration]
18
+ end
@@ -51,9 +51,10 @@
51
51
  <p>The following Rake tasks are available:</p>
52
52
  <table>
53
53
  <tr>
54
- <td>rake server</td>
55
- <th>Start the development server</th>
54
+ <td>rake ci</td>
55
+ <th>Run CI checks</th>
56
56
  </tr>
57
+ <% if 'test-unit' == options[:test_framework] -%>
57
58
  <tr>
58
59
  <td>rake test:all</td>
59
60
  <th>Run all tests</th>
@@ -62,6 +63,12 @@
62
63
  <td>rake test:unit</td>
63
64
  <th>Run unit tests</th>
64
65
  </tr>
66
+ <% else -%>
67
+ <tr>
68
+ <td>rake spec</td>
69
+ <th>Run RSpec</th>
70
+ </tr>
71
+ <% end -%>
65
72
  </table>
66
73
 
67
74
  <h3>Add Ons</h3>
@@ -70,7 +77,7 @@
70
77
 
71
78
  <h3>Links</h3>
72
79
  <ul>
73
- <li><a href="https://github.com/bnadlerjr/hoboken">Documentation</a></li>
80
+ <li><a href="http://bobnadler.com/hoboken">Documentation</a></li>
74
81
  <li><a href="https://github.com/bnadlerjr/hoboken">Source Code</a></li>
75
82
  </ul>
76
83
 
@@ -8,6 +8,9 @@
8
8
  <script type="text/javascript" src="js/app.js"></script>
9
9
  </head>
10
10
  <body>
11
- <%%= yield %>
11
+ <% unless options[:api_only] -%>
12
+ <%%= styled_flash %>
13
+ <% end -%>
14
+ <%%== yield %>
12
15
  </body>
13
16
  </html>
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Hoboken
2
- VERSION = "0.0.1"
4
+ VERSION = '0.9.0'
3
5
  end
@@ -1,4 +1,4 @@
1
- source "https://rubygems.org"
2
- ruby "2.0.0"
1
+ source 'https://rubygems.org'
2
+ ruby '2.0.0'
3
3
 
4
- gem "sinatra"
4
+ gem 'sinatra'
@@ -1,2 +1,3 @@
1
- source "https://rubygems.org"
2
- ruby "2.0.0"
1
+ source 'https://rubygems.org'
2
+ ruby '2.0.0'
3
+
@@ -1,242 +1,505 @@
1
- require_relative "../test_helper"
1
+ # frozen_string_literal: true
2
2
 
3
+ require_relative '../test_helper'
4
+
5
+ # rubocop:disable Metrics/ClassLength
3
6
  class AddOnTest < IntegrationTestCase
7
+ # rubocop:disable Metrics/MethodLength
4
8
  def test_metrics_add_on
5
9
  run_hoboken(:generate) do
6
- bin_path = File.expand_path("../../../bin/hoboken", __FILE__)
10
+ bin_path = File.expand_path('../../bin/hoboken', __dir__)
7
11
  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
12
+ assert_file('Gemfile', /flog/, /flay/, /simplecov/)
13
+ assert_file('tasks/metrics.rake')
14
+
15
+ assert_file('test/test_helper.rb', <<~CODE
16
+ require 'simplecov'
17
+ SimpleCov.start do
18
+ add_filter '/bin/'
19
+ add_filter '/config/'
20
+ add_filter '/test/'
21
+ coverage_dir 'tmp/coverage'
22
+ end
18
23
 
19
- CODE
20
- )
24
+ CODE
25
+ )
26
+
27
+ assert_match(/no offenses detected/, execute('rubocop'))
21
28
  end
22
29
  end
30
+ # rubocop:enable Metrics/MethodLength
23
31
 
24
32
  def test_internationalization_add_on_classic
25
33
  run_hoboken(:generate) do
26
- bin_path = File.expand_path("../../../bin/hoboken", __FILE__)
34
+ bin_path = File.expand_path('../../bin/hoboken', __dir__)
27
35
  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")
36
+ assert_file('Gemfile', 'sinatra-r18n')
37
+ assert_file('app.rb', "require 'sinatra/r18n'")
38
+ assert_file('i18n/en.yml')
39
+ assert_match(/no offenses detected/, execute('rubocop'))
31
40
  end
32
41
  end
33
42
 
34
43
  def test_internationalization_add_on_modular
35
44
  run_hoboken(:generate, type: :modular) do
36
- bin_path = File.expand_path("../../../bin/hoboken", __FILE__)
45
+ bin_path = File.expand_path('../../bin/hoboken', __dir__)
37
46
  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")
47
+ assert_file('Gemfile', 'sinatra-r18n')
48
+ assert_file('app.rb', "require 'sinatra/r18n'", 'register Sinatra::R18n')
49
+ assert_file('i18n/en.yml')
50
+ assert_match(/no offenses detected/, execute('rubocop'))
41
51
  end
42
52
  end
43
53
 
44
54
  def test_heroku_add_on
45
55
  run_hoboken(:generate) do
46
- bin_path = File.expand_path("../../../bin/hoboken", __FILE__)
56
+ bin_path = File.expand_path('../../bin/hoboken', __dir__)
47
57
  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"\)/)
58
+ assert_file('.slugignore')
59
+ assert_file('config.ru', /\$stdout.sync = true/)
60
+ assert_match(/no offenses detected/, execute('rubocop'))
53
61
  end
54
62
  end
55
63
 
64
+ # rubocop:disable Metrics/MethodLength
65
+ # rubocop:disable Metrics/AbcSize
56
66
  def test_sprockets_add_on_classic
57
67
  run_hoboken(:generate) do
58
- bin_path = File.expand_path("../../../bin/hoboken", __FILE__)
68
+ bin_path = File.expand_path('../../bin/hoboken', __dir__)
59
69
  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
+ assert_file('assets/styles.scss')
71
+ assert_file('assets/app.js')
72
+ assert_file('Gemfile', 'sassc', 'sprockets', 'uglifier', 'yui-compressor')
73
+ assert_file('tasks/sprockets.rake')
74
+ assert_file('middleware/sprockets_chain.rb')
75
+ assert_file('helpers/sprockets.rb')
76
+
77
+ assert_file('app.rb', <<CODE
70
78
  require File.expand_path('middleware/sprockets_chain', settings.root)
71
79
  use Middleware::SprocketsChain, %r{/assets} do |env|
72
- %w(assets vendor).each do |f|
80
+ %w[assets vendor].each do |f|
73
81
  env.append_path File.expand_path("../\#{f}", __FILE__)
74
82
  end
75
83
  end
76
- end
77
-
78
- helpers Helpers::Sprockets
79
84
  CODE
80
- )
81
- assert_file("views/layout.erb", <<CODE
82
- <%= stylesheet_tag :styles %>
85
+ )
83
86
 
84
- <%= javascript_tag :app %>
87
+ assert_file('app.rb', /helpers Helpers::Sprockets/)
88
+ assert_file('views/layout.erb', <<CODE
89
+ <%== stylesheet_tag :styles %>
90
+ <%== javascript_tag :app %>
85
91
  CODE
86
- )
92
+ )
93
+
94
+ assert_match(
95
+ /successfully compiled css assets/,
96
+ execute('rake assets:precompile_css')
97
+ )
98
+
99
+ assert_match(
100
+ /successfully compiled javascript assets/,
101
+ execute('rake assets:precompile_js')
102
+ )
103
+
104
+ assert_match(/no offenses detected/, execute('rubocop'))
87
105
  end
88
106
  end
107
+ # rubocop:enable Metrics/MethodLength
108
+ # rubocop:enable Metrics/AbcSize
89
109
 
110
+ # rubocop:disable Metrics/MethodLength
111
+ # rubocop:disable Metrics/AbcSize
90
112
  def test_sprockets_add_on_modular
91
113
  run_hoboken(:generate, type: :modular) do
92
- bin_path = File.expand_path("../../../bin/hoboken", __FILE__)
114
+ bin_path = File.expand_path('../../bin/hoboken', __dir__)
93
115
  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
116
+ assert_file('assets/styles.scss')
117
+ assert_file('assets/app.js')
118
+ assert_file('Gemfile', 'sassc', 'sprockets', 'uglifier', 'yui-compressor')
119
+ assert_file('tasks/sprockets.rake')
120
+ assert_file('middleware/sprockets_chain.rb')
121
+ assert_file('helpers/sprockets.rb')
122
+
123
+ assert_file('app.rb', <<CODE
101
124
  configure :development do
102
125
  require File.expand_path('middleware/sprockets_chain', settings.root)
103
126
  use Middleware::SprocketsChain, %r{/assets} do |env|
104
- %w(assets vendor).each do |f|
127
+ %w[assets vendor].each do |f|
105
128
  env.append_path File.expand_path("../\#{f}", __FILE__)
106
129
  end
107
130
  end
108
131
  CODE
109
- )
110
- assert_file("views/layout.erb", <<CODE
111
- <%= stylesheet_tag :styles %>
132
+ )
112
133
 
113
- <%= javascript_tag :app %>
134
+ assert_file('views/layout.erb', <<CODE
135
+ <%== stylesheet_tag :styles %>
136
+ <%== javascript_tag :app %>
114
137
  CODE
115
- )
138
+ )
139
+
140
+ assert_match(
141
+ /successfully compiled css assets/,
142
+ execute('rake assets:precompile_css')
143
+ )
144
+
145
+ assert_match(
146
+ /successfully compiled javascript assets/,
147
+ execute('rake assets:precompile_js')
148
+ )
149
+
150
+ assert_match(/no offenses detected/, execute('rubocop'))
116
151
  end
117
152
  end
153
+ # rubocop:enable Metrics/MethodLength
154
+ # rubocop:enable Metrics/AbcSize
118
155
 
119
156
  def test_travis_add_on
120
157
  run_hoboken(:generate) do
121
- bin_path = File.expand_path("../../../bin/hoboken", __FILE__)
158
+ bin_path = File.expand_path('../../bin/hoboken', __dir__)
122
159
  execute("#{bin_path} add:travis")
123
- assert_file(".travis.yml", "language: ruby")
160
+ assert_file('.travis.yml', 'language: ruby')
124
161
  end
125
162
  end
126
163
 
164
+ # rubocop:disable Metrics/MethodLength
127
165
  def test_sequel_add_on
128
166
  run_hoboken(:generate) do
129
- bin_path = File.expand_path("../../../bin/hoboken", __FILE__)
167
+ bin_path = File.expand_path('../../bin/hoboken', __dir__)
130
168
  execute("#{bin_path} add:sequel")
131
- assert_file("Gemfile", "sequel", "sqlite3")
132
- assert_file("tasks/sequel.rake")
169
+ assert_file('Gemfile', 'sequel', 'sqlite3')
170
+ assert_file('tasks/sequel.rake')
171
+
172
+ assert_file('config/db.rb')
173
+
174
+ assert_file(
175
+ 'test/test_helper.rb',
176
+ %r{ENV\['DATABASE_URL'\] = 'sqlite://db/test\.db'}
177
+ )
178
+
179
+ assert_file('test/test_helper.rb', /require 'sequel'/)
180
+ assert_file('test/test_helper.rb', <<~CODE
181
+ module Test
182
+ module Database
183
+ class TestCase < Test::Unit::TestCase
184
+ def run(*args, &block)
185
+ result = nil
186
+ DB.transaction(rollback: :always) { result = super }
187
+ result
188
+ end
189
+ end
190
+ end
191
+ end
192
+ CODE
193
+ )
133
194
 
134
- assert_file("config.ru", /require "logger"/)
135
- assert_file("config.ru", /require "sequel"/)
136
- assert_file("config.ru", <<CODE
195
+ result = execute('rake test:all')
196
+ assert_match(/1 tests, 3 assertions, 0 failures, 0 errors/, result)
197
+ assert_match(/no offenses detected/, execute('rubocop'))
198
+ end
199
+ end
200
+ # rubocop:enable Metrics/MethodLength
137
201
 
138
- db = Sequel.connect(ENV["DATABASE_URL"], loggers: [Logger.new($stdout)])
139
- Sequel.extension :migration
140
- Sequel::Migrator.check_current(db, "db/migrate") if Dir.glob("db/migrate/*.rb").size > 0
202
+ # rubocop:disable Metrics/MethodLength
203
+ def test_sequel_add_on_with_rspec
204
+ run_hoboken(:generate, test_framework: 'rspec') do
205
+ bin_path = File.expand_path('../../bin/hoboken', __dir__)
206
+ execute("#{bin_path} add:sequel")
141
207
 
142
- app = Sinatra::Application
143
- app.set :database, db
144
- run app
145
- CODE
146
- )
208
+ assert_file(
209
+ 'spec/spec_helper.rb',
210
+ %r{ENV\['DATABASE_URL'\] = 'sqlite://db/test\.db'}
211
+ )
147
212
 
148
- assert_file("test/test_helper.rb", /require "sequel"/)
149
- assert_file("test/test_helper.rb", <<CODE
213
+ assert_file('spec/spec_helper.rb', <<-CODE
214
+ config.around(:example, rack: true) do |example|
215
+ DB.transaction(rollback: :always) { example.run }
216
+ end
150
217
 
151
- module Test::Database
152
- class TestCase < Test::Unit::TestCase
153
- def run(*args, &block)
154
- result = nil
155
- database.transaction(rollback: :always) { result = super }
156
- result
157
- end
218
+ config.around(:example, database: true) do |example|
219
+ DB.transaction(rollback: :always) { example.run }
220
+ end
158
221
 
159
- private
222
+ CODE
223
+ )
160
224
 
161
- def database
162
- @database ||= Sequel.sqlite.tap do |db|
163
- Sequel.extension :migration
164
- Sequel::Migrator.run(db, 'db/migrate') if Dir.glob("db/migrate/*.rb").size > 0
165
- end
166
- end
167
- end
168
- end
169
- CODE
170
- )
225
+ result = execute('rake spec')
226
+ assert_match(/3 examples, 0 failures/, result)
227
+ assert_match(/no offenses detected/, execute('rubocop'))
171
228
  end
172
229
  end
230
+ # rubocop:enable Metrics/MethodLength
173
231
 
232
+ # rubocop:disable Metrics/MethodLength
174
233
  def test_omniauth_add_on
175
234
  run_hoboken(:generate) do
176
- bin_path = File.expand_path("../../../bin/hoboken", __FILE__)
235
+ bin_path = File.expand_path('../../bin/hoboken', __dir__)
177
236
  execute("(echo 'twitter' && echo '0.0.1') | #{bin_path} add:omniauth")
178
- assert_file("Gemfile", "omniauth-twitter")
179
- assert_file("app.rb", /require "omniauth-twitter"/)
180
- assert_file("app.rb", <<CODE
181
-
182
- use OmniAuth::Builder do
183
- provider :twitter, ENV["TWITTER_KEY"], ENV["TWITTER_SECRET"]
184
- end
185
-
237
+ assert_file('Gemfile', 'omniauth-twitter')
238
+ assert_file('app.rb', /require 'omniauth-twitter'/)
239
+ assert_file('app.rb', %r{require 'sinatra/json'})
240
+ assert_file('app.rb', <<CODE
241
+ use OmniAuth::Builder do
242
+ provider :twitter, ENV['TWITTER_KEY'], ENV['TWITTER_SECRET']
243
+ end
186
244
  CODE
187
- )
188
-
189
- assert_file("app.rb", <<CODE
245
+ )
190
246
 
247
+ assert_file('app.rb', <<~CODE
248
+ get '/login' do
249
+ '<a href="/auth/twitter">Login</a>'
250
+ end
191
251
 
192
- get "/login" do
193
- '<a href="/auth/twitter">Login</a>'
194
- end
252
+ get '/auth/:provider/callback' do
253
+ # TODO: Insert real authentication logic...
254
+ json request.env['omniauth.auth']
255
+ end
195
256
 
196
- get "/auth/:provider/callback" do
197
- # TODO: Insert real authentication logic...
198
- MultiJson.encode(request.env['omniauth.auth'])
199
- end
257
+ get '/auth/failure' do
258
+ # TODO: Insert real error handling logic...
259
+ halt 401, params[:message]
260
+ end
261
+ CODE
262
+ )
200
263
 
201
- get "/auth/failure" do
202
- # TODO: Insert real error handling logic...
203
- halt 401, params[:message]
204
- end
205
- CODE
206
- )
264
+ assert_match(/no offenses detected/, execute('rubocop'))
207
265
  end
266
+ end
267
+ # rubocop:enable Metrics/MethodLength
208
268
 
209
- assert_file("test/unit/app_test.rb", <<-CODE
269
+ # rubocop:disable Metrics/MethodLength
270
+ def test_omniauth_add_on_tests
271
+ run_hoboken(:generate) do
272
+ bin_path = File.expand_path('../../bin/hoboken', __dir__)
273
+ execute("(echo 'twitter' && echo '0.0.1') | #{bin_path} add:omniauth")
274
+ assert_file('test/unit/app_test.rb', <<-CODE
210
275
  setup do
211
276
  OmniAuth.config.test_mode = true
212
277
  end
213
278
 
214
- test "GET /login" do
215
- get "/login"
279
+ test 'GET /login' do
280
+ get '/login'
216
281
  assert_equal('<a href="/auth/twitter">Login</a>', last_response.body)
217
282
  end
218
283
 
219
- test "GET /auth/twitter/callback" do
284
+ test 'GET /auth/twitter/callback' do
220
285
  auth_hash = {
221
- "provider" => "twitter",
222
- "uid" => "123545",
223
- "info" => {
224
- "name" => "John Doe"
286
+ provider: 'twitter',
287
+ uid: '123545',
288
+ info: {
289
+ name: 'John Doe'
225
290
  }
226
291
  }
227
292
 
228
293
  OmniAuth.config.mock_auth[:twitter] = auth_hash
229
- get "/auth/fitbit/callback"
294
+ get '/auth/twitter/callback'
230
295
  assert_equal(MultiJson.encode(auth_hash), last_response.body)
231
296
  end
232
297
 
233
- test "GET /auth/failure" do
298
+ test 'GET /auth/failure' do
234
299
  OmniAuth.config.mock_auth[:twitter] = :invalid_credentials
235
- get "/auth/failure"
300
+ get '/auth/failure'
236
301
  assert_response :not_authorized
237
302
  end
238
303
 
239
- CODE
240
- )
304
+ CODE
305
+ )
306
+ end
307
+ end
308
+ # rubocop:enable Metrics/MethodLength
309
+
310
+ def test_omniauth_add_on_tests_pass
311
+ run_hoboken(:generate) do
312
+ bin_path = File.expand_path('../../bin/hoboken', __dir__)
313
+ execute("(echo 'twitter' && echo '0.0.1') | #{bin_path} add:omniauth")
314
+ execute('bundle install')
315
+ result = execute('rake test:all')
316
+ assert_match(/4 tests, 6 assertions, 0 failures, 0 errors/, result)
317
+ end
318
+ end
319
+
320
+ # rubocop:disable Metrics/MethodLength
321
+ def test_omniauth_add_on_specs
322
+ run_hoboken(:generate, test_framework: 'rspec') do
323
+ bin_path = File.expand_path('../../bin/hoboken', __dir__)
324
+ execute("(echo 'twitter' && echo '0.0.1') | #{bin_path} add:omniauth")
325
+ assert_file(
326
+ 'spec/app_spec.rb',
327
+ <<~CODE
328
+ # rubocop:disable RSpec/DescribeClass
329
+ RSpec.describe 'omniauth', rack: true do
330
+ before(:each) { OmniAuth.config.test_mode = true }
331
+
332
+ describe 'GET /login' do
333
+ before(:each) { get '/login' }
334
+
335
+ it { expect(last_response).to have_http_status(:ok) }
336
+ it { expect(last_response).to have_content_type(:html) }
337
+
338
+ it 'renders a template with a login link' do
339
+ twitter_link = '<a href="/auth/twitter">Login</a>'
340
+ expect(last_response.body).to include(twitter_link)
341
+ end
342
+ end
343
+
344
+ describe 'GET /auth/twitter/callback' do
345
+ let(:auth_hash) do
346
+ {
347
+ provider: 'twitter',
348
+ uid: '123545',
349
+ info: {
350
+ name: 'John Doe'
351
+ }
352
+ }
353
+ end
354
+
355
+ before(:each) do
356
+ OmniAuth.config.mock_auth[:twitter] = auth_hash
357
+ get '/auth/twitter/callback'
358
+ end
359
+
360
+ it { expect(last_response).to have_http_status(:ok) }
361
+ it { expect(last_response).to have_content_type(:json) }
362
+
363
+ it 'renders the auth hash result' do
364
+ expect(last_response.body).to eq(JSON.generate(auth_hash))
365
+ end
366
+ end
367
+
368
+ describe 'GET /auth/failure' do
369
+ before(:each) do
370
+ OmniAuth.config.mock_auth[:twitter] = :invalid_credentials
371
+ get '/auth/failure'
372
+ end
373
+
374
+ it { expect(last_response).to have_http_status(:not_authorized) }
375
+ end
376
+ end
377
+ # rubocop:enable RSpec/DescribeClass
378
+ CODE
379
+ )
380
+ end
381
+ end
382
+ # rubocop:enable Metrics/MethodLength
383
+
384
+ def test_omniauth_add_on_specs_pass
385
+ run_hoboken(:generate, test_framework: 'rspec') do
386
+ bin_path = File.expand_path('../../bin/hoboken', __dir__)
387
+ execute("(echo 'twitter' && echo '0.0.1') | #{bin_path} add:omniauth")
388
+ execute('bundle install')
389
+ result = execute('rake spec')
390
+ assert_match(/10 examples, 0 failures/, result)
391
+ end
392
+ end
393
+
394
+ def test_rubocop_add_on
395
+ run_hoboken(:generate) do
396
+ bin_path = File.expand_path('../../bin/hoboken', __dir__)
397
+ execute("#{bin_path} add:rubocop")
398
+ assert_file('Gemfile', /rubocop/, /rubocop-rake/)
399
+ assert_file_does_not_have_content 'Gemfile', /rubocop-rspec/
400
+ assert_file('tasks/rubocop.rake', %r{rubocop/rake_task}, /RuboCop::RakeTask\.new/)
401
+ assert_file('Rakefile', /task ci: \['test:all', 'rubocop'\]/)
402
+
403
+ assert_file('.rubocop.yml', '- rubocop-rake')
404
+ assert_file('.rubocop.yml', "TargetRubyVersion: #{RUBY_VERSION}")
405
+
406
+ assert_match(/no offenses detected/, execute('rubocop'))
407
+ end
408
+ end
409
+
410
+ def test_rubocop_with_rspec_add_on
411
+ run_hoboken(:generate, test_framework: 'rspec') do
412
+ bin_path = File.expand_path('../../bin/hoboken', __dir__)
413
+ execute("#{bin_path} add:rubocop")
414
+ assert_file('Gemfile', /rubocop/, /rubocop-rspec/)
415
+ assert_file('tasks/rubocop.rake', %r{rubocop/rake_task}, /RuboCop::RakeTask\.new/)
416
+ assert_file('Rakefile', /task ci: .*spec rubocop/)
417
+
418
+ assert_file('.rubocop.yml', '- rubocop-rspec')
419
+
420
+ assert_match(/no offenses detected/, execute('rubocop'))
421
+ end
422
+ end
423
+
424
+ def test_github_action_add_on
425
+ run_hoboken(:generate) do
426
+ bin_path = File.expand_path('../../bin/hoboken', __dir__)
427
+ execute("#{bin_path} add:github_action")
428
+ assert_file('.github/workflows/ruby.yml')
429
+ assert_match(/no offenses detected/, execute('rubocop'))
430
+ end
431
+ end
432
+
433
+ # rubocop:disable Metrics/MethodLength
434
+ # rubocop:disable Metrics/AbcSize
435
+ def test_twitter_bootstrap_add_on_classic
436
+ run_hoboken(:generate) do
437
+ bin_path = File.expand_path('../../bin/hoboken', __dir__)
438
+ execute("#{bin_path} add:sprockets")
439
+ result = execute("#{bin_path} add:twbs")
440
+ assert_match(/Gemfile updated/, result)
441
+
442
+ assert_file('Gemfile', /bootstrap/)
443
+ assert_file('app.rb', /require 'bootstrap'/)
444
+ assert_file('assets/styles.scss', /@import "bootstrap"/)
445
+ assert_file('assets/app.js', /require popper/, /require bootstrap-sprockets/)
446
+ assert_file('tasks/sprockets.rake', /require 'bootstrap'/)
447
+ assert_file_does_not_have_content('views/layout.erb', /normalize/)
448
+
449
+ assert_match(
450
+ /successfully compiled css assets/,
451
+ execute('rake assets:precompile_css')
452
+ )
453
+
454
+ assert_match(
455
+ /successfully compiled javascript assets/,
456
+ execute('rake assets:precompile_js')
457
+ )
458
+
459
+ assert_match(/no offenses detected/, execute('rubocop'))
460
+ end
461
+ end
462
+ # rubocop:enable Metrics/MethodLength
463
+ # rubocop:enable Metrics/AbcSize
464
+
465
+ # rubocop:disable Metrics/MethodLength
466
+ # rubocop:disable Metrics/AbcSize
467
+ def test_twitter_bootstrap_add_on_modular
468
+ run_hoboken(:generate, type: :modular) do
469
+ bin_path = File.expand_path('../../bin/hoboken', __dir__)
470
+ execute("#{bin_path} add:sprockets")
471
+ result = execute("#{bin_path} add:twbs")
472
+ assert_match(/Gemfile updated/, result)
473
+
474
+ assert_file('Gemfile', /bootstrap/)
475
+ assert_file('app.rb', /require 'bootstrap'/)
476
+ assert_file('assets/styles.scss', /@import "bootstrap"/)
477
+ assert_file('assets/app.js', /require popper/, /require bootstrap-sprockets/)
478
+ assert_file('tasks/sprockets.rake', /require 'bootstrap'/)
479
+ assert_file_does_not_have_content('views/layout.erb', /normalize/)
480
+
481
+ assert_match(
482
+ /successfully compiled css assets/,
483
+ execute('rake assets:precompile_css')
484
+ )
485
+
486
+ assert_match(
487
+ /successfully compiled javascript assets/,
488
+ execute('rake assets:precompile_js')
489
+ )
490
+
491
+ assert_match(/no offenses detected/, execute('rubocop'))
492
+ end
493
+ end
494
+ # rubocop:enable Metrics/MethodLength
495
+ # rubocop:enable Metrics/AbcSize
496
+
497
+ def test_twitter_bootstrap_add_on_without_sprockets
498
+ run_hoboken(:generate) do
499
+ bin_path = File.expand_path('../../bin/hoboken', __dir__)
500
+ result = execute("#{bin_path} add:twbs")
501
+ assert_match(/Sprockets is required/, result)
502
+ end
241
503
  end
242
504
  end
505
+ # rubocop:enable Metrics/ClassLength