hoboken 0.0.1.beta2 → 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (115) hide show
  1. checksums.yaml +5 -5
  2. data/.github/ISSUE_TEMPLATE/bug_report.md +33 -0
  3. data/.github/ISSUE_TEMPLATE/code_change.md +11 -0
  4. data/.github/PULL_REQUEST_TEMPLATE.md +25 -0
  5. data/.github/dependabot.yml +7 -0
  6. data/.github/workflows/ruby.yml +28 -0
  7. data/.gitignore +3 -0
  8. data/.rubocop.yml +41 -0
  9. data/.ruby-version +1 -0
  10. data/.tool-versions +1 -0
  11. data/CHANGELOG.md +131 -0
  12. data/CODE_OF_CONDUCT.md +8 -0
  13. data/CONTRIBUTING.md +16 -0
  14. data/Gemfile +2 -0
  15. data/IDEAS.md +57 -0
  16. data/LICENSE.txt +1 -1
  17. data/README.md +28 -17
  18. data/Rakefile +14 -8
  19. data/bin/hoboken +2 -1
  20. data/hoboken.gemspec +63 -16
  21. data/lib/hoboken/actions.rb +11 -6
  22. data/lib/hoboken/add_ons/active_record.rb +142 -0
  23. data/lib/hoboken/add_ons/airbrake.rb +64 -0
  24. data/lib/hoboken/add_ons/github_action.rb +14 -0
  25. data/lib/hoboken/add_ons/heroku.rb +29 -0
  26. data/lib/hoboken/add_ons/internationalization.rb +28 -0
  27. data/lib/hoboken/add_ons/metrics.rb +60 -0
  28. data/lib/hoboken/add_ons/omniauth.rb +174 -0
  29. data/lib/hoboken/add_ons/rubocop.rb +46 -0
  30. data/lib/hoboken/add_ons/sequel.rb +135 -0
  31. data/lib/hoboken/add_ons/sidekiq.rb +137 -0
  32. data/lib/hoboken/add_ons/travis.rb +15 -0
  33. data/lib/hoboken/add_ons/turnip.rb +109 -0
  34. data/lib/hoboken/add_ons/twbs.rb +50 -0
  35. data/lib/hoboken/add_ons/vcr.rb +54 -0
  36. data/lib/hoboken/generate.rb +146 -46
  37. data/lib/hoboken/templates/Gemfile.erb.tt +43 -8
  38. data/lib/hoboken/templates/README.md.tt +117 -35
  39. data/lib/hoboken/templates/Rakefile.tt +20 -16
  40. data/lib/hoboken/templates/active_record.rake +11 -0
  41. data/lib/hoboken/templates/airbrake.rb.tt +13 -0
  42. data/lib/hoboken/templates/classic.rb.tt +25 -11
  43. data/lib/hoboken/templates/classic_environment.rb.tt +51 -0
  44. data/lib/hoboken/templates/config.ru.tt +4 -2
  45. data/lib/hoboken/templates/console +19 -0
  46. data/lib/hoboken/templates/db.rb.tt +24 -0
  47. data/lib/hoboken/templates/example_worker.rb.tt +14 -0
  48. data/lib/hoboken/templates/github_action.tt +28 -0
  49. data/lib/hoboken/templates/gitignore +8 -0
  50. data/lib/hoboken/templates/metrics.rake.tt +12 -9
  51. data/lib/hoboken/templates/modular.rb.tt +28 -15
  52. data/lib/hoboken/templates/modular_environment.rb.tt +62 -0
  53. data/lib/hoboken/templates/puma.rb.tt +21 -0
  54. data/lib/hoboken/templates/rspec.rake.tt +9 -0
  55. data/lib/hoboken/templates/rubocop.yml.tt +51 -0
  56. data/lib/hoboken/templates/seeds.rb +12 -0
  57. data/lib/hoboken/templates/sequel.rake +21 -0
  58. data/lib/hoboken/templates/server +15 -0
  59. data/lib/hoboken/templates/setup +28 -0
  60. data/lib/hoboken/templates/sidekiq.rb.tt +21 -0
  61. data/lib/hoboken/templates/spec/app_spec.rb.tt +13 -0
  62. data/lib/hoboken/templates/spec/example_worker_spec.rb.tt +16 -0
  63. data/lib/hoboken/templates/spec/rack_matchers.rb.tt +58 -0
  64. data/lib/hoboken/templates/spec/spec_helper.rb.tt +37 -0
  65. data/lib/hoboken/templates/spec/turnip_helper.rb.tt +10 -0
  66. data/lib/hoboken/templates/styles.css.tt +1 -1
  67. data/lib/hoboken/templates/support/rack_helpers.rb.tt +55 -0
  68. data/lib/hoboken/templates/support/rack_test_assertions.rb.tt +113 -0
  69. data/lib/hoboken/templates/test/test_helper.rb.tt +47 -0
  70. data/lib/hoboken/templates/test/unit/app_test.rb.tt +11 -3
  71. data/lib/hoboken/templates/test/unit/example_worker_test.rb.tt +20 -0
  72. data/lib/hoboken/templates/test_unit.rake.tt +18 -0
  73. data/lib/hoboken/templates/vcr_setup.rb.tt +15 -0
  74. data/lib/hoboken/templates/views/index.erb.tt +11 -4
  75. data/lib/hoboken/templates/views/layout.erb.tt +7 -4
  76. data/lib/hoboken/version.rb +3 -1
  77. data/lib/hoboken.rb +147 -325
  78. data/test/fixtures/Gemfile +3 -3
  79. data/test/fixtures/Gemfile.pristine +3 -2
  80. data/test/integration/active_record_test.rb +66 -0
  81. data/test/integration/airbrake_test.rb +31 -0
  82. data/test/integration/generate_classic_test.rb +75 -0
  83. data/test/integration/generate_modular_test.rb +83 -0
  84. data/test/integration/github_action_test.rb +13 -0
  85. data/test/integration/heroku_test.rb +14 -0
  86. data/test/integration/internationalization_test.rb +26 -0
  87. data/test/integration/metrics_test.rb +54 -0
  88. data/test/integration/omniauth_test.rb +143 -0
  89. data/test/integration/rubocop_test.rb +39 -0
  90. data/test/integration/sequel_test.rb +64 -0
  91. data/test/integration/sidekiq_test.rb +105 -0
  92. data/test/integration/travis_test.rb +13 -0
  93. data/test/integration/turnip_test.rb +51 -0
  94. data/test/integration/twitter_bootstrap_test.rb +39 -0
  95. data/test/integration/vcr_test.rb +54 -0
  96. data/test/test_helper.rb +109 -0
  97. data/test/unit/hoboken_actions_test.rb +82 -53
  98. data/www/Gemfile +4 -0
  99. data/www/README.md +2 -0
  100. data/www/config.rb +11 -0
  101. data/www/source/documentation.html.erb +274 -0
  102. data/www/source/images/hoboken-running.png +0 -0
  103. data/www/source/images/hoboken.png +0 -0
  104. data/www/source/images/sinatra.png +0 -0
  105. data/www/source/index.html.erb +44 -0
  106. data/www/source/javascripts/all.js +1 -0
  107. data/www/source/layouts/layout.erb +38 -0
  108. data/www/source/stylesheets/all.css.scss +116 -0
  109. data/www/source/stylesheets/normalize.css +375 -0
  110. metadata +655 -29
  111. data/lib/hoboken/templates/sprockets.rake +0 -33
  112. data/lib/hoboken/templates/sprockets_chain.rb +0 -26
  113. data/lib/hoboken/templates/sprockets_helper.rb +0 -13
  114. data/lib/hoboken/templates/test/support/rack_test_assertions.rb.tt +0 -79
  115. data/lib/hoboken/templates/test/unit/test_helper.rb.tt +0 -36
@@ -0,0 +1,75 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../test_helper'
4
+
5
+ class GenerateClassicTest < IntegrationTestCase
6
+ # rubocop:disable Metrics/MethodLength
7
+ # rubocop:disable Metrics/AbcSize
8
+ def test_generate_classic
9
+ run_hoboken(:generate) do
10
+ assert_file '.env'
11
+ assert_file 'Gemfile'
12
+ assert_file('Procfile')
13
+ assert_file 'README.md'
14
+ assert_file 'Rakefile'
15
+ assert_file 'app.rb', /require 'sinatra'/
16
+ assert_file 'app.rb', %r{require 'sinatra/flash'}
17
+ assert_file 'app.rb', %r{require 'sinatra/asset_pipeline'}
18
+ assert_file 'app.rb', /require 'erubi'/
19
+ assert_file 'app.rb', /erb :index/
20
+ assert_file_does_not_have_content 'app.rb', /json message:/
21
+ assert_file 'bin/console'
22
+ assert_file 'bin/server'
23
+ assert_file 'bin/setup'
24
+ assert_file 'config.ru', /run Sinatra::Application/
25
+ assert_file 'config/environment.rb', /set :erb, { escape_html: true }/
26
+ assert_file 'config/environment.rb', /require 'better_errors'/
27
+ assert_directory 'assets'
28
+ assert_directory 'public'
29
+ assert_directory 'test'
30
+ assert_file 'views/index.erb'
31
+ assert_file 'views/layout.erb', /styled_flash/
32
+ end
33
+ end
34
+ # rubocop:enable Metrics/MethodLength
35
+ # rubocop:enable Metrics/AbcSize
36
+
37
+ def test_generate_classic_tiny
38
+ run_hoboken(:generate, tiny: true) do
39
+ assert_file 'app.rb', /__END__/, /@@layout/, /@@index/
40
+ end
41
+ end
42
+
43
+ def test_generate_classic_api_only
44
+ run_hoboken(:generate, api_only: true) do
45
+ refute_directory('public')
46
+ refute_directory('views')
47
+ assert_file 'app.rb', %r{require 'sinatra/json'}
48
+ assert_file 'app.rb', /json message:/
49
+ assert_file_does_not_have_content 'app.rb', %r{require 'sinatra/flash'}
50
+ assert_file_does_not_have_content 'app.rb', /erb :index/
51
+ assert_file_does_not_have_content(
52
+ 'config/environment.rb',
53
+ /set :erb, { escape_html: true }/
54
+ )
55
+ end
56
+ end
57
+
58
+ def test_generate_api_only_with_tiny
59
+ run_hoboken(:generate, api_only: true, tiny: true) do
60
+ assert_file_does_not_have_content 'app.rb', /__END__/, /@@layout/, /@@index/
61
+ end
62
+ end
63
+
64
+ def test_generate_with_ruby_version
65
+ run_hoboken(:generate, run_tests: false, rubocop: false, ruby_version: '2.1.0') do
66
+ assert_file 'Gemfile', /ruby '2\.1\.0'/
67
+ end
68
+ end
69
+
70
+ def test_generate_with_git
71
+ run_hoboken(:generate, run_tests: false, rubocop: false, git: true) do
72
+ assert_directory '.git'
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,83 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../test_helper'
4
+
5
+ class GenerateModularTest < IntegrationTestCase
6
+ # rubocop:disable Metrics/MethodLength
7
+ # rubocop:disable Metrics/AbcSize
8
+ def test_generate_modular
9
+ run_hoboken(:generate, type: :modular) do
10
+ assert_file '.env'
11
+ assert_file 'Gemfile'
12
+ assert_file('Procfile')
13
+ assert_file 'README.md'
14
+ assert_file 'Rakefile'
15
+ assert_file('app.rb', %r{require 'sinatra/base'})
16
+ assert_file 'app.rb', %r{require 'sinatra/flash'}
17
+ assert_file('app.rb', /require 'erubi'/)
18
+ assert_file('app.rb', /module Sample/)
19
+ assert_file('app.rb', /class App < Sinatra::Base/)
20
+ assert_file 'bin/console'
21
+ assert_file 'bin/server'
22
+ assert_file 'bin/setup'
23
+ assert_file 'config.ru', /run Sample::App/
24
+ assert_file 'config/environment.rb', /set :erb, { escape_html: true }/
25
+ assert_file 'config/environment.rb', /register Sinatra::Flash/
26
+ assert_file 'config/environment.rb', /require 'better_errors'/
27
+ assert_directory 'public'
28
+ assert_file 'test/support/rack_helpers.rb', /Sample::App/
29
+ assert_file 'views/index.erb'
30
+ assert_file 'views/layout.erb', /styled_flash/
31
+ end
32
+ end
33
+ # rubocop:enable Metrics/MethodLength
34
+ # rubocop:enable Metrics/AbcSize
35
+
36
+ def test_generate_modular_tiny
37
+ # FIXME: For some reason modular apps can't find the inline templates even
38
+ # if `enable :inline_templates is set. This is a bit of an edge case since
39
+ # most apps with inline templates are of the classic variety.
40
+ run_hoboken(:generate, run_tests: false, tiny: true, type: :modular) do
41
+ assert_file 'app.rb', /__END__/, /@@layout/, /@@index/
42
+ end
43
+ end
44
+
45
+ # rubocop:disable Metrics/MethodLength
46
+ def test_generate_modular_api_only
47
+ run_hoboken(:generate, type: :modular, api_only: true) do
48
+ refute_directory('public')
49
+ refute_directory('views')
50
+ assert_file 'app.rb', %r{require 'sinatra/json'}
51
+ assert_file 'app.rb', /json message:/
52
+ assert_file_does_not_have_content 'app.rb', /erb :index/
53
+
54
+ assert_file_does_not_have_content(
55
+ 'config/environment.rb',
56
+ %r{require 'sinatra/flash'}
57
+ )
58
+
59
+ assert_file_does_not_have_content(
60
+ 'config/environment.rb',
61
+ /register Sinatra::Flash/
62
+ )
63
+
64
+ assert_file_does_not_have_content(
65
+ 'config/environment.rb',
66
+ /set :erb, { escape_html: true }/
67
+ )
68
+ end
69
+ end
70
+ # rubocop:enable Metrics/MethodLength
71
+
72
+ def test_generate_with_ruby_version
73
+ run_hoboken(:generate, run_tests: false, rubocop: false, ruby_version: '2.1.0') do
74
+ assert_file 'Gemfile', /ruby '2\.1\.0'/
75
+ end
76
+ end
77
+
78
+ def test_generate_with_git
79
+ run_hoboken(:generate, run_tests: false, rubocop: false, git: true) do
80
+ assert_directory '.git'
81
+ end
82
+ end
83
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../test_helper'
4
+
5
+ class GitHubActionTest < IntegrationTestCase
6
+ def test_github_action_add_on
7
+ run_hoboken(:generate, run_tests: false, rubocop: false) do
8
+ bin_path = File.expand_path('../../bin/hoboken', __dir__)
9
+ execute("#{bin_path} add:github_action")
10
+ assert_file('.github/workflows/ruby.yml')
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../test_helper'
4
+
5
+ class HerokuTest < IntegrationTestCase
6
+ def test_heroku_add_on
7
+ run_hoboken(:generate, run_tests: false) do
8
+ bin_path = File.expand_path('../../bin/hoboken', __dir__)
9
+ execute("#{bin_path} add:heroku")
10
+ assert_file('.slugignore')
11
+ assert_file('config.ru', /\$stdout.sync = true/)
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../test_helper'
4
+
5
+ class InternationalizationTest < IntegrationTestCase
6
+ def test_internationalization_add_on_classic
7
+ run_hoboken(:generate) do
8
+ bin_path = File.expand_path('../../bin/hoboken', __dir__)
9
+ execute("#{bin_path} add:i18n")
10
+ assert_file('Gemfile', 'sinatra-r18n')
11
+ assert_file('app.rb', "require 'sinatra/r18n'")
12
+ assert_file('i18n/en.yml')
13
+ end
14
+ end
15
+
16
+ def test_internationalization_add_on_modular
17
+ run_hoboken(:generate, type: :modular) do
18
+ bin_path = File.expand_path('../../bin/hoboken', __dir__)
19
+ execute("#{bin_path} add:i18n")
20
+ assert_file('Gemfile', 'sinatra-r18n')
21
+ assert_file('app.rb', "require 'sinatra/r18n'")
22
+ assert_file('config/environment.rb', 'register Sinatra::R18n')
23
+ assert_file('i18n/en.yml')
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,54 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../test_helper'
4
+
5
+ class MetricsTest < IntegrationTestCase
6
+ # rubocop:disable Metrics/MethodLength
7
+ def test_metrics_add_on_with_test_unit
8
+ run_hoboken(:generate) do
9
+ bin_path = File.expand_path('../../bin/hoboken', __dir__)
10
+ execute("#{bin_path} add:metrics")
11
+
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 '/db/migrate/'
21
+ add_filter '/test/'
22
+ coverage_dir 'tmp/coverage'
23
+ end
24
+
25
+ CODE
26
+ )
27
+ end
28
+ end
29
+ # rubocop:enable Metrics/MethodLength
30
+
31
+ # rubocop:disable Metrics/MethodLength
32
+ def test_metrics_add_on_with_rspec
33
+ run_hoboken(:generate, test_framework: 'rspec') do
34
+ bin_path = File.expand_path('../../bin/hoboken', __dir__)
35
+ execute("#{bin_path} add:metrics")
36
+ assert_file('Gemfile', /flog/, /flay/, /simplecov/)
37
+ assert_file('tasks/metrics.rake')
38
+
39
+ assert_file('spec/spec_helper.rb', <<~CODE
40
+ require 'simplecov'
41
+ SimpleCov.start do
42
+ add_filter '/bin/'
43
+ add_filter '/config/'
44
+ add_filter '/db/migrate/'
45
+ add_filter '/spec/'
46
+ coverage_dir 'tmp/coverage'
47
+ end
48
+
49
+ CODE
50
+ )
51
+ end
52
+ end
53
+ # rubocop:enable Metrics/MethodLength
54
+ end
@@ -0,0 +1,143 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../test_helper'
4
+
5
+ class OmniauthTest < IntegrationTestCase
6
+ # rubocop:disable Metrics/MethodLength
7
+ def test_omniauth_add_on
8
+ run_hoboken(:generate) do
9
+ bin_path = File.expand_path('../../bin/hoboken', __dir__)
10
+ execute("(echo 'twitter' && echo '0.0.1') | #{bin_path} add:omniauth")
11
+ assert_file('Gemfile', 'omniauth-twitter')
12
+ assert_file('app.rb', /require 'omniauth-twitter'/)
13
+ assert_file('app.rb', %r{require 'sinatra/json'})
14
+ assert_file('config/environment.rb', <<CODE
15
+ use OmniAuth::Builder do
16
+ provider :twitter, ENV['TWITTER_KEY'], ENV['TWITTER_SECRET']
17
+ end
18
+ CODE
19
+ )
20
+
21
+ assert_file('app.rb', <<~CODE
22
+ get '/login' do
23
+ '<a href="/auth/twitter">Login</a>'
24
+ end
25
+
26
+ get '/auth/:provider/callback' do
27
+ # TODO: Insert real authentication logic...
28
+ json request.env['omniauth.auth']
29
+ end
30
+
31
+ get '/auth/failure' do
32
+ # TODO: Insert real error handling logic...
33
+ halt 401, params[:message]
34
+ end
35
+ CODE
36
+ )
37
+ end
38
+ end
39
+ # rubocop:enable Metrics/MethodLength
40
+
41
+ # rubocop:disable Metrics/MethodLength
42
+ def test_omniauth_add_on_tests
43
+ run_hoboken(:generate) do
44
+ bin_path = File.expand_path('../../bin/hoboken', __dir__)
45
+ execute("(echo 'twitter' && echo '0.0.1') | #{bin_path} add:omniauth")
46
+ assert_file('test/unit/app_test.rb', <<-CODE
47
+ setup do
48
+ OmniAuth.config.test_mode = true
49
+ end
50
+
51
+ test 'GET /login' do
52
+ get '/login'
53
+ assert_equal('<a href="/auth/twitter">Login</a>', last_response.body)
54
+ end
55
+
56
+ test 'GET /auth/twitter/callback' do
57
+ auth_hash = {
58
+ provider: 'twitter',
59
+ uid: '123545',
60
+ info: {
61
+ name: 'John Doe'
62
+ }
63
+ }
64
+
65
+ OmniAuth.config.mock_auth[:twitter] = auth_hash
66
+ get '/auth/twitter/callback'
67
+ assert_equal(MultiJson.encode(auth_hash), last_response.body)
68
+ end
69
+
70
+ test 'GET /auth/failure' do
71
+ OmniAuth.config.mock_auth[:twitter] = :invalid_credentials
72
+ get '/auth/failure'
73
+ assert_response :not_authorized
74
+ end
75
+
76
+ CODE
77
+ )
78
+ end
79
+ end
80
+ # rubocop:enable Metrics/MethodLength
81
+
82
+ # rubocop:disable Metrics/MethodLength
83
+ def test_omniauth_add_on_specs
84
+ run_hoboken(:generate, test_framework: 'rspec') do
85
+ bin_path = File.expand_path('../../bin/hoboken', __dir__)
86
+ execute("(echo 'twitter' && echo '0.0.1') | #{bin_path} add:omniauth")
87
+ assert_file(
88
+ 'spec/app_spec.rb',
89
+ <<~CODE
90
+ RSpec.describe 'omniauth', rack: true do
91
+ before { OmniAuth.config.test_mode = true }
92
+
93
+ describe 'GET /login' do
94
+ before { get '/login' }
95
+
96
+ it { expect(last_response).to have_http_status(:ok) }
97
+ it { expect(last_response).to have_content_type(:html) }
98
+
99
+ it 'renders a template with a login link' do
100
+ twitter_link = '<a href="/auth/twitter">Login</a>'
101
+ expect(last_response.body).to include(twitter_link)
102
+ end
103
+ end
104
+
105
+ describe 'GET /auth/twitter/callback' do
106
+ let(:auth_hash) do
107
+ {
108
+ provider: 'twitter',
109
+ uid: '123545',
110
+ info: {
111
+ name: 'John Doe'
112
+ }
113
+ }
114
+ end
115
+
116
+ before do
117
+ OmniAuth.config.mock_auth[:twitter] = auth_hash
118
+ get '/auth/twitter/callback'
119
+ end
120
+
121
+ it { expect(last_response).to have_http_status(:ok) }
122
+ it { expect(last_response).to have_content_type(:json) }
123
+
124
+ it 'renders the auth hash result' do
125
+ expect(last_response.body).to eq(JSON.generate(auth_hash))
126
+ end
127
+ end
128
+
129
+ describe 'GET /auth/failure' do
130
+ before do
131
+ OmniAuth.config.mock_auth[:twitter] = :invalid_credentials
132
+ get '/auth/failure'
133
+ end
134
+
135
+ it { expect(last_response).to have_http_status(:not_authorized) }
136
+ end
137
+ end
138
+ CODE
139
+ )
140
+ end
141
+ end
142
+ # rubocop:enable Metrics/MethodLength
143
+ end
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../test_helper'
4
+
5
+ class RubocopTest < IntegrationTestCase
6
+ def test_rubocop_add_on
7
+ run_hoboken(:generate, run_tests: false) do
8
+ bin_path = File.expand_path('../../bin/hoboken', __dir__)
9
+ execute("#{bin_path} add:rubocop")
10
+ assert_file('Gemfile', /rubocop/, /rubocop-rake/, /rubocop-performance/)
11
+ assert_file_does_not_have_content 'Gemfile', /rubocop-rspec/
12
+ assert_file('tasks/rubocop.rake', %r{rubocop/rake_task}, /RuboCop::RakeTask\.new/)
13
+ assert_file('Rakefile', /task ci: \['test:all', 'rubocop'\]/)
14
+ assert_file('.rubocop.yml', '- rubocop-rake')
15
+ assert_file('.rubocop.yml', "TargetRubyVersion: #{RUBY_VERSION}")
16
+ end
17
+ end
18
+
19
+ def test_rubocop_with_rspec_add_on
20
+ run_hoboken(:generate, run_tests: false, test_framework: 'rspec') do
21
+ bin_path = File.expand_path('../../bin/hoboken', __dir__)
22
+ execute("#{bin_path} add:rubocop")
23
+ assert_file('Gemfile', /rubocop/, /rubocop-rspec/)
24
+ assert_file('tasks/rubocop.rake', %r{rubocop/rake_task}, /RuboCop::RakeTask\.new/)
25
+ assert_file('Rakefile', /task ci: .*spec rubocop/)
26
+ assert_file('.rubocop.yml', '- rubocop-rspec')
27
+ end
28
+ end
29
+
30
+ def test_rubocop_with_sequel_add_on
31
+ run_hoboken(:generate, run_tests: false) do
32
+ bin_path = File.expand_path('../../bin/hoboken', __dir__)
33
+ execute("#{bin_path} add:sequel")
34
+ execute("#{bin_path} add:rubocop")
35
+ assert_file('Gemfile', /rubocop/, /rubocop-sequel/)
36
+ assert_file('.rubocop.yml', '- rubocop-sequel')
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,64 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../test_helper'
4
+
5
+ class SequelTest < IntegrationTestCase
6
+ # rubocop:disable Metrics/MethodLength
7
+ def test_sequel_add_on
8
+ run_hoboken(:generate) do
9
+ bin_path = File.expand_path('../../bin/hoboken', __dir__)
10
+ execute("#{bin_path} add:sequel")
11
+ execute('echo "DATABASE_URL=sqlite://db/development.db" > .env')
12
+ assert_file('Gemfile', 'sequel', 'sqlite3')
13
+ assert_file('tasks/sequel.rake')
14
+ assert_file('config/db.rb')
15
+
16
+ assert_file(
17
+ 'test/test_helper.rb',
18
+ %r{ENV\['DATABASE_URL'\] = 'sqlite://db/test\.db'}
19
+ )
20
+
21
+ assert_file('test/test_helper.rb', /require 'sequel'/)
22
+ assert_file('test/test_helper.rb', <<-CODE
23
+ def run(*args, &block)
24
+ result = nil
25
+ DB.transaction(rollback: :always) { result = super }
26
+ result
27
+ end
28
+ CODE
29
+ )
30
+ end
31
+ end
32
+ # rubocop:enable Metrics/MethodLength
33
+
34
+ def test_sequel_add_on_with_rspec
35
+ run_hoboken(:generate, test_framework: 'rspec') do
36
+ bin_path = File.expand_path('../../bin/hoboken', __dir__)
37
+ execute("#{bin_path} add:sequel")
38
+
39
+ assert_file(
40
+ 'spec/spec_helper.rb',
41
+ %r{ENV\['DATABASE_URL'\] = 'sqlite://db/test\.db'}
42
+ )
43
+
44
+ assert_file('spec/spec_helper.rb', <<-CODE
45
+ config.around do |example|
46
+ DB.transaction(rollback: :always) { example.run }
47
+ end
48
+
49
+ CODE
50
+ )
51
+ end
52
+ end
53
+
54
+ def test_sequel_add_on_with_rubocop
55
+ run_hoboken(:generate) do
56
+ bin_path = File.expand_path('../../bin/hoboken', __dir__)
57
+ execute("#{bin_path} add:rubocop")
58
+ execute("#{bin_path} add:sequel")
59
+ execute('echo "DATABASE_URL=sqlite://db/development.db" > .env')
60
+ assert_file('Gemfile', /rubocop-sequel/)
61
+ assert_file('.rubocop.yml', /- rubocop-sequel/)
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,105 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../test_helper'
4
+
5
+ class SidekiqTest < IntegrationTestCase
6
+ # rubocop:disable Metrics/MethodLength
7
+ def test_sidekiq_add_on_with_classic_and_test_unit
8
+ run_hoboken(:generate) do
9
+ bin_path = File.expand_path('../../bin/hoboken', __dir__)
10
+ execute("#{bin_path} add:sidekiq")
11
+ assert_file('Gemfile', 'sidekiq')
12
+ assert_file('config.ru', "require 'sidekiq/web'")
13
+
14
+ assert_file('config.ru', <<~CODE
15
+ if 'production' == ENV.fetch('RACK_ENV', 'production')
16
+ Sidekiq::Web.use Rack::Auth::Basic do |username, password|
17
+ [username, password] == [ENV['SIDEKIQ_USERNAME'], ENV['SIDEKIQ_PASSWORD']]
18
+ end
19
+ end
20
+
21
+ Sidekiq::Web.use Rack::Session::Cookie, secret: ENV['SESSION_SECRET']
22
+ run Rack::URLMap.new('/' => Sinatra::Application, '/sidekiq' => Sidekiq::Web)
23
+ CODE
24
+ )
25
+
26
+ assert_file('config/sidekiq.rb')
27
+ assert_file('workers/example_worker.rb')
28
+ assert_file('test/unit/example_worker_test.rb')
29
+ end
30
+ end
31
+ # rubocop:enable Metrics/MethodLength
32
+
33
+ def test_sidekiq_add_on_with_classic_and_rspec
34
+ run_hoboken(:generate, test_framework: 'rspec') do
35
+ bin_path = File.expand_path('../../bin/hoboken', __dir__)
36
+ execute("#{bin_path} add:sidekiq")
37
+ assert_file('workers/example_worker.rb')
38
+ assert_file('spec/spec_helper.rb', <<CODE
39
+ config.before(:each, sidekiq: true) do
40
+ Sidekiq::Worker.clear_all
41
+ end
42
+ CODE
43
+ )
44
+
45
+ assert_file('spec/example_worker_spec.rb')
46
+ end
47
+ end
48
+
49
+ # rubocop:disable Metrics/MethodLength
50
+ def test_sidekiq_add_on_with_modular_and_test_unit
51
+ run_hoboken(:generate, type: :modular) do
52
+ bin_path = File.expand_path('../../bin/hoboken', __dir__)
53
+ execute("#{bin_path} add:sidekiq")
54
+ assert_file('Gemfile', 'sidekiq')
55
+ assert_file('config.ru', "require 'sidekiq/web'")
56
+
57
+ assert_file('config.ru', <<~CODE
58
+ if 'production' == ENV.fetch('RACK_ENV', 'production')
59
+ Sidekiq::Web.use Rack::Auth::Basic do |username, password|
60
+ [username, password] == [ENV['SIDEKIQ_USERNAME'], ENV['SIDEKIQ_PASSWORD']]
61
+ end
62
+ end
63
+
64
+ Sidekiq::Web.use Rack::Session::Cookie, secret: ENV['SESSION_SECRET']
65
+ run Rack::URLMap.new('/' => Sample::App, '/sidekiq' => Sidekiq::Web)
66
+ CODE
67
+ )
68
+
69
+ assert_file('config/sidekiq.rb')
70
+ assert_file('workers/example_worker.rb')
71
+ assert_file('test/unit/example_worker_test.rb')
72
+ end
73
+ end
74
+ # rubocop:enable Metrics/MethodLength
75
+
76
+ # rubocop:disable Metrics/MethodLength
77
+ def test_sidekiq_add_on_with_modular_and_rspec
78
+ run_hoboken(:generate, type: :modular, test_framework: 'rspec') do
79
+ bin_path = File.expand_path('../../bin/hoboken', __dir__)
80
+ execute("#{bin_path} add:sidekiq")
81
+ assert_file('workers/example_worker.rb')
82
+ assert_file('spec/spec_helper.rb', <<CODE
83
+ config.before(:each, sidekiq: true) do
84
+ Sidekiq::Worker.clear_all
85
+ end
86
+ CODE
87
+ )
88
+
89
+ assert_file('config.ru', <<~CODE
90
+ if 'production' == ENV.fetch('RACK_ENV', 'production')
91
+ Sidekiq::Web.use Rack::Auth::Basic do |username, password|
92
+ [username, password] == [ENV['SIDEKIQ_USERNAME'], ENV['SIDEKIQ_PASSWORD']]
93
+ end
94
+ end
95
+
96
+ Sidekiq::Web.use Rack::Session::Cookie, secret: ENV['SESSION_SECRET']
97
+ run Rack::URLMap.new('/' => Sample::App, '/sidekiq' => Sidekiq::Web)
98
+ CODE
99
+ )
100
+
101
+ assert_file('spec/example_worker_spec.rb')
102
+ end
103
+ end
104
+ # rubocop:enable Metrics/MethodLength
105
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../test_helper'
4
+
5
+ class TravisTest < IntegrationTestCase
6
+ def test_travis_add_on
7
+ run_hoboken(:generate, run_tests: false, rubocop: false) do
8
+ bin_path = File.expand_path('../../bin/hoboken', __dir__)
9
+ execute("#{bin_path} add:travis")
10
+ assert_file('.travis.yml', 'language: ruby')
11
+ end
12
+ end
13
+ end