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