4
4
require "timeout"
5
5
require "spring/sid"
6
6
require "spring/client"
7
+ require "active_support/core_ext/string/strip"
7
8
8
9
module Spring
9
10
module Test
@@ -111,13 +112,13 @@ def assert_speedup(ratio = DEFAULT_SPEEDUP)
111
112
test "app gets reloaded when preloaded files change" do
112
113
assert_success app . spring_test_command
113
114
114
- File . write ( app . application_config , app . application_config . read + <<-CODE )
115
+ File . write ( app . application_config , app . application_config . read + <<-RUBY . strip_heredoc )
115
116
class Foo
116
117
def self.omg
117
118
raise "omg"
118
119
end
119
120
end
120
- CODE
121
+ RUBY
121
122
File . write ( app . test , app . test . read . sub ( "get :index" , "Foo.omg" ) )
122
123
123
124
app . await_reload
@@ -160,7 +161,7 @@ def self.omg
160
161
# Start spring before setting up the command, to test that it gracefully upgrades itself
161
162
assert_success "bin/rails runner ''"
162
163
163
- File . write ( app . spring_config , <<-CODE )
164
+ File . write ( app . spring_config , <<-RUBY . strip_heredoc )
164
165
class CustomCommand
165
166
def call
166
167
puts "omg"
@@ -172,7 +173,7 @@ def exec_name
172
173
end
173
174
174
175
Spring.register_command "custom", CustomCommand.new
175
- CODE
176
+ RUBY
176
177
177
178
assert_success "bin/spring custom" , stdout : "omg"
178
179
@@ -200,46 +201,48 @@ def exec_name
200
201
end
201
202
202
203
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
226
227
227
228
assert_success "bin/spring binstub --all" , stdout : "upgraded"
228
229
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
235
237
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
243
246
end
244
247
245
248
test "after fork callback" do
@@ -278,17 +281,17 @@ def exec_name
278
281
end
279
282
280
283
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 )
282
285
task :print_rails_env => :environment do
283
286
puts Rails.env
284
287
end
285
288
286
289
task :print_env do
287
- ENV.each { |k, v| puts "#{k}=#{v}" }
290
+ ENV.each { |k, v| puts "\ # {k}=\ # {v}" }
288
291
end
289
292
290
293
task(:default).clear.enhance [:print_rails_env]
291
- CODE
294
+ RUBY
292
295
293
296
assert_success "bin/rake RAILS_ENV=test print_rails_env" , stdout : "test"
294
297
assert_success "bin/rake FOO=bar print_env" , stdout : "FOO=bar"
@@ -305,15 +308,15 @@ def exec_name
305
308
end
306
309
307
310
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 )
309
312
gemfile = Rails.root.join("Gemfile")
310
313
File.write(gemfile, "\# {gemfile.read}gem 'devise'\\ n")
311
314
Bundler.with_clean_env do
312
315
system(#{ app . env . inspect } , "bundle install")
313
316
end
314
317
output = `\# {Rails.root.join('bin/rails')} runner 'require "devise"; puts "done";'`
315
318
exit output == "done\n "
316
- CODE
319
+ RUBY
317
320
318
321
assert_success [ %(bin/rails runner 'load Rails.root.join("script.rb")') , timeout : 60 ]
319
322
end
0 commit comments