-
-
Notifications
You must be signed in to change notification settings - Fork 529
/
new_project_spec.rb
317 lines (252 loc) · 9.34 KB
/
new_project_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
require "spec_helper"
RSpec.describe "Suspend a new project with default configuration", type: :feature do
before(:all) do
drop_dummy_database
clear_tmp_directory
run_suspenders
setup_app_dependencies
end
it "uses custom Gemfile" do
gemfile_file = IO.read("#{project_path}/Gemfile")
expect(gemfile_file).to match(
/^ruby "#{Suspenders::RUBY_VERSION}"$/o
)
expect(gemfile_file).to match(
/^gem "autoprefixer-rails"$/
)
expect(gemfile_file).to match(
/^gem "rails", "#{Suspenders::RAILS_VERSION}"$/o
)
end
it "ensures project specs pass" do
Dir.chdir(project_path) do
Bundler.with_unbundled_env do
expect(`rake`).to include("0 failures")
end
end
end
it "includes the bundle:audit task" do
Dir.chdir(project_path) do
Bundler.with_unbundled_env do
expect(`rails -T`).to include("rails bundle:audit")
end
end
end
it "creates .ruby-version from Suspenders .ruby-version" do
ruby_version_file = IO.read("#{project_path}/.ruby-version")
expect(ruby_version_file).to eq "#{RUBY_VERSION}\n"
end
it "copies dotfiles" do
expect(File).to exist("#{project_path}/.sample.env")
end
it "doesn't generate test directory" do
expect(File).not_to exist("#{project_path}/test")
end
it "loads secret_key_base from env" do
secrets_file = IO.read("#{project_path}/config/secrets.yml")
expect(secrets_file)
.to match(/secret_key_base: <%= ENV\["SECRET_KEY_BASE"\] %>/)
end
it "adds bin/setup file" do
expect(File).to exist("#{project_path}/bin/setup")
end
it "makes bin/setup executable" do
expect("bin/setup").to be_executable
end
it "adds support file for action mailer" do
expect(File).to exist("#{project_path}/spec/support/action_mailer.rb")
end
it "configures capybara-chromedriver" do
expect(File).to exist("#{project_path}/spec/support/chromedriver.rb")
end
it "adds support file for i18n" do
expect(File).to exist("#{project_path}/spec/support/i18n.rb")
end
it "creates good default .hound.yml" do
hound_config_file = IO.read("#{project_path}/.hound.yml")
expect(hound_config_file).to include "enabled: true"
end
it "initializes ActiveJob to avoid memory bloat" do
expect(File)
.to exist("#{project_path}/config/initializers/active_job.rb")
end
it "records pageviews through Segment if ENV variable set" do
expect(analytics_partial)
.to include(%(<% if ENV["SEGMENT_KEY"] %>))
expect(analytics_partial)
.to include(%{analytics.load("<%= ENV["SEGMENT_KEY"] %>");})
end
it "raises on unpermitted parameters in all environments" do
result = IO.read("#{project_path}/config/application.rb")
expect(result).to match(
/^ +config.action_controller.action_on_unpermitted_parameters = :raise$/
)
end
it "adds explicit quiet_assets configuration" do
result = IO.read("#{project_path}/config/application.rb")
expect(result).to match(/^ +config.assets.quiet = true$/)
end
it "configures public_file_server.headers in production" do
expect(production_config).to match(
/^ +config.public_file_server.headers = {\n +"Cache-Control" => "public,/
)
end
it "configures production environment to enforce SSL" do
expect(production_config).to match(
/^ +config.force_ssl = true/
)
end
it "raises on missing translations in development and test" do
[development_config, test_config].each do |environment_file|
expect(environment_file).to match(
/^ +config.i18n.raise_on_missing_translations = true$/
)
end
end
it "evaluates en.yml.erb" do
locales_en_file = IO.read("#{project_path}/config/locales/en.yml")
expect(locales_en_file).to match(/application: #{app_name.humanize}/)
end
it "configs simple_form" do
expect(File).to exist("#{project_path}/config/initializers/simple_form.rb")
end
it "configs :test email delivery method for development" do
expect(development_config)
.to match(/^ +config.action_mailer.delivery_method = :file$/)
end
it "sets action mailer default host and asset host" do
config_key = "config.action_mailer.asset_host"
# rubocop:disable Lint/InterpolationCheck
config_value =
%q{"https://#{ENV\.fetch\("ASSET_HOST", ENV\.fetch\("APPLICATION_HOST"\)\)}}
# rubocop:enable Lint/InterpolationCheck
expect(production_config).to match(/#{config_key} = #{config_value}/)
end
it "uses APPLICATION_HOST, not HOST in the production config" do
expect(production_config).to match(/"APPLICATION_HOST"/)
expect(production_config).not_to match(/"HOST"/)
end
it "configures email interceptor" do
email_file = File.join(project_path, "config", "initializers", "email.rb")
email_config = IO.read(email_file)
expect(email_config)
.to include(%{RecipientInterceptor.new(ENV["EMAIL_RECIPIENTS"])})
end
it "configures language in html element" do
layout_path = "/app/views/layouts/application.html.erb"
layout_file = IO.read("#{project_path}#{layout_path}")
expect(layout_file).to match(/<html lang="en">/)
end
it "configures requests specs" do
application_config = IO.read("#{project_path}/config/application.rb")
expect(application_config).to match(
/^ +generate.request_specs true$/
)
end
it "configs active job queue adapter" do
application_config = IO.read("#{project_path}/config/application.rb")
expect(application_config).to match(/^ +config.active_job.queue_adapter = :sidekiq$/) &
match(/^ +config.action_mailer.deliver_later_queue_name = nil$/) &
match(/^ +config.action_mailbox.queues.routing = nil$/) &
match(/^ +config.active_storage.queues.analysis = nil$/) &
match(/^ +config.active_storage.queues.purge = nil$/) &
match(/^ +config.active_storage.queues.mirror = nil$/)
expect(test_config).to match(
/^ +config.active_job.queue_adapter = :inline$/
)
end
it "configs bullet gem in development" do
expect(development_config).to match(/^ +Bullet.enable = true$/)
expect(development_config).to match(/^ +Bullet.bullet_logger = true$/)
expect(development_config).to match(/^ +Bullet.rails_logger = true$/)
# prevent broken result of standard removing whitespaces
expect(development_config).to_not match(/trueconfig/)
end
it "configs missing assets to raise in test" do
expect(test_config).to match(
/^ +config.assets.raise_runtime_errors = true$/
)
end
it "removes comments and extra newlines from config files" do
config_files = [
IO.read("#{project_path}/config/application.rb"),
IO.read("#{project_path}/config/environment.rb"),
development_config,
test_config,
production_config
]
config_files.each do |file|
expect(file).not_to match(/^\s*#.*$/)
expect(file).not_to eq(file.strip)
expect(file).not_to match(%r{^$\n\n})
end
end
it "copies factories.rb" do
expect(File).to exist("#{project_path}/spec/factories.rb")
end
it "creates review apps setup script" do
bin_setup_path = "#{project_path}/bin/setup_review_app"
bin_setup = IO.read(bin_setup_path)
expect(bin_setup).to include("PARENT_APP_NAME=#{app_name.dasherize}-staging")
expect(bin_setup).to include("APP_NAME=#{app_name.dasherize}-staging-pr-$1")
expect(bin_setup).to include("heroku ps:scale worker=1 --app $APP_NAME")
expect(bin_setup).to include("heroku restart --app $APP_NAME")
expect("bin/setup_review_app").to be_executable
end
it "creates deploy script" do
bin_deploy_path = "#{project_path}/bin/deploy"
bin_deploy = IO.read(bin_deploy_path)
expect(bin_deploy).to include("git push")
expect("bin/deploy").to be_executable
end
it "creates heroku application manifest file with application name in it" do
app_json_file = IO.read("#{project_path}/app.json")
expect(app_json_file).to match(/"name":\s*"#{app_name.dasherize}"/)
end
def app_name
TestPaths::APP_NAME
end
it "adds high_voltage" do
gemfile = IO.read("#{project_path}/Gemfile")
expect(gemfile).to match(/high_voltage/)
end
it "adds sassc-rails" do
gemfile = read_project_file("Gemfile")
expect(gemfile).to match(/sassc-rails/)
end
it "adds and configures bourbon" do
gemfile = read_project_file("Gemfile")
expect(gemfile).to match(/bourbon/)
end
it "configures bourbon, and bitters" do
app_css = read_project_file(%w[app assets stylesheets application.scss])
expect(app_css).to match(
/normalize\.css\/normalize.*bourbon.*base/m
)
end
it "doesn't use turbolinks" do
app_js = read_project_file(%w[app javascript packs application.js])
expect(app_js).not_to match(/turbolinks/)
end
it "configures Timecop safe mode" do
spec_helper = read_project_file(%w[spec spec_helper.rb])
expect(spec_helper).to match(/Timecop.safe_mode = true/)
end
def development_config
@_development_config ||=
read_project_file %w[config environments development.rb]
end
def test_config
@_test_config ||= read_project_file %w[config environments test.rb]
end
def production_config
@_production_config ||=
read_project_file %w[config environments production.rb]
end
def analytics_partial
IO.read("#{project_path}/app/views/application/_analytics.html.erb")
end
def read_project_file(path)
IO.read(File.join(project_path, *path))
end
end