44require "timeout"
55require "spring/sid"
66require "spring/client"
7+ require "active_support/core_ext/string/strip"
78
89module Spring
910 module Test
@@ -111,13 +112,13 @@ def assert_speedup(ratio = DEFAULT_SPEEDUP)
111112 test "app gets reloaded when preloaded files change" do
112113 assert_success app . spring_test_command
113114
114- File . write ( app . application_config , app . application_config . read + <<-CODE )
115+ File . write ( app . application_config , app . application_config . read + <<-RUBY . strip_heredoc )
115116 class Foo
116117 def self.omg
117118 raise "omg"
118119 end
119120 end
120- CODE
121+ RUBY
121122 File . write ( app . test , app . test . read . sub ( "get :index" , "Foo.omg" ) )
122123
123124 app . await_reload
@@ -160,7 +161,7 @@ def self.omg
160161 # Start spring before setting up the command, to test that it gracefully upgrades itself
161162 assert_success "bin/rails runner ''"
162163
163- File . write ( app . spring_config , <<-CODE )
164+ File . write ( app . spring_config , <<-RUBY . strip_heredoc )
164165 class CustomCommand
165166 def call
166167 puts "omg"
@@ -172,7 +173,7 @@ def exec_name
172173 end
173174
174175 Spring.register_command "custom", CustomCommand.new
175- CODE
176+ RUBY
176177
177178 assert_success "bin/spring custom" , stdout : "omg"
178179
@@ -200,46 +201,48 @@ def exec_name
200201 end
201202
202203 test "binstub upgrade" do
203- File . write ( app . path ( "bin/rake" ) , <<CODE )
204- #!/usr/bin/env ruby
205-
206- if !Process.respond_to?(:fork) || Gem::Specification.find_all_by_name("spring").empty?
207- exec "bundle", "exec", "rake", *ARGV
208- else
209- ARGV.unshift "rake"
210- load Gem.bin_path("spring", "spring")
211- end
212- CODE
213-
214- File . write ( app . path ( "bin/rails" ) , <<CODE )
215- #!/usr/bin/env ruby
216-
217- if !Process.respond_to?(:fork) || Gem::Specification.find_all_by_name("spring").empty?
218- APP_PATH = File.expand_path('../../config/application', __FILE__)
219- require_relative '../config/boot'
220- require 'rails/commands'
221- else
222- ARGV.unshift "rails"
223- load Gem.bin_path("spring", "spring")
224- end
225- CODE
204+ File . write ( app . path ( "bin/rake" ) , <<-RUBY . strip_heredoc )
205+ #!/usr/bin/env ruby
206+
207+ if !Process.respond_to?(:fork) || Gem::Specification.find_all_by_name("spring").empty?
208+ exec "bundle", "exec", "rake", *ARGV
209+ else
210+ ARGV.unshift "rake"
211+ load Gem.bin_path("spring", "spring")
212+ end
213+ RUBY
214+
215+ File . write ( app . path ( "bin/rails" ) , <<-RUBY . strip_heredoc )
216+ #!/usr/bin/env ruby
217+
218+ if !Process.respond_to?(:fork) || Gem::Specification.find_all_by_name("spring").empty?
219+ APP_PATH = File.expand_path('../../config/application', __FILE__)
220+ require_relative '../config/boot'
221+ require 'rails/commands'
222+ else
223+ ARGV.unshift "rails"
224+ load Gem.bin_path("spring", "spring")
225+ end
226+ RUBY
226227
227228 assert_success "bin/spring binstub --all" , stdout : "upgraded"
228229
229- assert_equal app . path ( "bin/rake" ) . read , <<CODE
230- #!/usr/bin/env ruby
231- #{ Spring ::Client ::Binstub ::LOADER . strip }
232- require 'bundler/setup'
233- load Gem.bin_path('rake', 'rake')
234- CODE
230+ expected = <<-RUBY . gsub ( /^ / , "" )
231+ #!/usr/bin/env ruby
232+ #{ Spring ::Client ::Binstub ::LOADER . strip }
233+ require 'bundler/setup'
234+ load Gem.bin_path('rake', 'rake')
235+ RUBY
236+ assert_equal expected , app . path ( "bin/rake" ) . read
235237
236- assert_equal app . path ( "bin/rails" ) . read , <<CODE
237- #!/usr/bin/env ruby
238- #{ Spring ::Client ::Binstub ::LOADER . strip }
239- APP_PATH = File.expand_path('../../config/application', __FILE__)
240- require_relative '../config/boot'
241- require 'rails/commands'
242- CODE
238+ expected = <<-RUBY . gsub ( /^ / , "" )
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+ RUBY
245+ assert_equal expected , app . path ( "bin/rails" ) . read
243246 end
244247
245248 test "after fork callback" do
@@ -278,17 +281,17 @@ def exec_name
278281 end
279282
280283 test "setting env vars with rake" do
281- File . write ( app . path ( "lib/tasks/env.rake" ) , <<-'CODE' )
284+ File . write ( app . path ( "lib/tasks/env.rake" ) , <<-RUBY . strip_heredoc )
282285 task :print_rails_env => :environment do
283286 puts Rails.env
284287 end
285288
286289 task :print_env do
287- ENV.each { |k, v| puts "#{k}=#{v}" }
290+ ENV.each { |k, v| puts "\ # {k}=\ # {v}" }
288291 end
289292
290293 task(:default).clear.enhance [:print_rails_env]
291- CODE
294+ RUBY
292295
293296 assert_success "bin/rake RAILS_ENV=test print_rails_env" , stdout : "test"
294297 assert_success "bin/rake FOO=bar print_env" , stdout : "FOO=bar"
@@ -305,15 +308,15 @@ def exec_name
305308 end
306309
307310 test "changing the Gemfile works when spring calls into itself" do
308- File . write ( app . path ( "script.rb" ) , <<-CODE )
311+ File . write ( app . path ( "script.rb" ) , <<-RUBY . strip_heredoc )
309312 gemfile = Rails.root.join("Gemfile")
310313 File.write(gemfile, "\# {gemfile.read}gem 'devise'\\ n")
311314 Bundler.with_clean_env do
312315 system(#{ app . env . inspect } , "bundle install")
313316 end
314317 output = `\# {Rails.root.join('bin/rails')} runner 'require "devise"; puts "done";'`
315318 exit output == "done\n "
316- CODE
319+ RUBY
317320
318321 assert_success [ %(bin/rails runner 'load Rails.root.join("script.rb")') , timeout : 60 ]
319322 end
0 commit comments