@@ -208,6 +208,11 @@ def exec_name
208
208
assert_success "bin/rake -T" , stdout : "rake db:migrate"
209
209
end
210
210
211
+ test "binstub remove all" do
212
+ assert_success "bin/spring binstub --remove --all"
213
+ refute File . exist? ( app . path ( "bin/spring" ) )
214
+ end
215
+
211
216
test "binstub when spring gem is missing" do
212
217
without_gem "spring-#{ Spring ::VERSION } " do
213
218
File . write ( app . gemfile , app . gemfile . read . gsub ( /gem 'spring.*/ , "" ) )
@@ -224,7 +229,7 @@ def exec_name
224
229
end
225
230
end
226
231
227
- test "binstub upgrade" do
232
+ test "binstub upgrade with old binstub " do
228
233
File . write ( app . path ( "bin/rake" ) , <<-RUBY . strip_heredoc )
229
234
#!/usr/bin/env ruby
230
235
@@ -269,6 +274,93 @@ def exec_name
269
274
assert_equal expected , app . path ( "bin/rails" ) . read
270
275
end
271
276
277
+ test "binstub upgrade with new binstub variations" do
278
+ # older variation with double quotes
279
+ File . write ( app . path ( "bin/rake" ) , <<-RUBY . strip_heredoc )
280
+ #!/usr/bin/env ruby
281
+ begin
282
+ load File.expand_path("../spring", __FILE__)
283
+ rescue LoadError
284
+ end
285
+ require 'bundler/setup'
286
+ load Gem.bin_path('rake', 'rake')
287
+ RUBY
288
+
289
+ # newer variation with single quotes
290
+ File . write ( app . path ( "bin/rails" ) , <<-RUBY . strip_heredoc )
291
+ #!/usr/bin/env ruby
292
+ begin
293
+ load File.expand_path('../spring', __FILE__)
294
+ rescue LoadError
295
+ end
296
+ APP_PATH = File.expand_path('../../config/application', __FILE__)
297
+ require_relative '../config/boot'
298
+ require 'rails/commands'
299
+ RUBY
300
+
301
+ assert_success "bin/spring binstub --all" , stdout : "upgraded"
302
+
303
+ expected = <<-RUBY . gsub ( /^ / , "" )
304
+ #!/usr/bin/env ruby
305
+ #{ Spring ::Client ::Binstub ::LOADER . strip }
306
+ require 'bundler/setup'
307
+ load Gem.bin_path('rake', 'rake')
308
+ RUBY
309
+ assert_equal expected , app . path ( "bin/rake" ) . read
310
+
311
+ expected = <<-RUBY . gsub ( /^ / , "" )
312
+ #!/usr/bin/env ruby
313
+ #{ Spring ::Client ::Binstub ::LOADER . strip }
314
+ APP_PATH = File.expand_path('../../config/application', __FILE__)
315
+ require_relative '../config/boot'
316
+ require 'rails/commands'
317
+ RUBY
318
+ assert_equal expected , app . path ( "bin/rails" ) . read
319
+ end
320
+
321
+ test "binstub remove with new binstub variations" do
322
+ # older variation with double quotes
323
+ File . write ( app . path ( "bin/rake" ) , <<-RUBY . strip_heredoc )
324
+ #!/usr/bin/env ruby
325
+ begin
326
+ load File.expand_path("../spring", __FILE__)
327
+ rescue LoadError
328
+ end
329
+ require 'bundler/setup'
330
+ load Gem.bin_path('rake', 'rake')
331
+ RUBY
332
+
333
+ # newer variation with single quotes
334
+ File . write ( app . path ( "bin/rails" ) , <<-RUBY . strip_heredoc )
335
+ #!/usr/bin/env ruby
336
+ begin
337
+ load File.expand_path('../spring', __FILE__)
338
+ rescue LoadError
339
+ end
340
+ APP_PATH = File.expand_path('../../config/application', __FILE__)
341
+ require_relative '../config/boot'
342
+ require 'rails/commands'
343
+ RUBY
344
+
345
+ assert_success "bin/spring binstub --remove rake" , stdout : "bin/rake: spring removed"
346
+ assert_success "bin/spring binstub --remove rails" , stdout : "bin/rails: spring removed"
347
+
348
+ expected = <<-RUBY . strip_heredoc
349
+ #!/usr/bin/env ruby
350
+ require 'bundler/setup'
351
+ load Gem.bin_path('rake', 'rake')
352
+ RUBY
353
+ assert_equal expected , app . path ( "bin/rake" ) . read
354
+
355
+ expected = <<-RUBY . strip_heredoc
356
+ #!/usr/bin/env ruby
357
+ APP_PATH = File.expand_path('../../config/application', __FILE__)
358
+ require_relative '../config/boot'
359
+ require 'rails/commands'
360
+ RUBY
361
+ assert_equal expected , app . path ( "bin/rails" ) . read
362
+ end
363
+
272
364
test "after fork callback" do
273
365
File . write ( app . spring_config , "Spring.after_fork { puts '!callback!' }" )
274
366
assert_success "bin/rails runner 'puts 2'" , stdout : "!callback!\n 2"
0 commit comments