Skip to content

Commit b0c4a8d

Browse files
committed
Merge pull request #416 from grosser/grosser/indet
make code nicer to read by using stripper heredoc
2 parents 36353af + e3388c6 commit b0c4a8d

File tree

1 file changed

+48
-45
lines changed

1 file changed

+48
-45
lines changed

lib/spring/test/acceptance_test.rb

Lines changed: 48 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
require "timeout"
33
require "spring/sid"
44
require "spring/client"
5+
require "active_support/core_ext/string/strip"
56

67
module Spring
78
module Test
@@ -109,13 +110,13 @@ def assert_speedup(ratio = DEFAULT_SPEEDUP)
109110
test "app gets reloaded when preloaded files change" do
110111
assert_success app.spring_test_command
111112

112-
File.write(app.application_config, app.application_config.read + <<-CODE)
113+
File.write(app.application_config, app.application_config.read + <<-RUBY.strip_heredoc)
113114
class Foo
114115
def self.omg
115116
raise "omg"
116117
end
117118
end
118-
CODE
119+
RUBY
119120
File.write(app.test, app.test.read.sub("get :index", "Foo.omg"))
120121

121122
app.await_reload
@@ -158,7 +159,7 @@ def self.omg
158159
# Start spring before setting up the command, to test that it gracefully upgrades itself
159160
assert_success "bin/rails runner ''"
160161

161-
File.write(app.spring_config, <<-CODE)
162+
File.write(app.spring_config, <<-RUBY.strip_heredoc)
162163
class CustomCommand
163164
def call
164165
puts "omg"
@@ -170,7 +171,7 @@ def exec_name
170171
end
171172
172173
Spring.register_command "custom", CustomCommand.new
173-
CODE
174+
RUBY
174175

175176
assert_success "bin/spring custom", stdout: "omg"
176177

@@ -202,46 +203,48 @@ def exec_name
202203
end
203204

204205
test "binstub upgrade" do
205-
File.write(app.path("bin/rake"), <<CODE)
206-
#!/usr/bin/env ruby
207-
208-
if !Process.respond_to?(:fork) || Gem::Specification.find_all_by_name("spring").empty?
209-
exec "bundle", "exec", "rake", *ARGV
210-
else
211-
ARGV.unshift "rake"
212-
load Gem.bin_path("spring", "spring")
213-
end
214-
CODE
215-
216-
File.write(app.path("bin/rails"), <<CODE)
217-
#!/usr/bin/env ruby
218-
219-
if !Process.respond_to?(:fork) || Gem::Specification.find_all_by_name("spring").empty?
220-
APP_PATH = File.expand_path('../../config/application', __FILE__)
221-
require_relative '../config/boot'
222-
require 'rails/commands'
223-
else
224-
ARGV.unshift "rails"
225-
load Gem.bin_path("spring", "spring")
226-
end
227-
CODE
206+
File.write(app.path("bin/rake"), <<-RUBY.strip_heredoc)
207+
#!/usr/bin/env ruby
208+
209+
if !Process.respond_to?(:fork) || Gem::Specification.find_all_by_name("spring").empty?
210+
exec "bundle", "exec", "rake", *ARGV
211+
else
212+
ARGV.unshift "rake"
213+
load Gem.bin_path("spring", "spring")
214+
end
215+
RUBY
216+
217+
File.write(app.path("bin/rails"), <<-RUBY.strip_heredoc)
218+
#!/usr/bin/env ruby
219+
220+
if !Process.respond_to?(:fork) || Gem::Specification.find_all_by_name("spring").empty?
221+
APP_PATH = File.expand_path('../../config/application', __FILE__)
222+
require_relative '../config/boot'
223+
require 'rails/commands'
224+
else
225+
ARGV.unshift "rails"
226+
load Gem.bin_path("spring", "spring")
227+
end
228+
RUBY
228229

229230
assert_success "bin/spring binstub --all", stdout: "upgraded"
230231

231-
assert_equal app.path("bin/rake").read, <<CODE
232-
#!/usr/bin/env ruby
233-
#{Spring::Client::Binstub::LOADER.strip}
234-
require 'bundler/setup'
235-
load Gem.bin_path('rake', 'rake')
236-
CODE
232+
expected = <<-RUBY.gsub(/^ /, "")
233+
#!/usr/bin/env ruby
234+
#{Spring::Client::Binstub::LOADER.strip}
235+
require 'bundler/setup'
236+
load Gem.bin_path('rake', 'rake')
237+
RUBY
238+
assert_equal expected, app.path("bin/rake").read
237239

238-
assert_equal app.path("bin/rails").read, <<CODE
239-
#!/usr/bin/env ruby
240-
#{Spring::Client::Binstub::LOADER.strip}
241-
APP_PATH = File.expand_path('../../config/application', __FILE__)
242-
require_relative '../config/boot'
243-
require 'rails/commands'
244-
CODE
240+
expected = <<-RUBY.gsub(/^ /, "")
241+
#!/usr/bin/env ruby
242+
#{Spring::Client::Binstub::LOADER.strip}
243+
APP_PATH = File.expand_path('../../config/application', __FILE__)
244+
require_relative '../config/boot'
245+
require 'rails/commands'
246+
RUBY
247+
assert_equal expected, app.path("bin/rails").read
245248
end
246249

247250
test "after fork callback" do
@@ -280,17 +283,17 @@ def exec_name
280283
end
281284

282285
test "setting env vars with rake" do
283-
File.write(app.path("lib/tasks/env.rake"), <<-'CODE')
286+
File.write(app.path("lib/tasks/env.rake"), <<-RUBY.strip_heredoc)
284287
task :print_rails_env => :environment do
285288
puts Rails.env
286289
end
287290
288291
task :print_env do
289-
ENV.each { |k, v| puts "#{k}=#{v}" }
292+
ENV.each { |k, v| puts "\#{k}=\#{v}" }
290293
end
291294
292295
task(:default).clear.enhance [:print_rails_env]
293-
CODE
296+
RUBY
294297

295298
assert_success "bin/rake RAILS_ENV=test print_rails_env", stdout: "test"
296299
assert_success "bin/rake FOO=bar print_env", stdout: "FOO=bar"
@@ -307,15 +310,15 @@ def exec_name
307310
end
308311

309312
test "changing the Gemfile works when spring calls into itself" do
310-
File.write(app.path("script.rb"), <<-CODE)
313+
File.write(app.path("script.rb"), <<-RUBY.strip_heredoc)
311314
gemfile = Rails.root.join("Gemfile")
312315
File.write(gemfile, "\#{gemfile.read}gem 'devise'\\n")
313316
Bundler.with_clean_env do
314317
system(#{app.env.inspect}, "bundle install")
315318
end
316319
output = `\#{Rails.root.join('bin/rails')} runner 'require "devise"; puts "done";'`
317320
exit output == "done\n"
318-
CODE
321+
RUBY
319322

320323
assert_success [%(bin/rails runner 'load Rails.root.join("script.rb")'), timeout: 60]
321324
end

0 commit comments

Comments
 (0)