Skip to content

Fix uncaught Gem::LoadError in binstub loader #448

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 18, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions lib/spring/client/binstub.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,9 @@ class Binstub < Command
# should cause the "unsprung" version of the command to run.
LOADER = <<CODE
begin
spring_bin_path = File.expand_path('../spring', __FILE__)
load spring_bin_path
load File.expand_path('../spring', __FILE__)
rescue LoadError => e
raise unless e.message.end_with? spring_bin_path, 'spring/binstub'
raise unless e.message.include?('spring')
end
CODE

Expand Down Expand Up @@ -51,6 +50,7 @@ class Binstub < Command
BINSTUB_VARIATIONS = Regexp.union [
%{begin\n load File.expand_path("../spring", __FILE__)\nrescue LoadError\nend\n},
%{begin\n load File.expand_path('../spring', __FILE__)\nrescue LoadError\nend\n},
%{begin\n spring_bin_path = File.expand_path('../spring', __FILE__)\n load spring_bin_path\nrescue LoadError => e\n raise unless e.message.end_with? spring_bin_path, 'spring/binstub'\nend\n},
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is getting annoying :D

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well it's much easier now that the variations are listed and used by both upgrade and remove.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, that was a great refactor :D

LOADER
]

Expand Down
41 changes: 25 additions & 16 deletions lib/spring/test/acceptance_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,13 @@ def exec_name
end

test "binstub upgrade with new binstub variations" do
expected = <<-RUBY.gsub(/^ /, "")
#!/usr/bin/env ruby
#{Spring::Client::Binstub::LOADER.strip}
require 'bundler/setup'
load Gem.bin_path('rake', 'rake')
RUBY

# older variation with double quotes
File.write(app.path("bin/rake"), <<-RUBY.strip_heredoc)
#!/usr/bin/env ruby
Expand All @@ -286,36 +293,38 @@ def exec_name
load Gem.bin_path('rake', 'rake')
RUBY

assert_success "bin/spring binstub rake", stdout: "bin/rake: upgraded"
assert_equal expected, app.path("bin/rake").read

# newer variation with single quotes
File.write(app.path("bin/rails"), <<-RUBY.strip_heredoc)
File.write(app.path("bin/rake"), <<-RUBY.strip_heredoc)
#!/usr/bin/env ruby
begin
load File.expand_path('../spring', __FILE__)
rescue LoadError
end
APP_PATH = File.expand_path('../../config/application', __FILE__)
require_relative '../config/boot'
require 'rails/commands'
require 'bundler/setup'
load Gem.bin_path('rake', 'rake')
RUBY

assert_success "bin/spring binstub --all", stdout: "upgraded"
assert_success "bin/spring binstub rake", stdout: "bin/rake: upgraded"
assert_equal expected, app.path("bin/rake").read

expected = <<-RUBY.gsub(/^ /, "")
# newer variation which checks end of exception message
File.write(app.path("bin/rake"), <<-RUBY.strip_heredoc)
#!/usr/bin/env ruby
#{Spring::Client::Binstub::LOADER.strip}
begin
spring_bin_path = File.expand_path('../spring', __FILE__)
load spring_bin_path
rescue LoadError => e
raise unless e.message.end_with? spring_bin_path, 'spring/binstub'
end
require 'bundler/setup'
load Gem.bin_path('rake', 'rake')
RUBY
assert_equal expected, app.path("bin/rake").read

expected = <<-RUBY.gsub(/^ /, "")
#!/usr/bin/env ruby
#{Spring::Client::Binstub::LOADER.strip}
APP_PATH = File.expand_path('../../config/application', __FILE__)
require_relative '../config/boot'
require 'rails/commands'
RUBY
assert_equal expected, app.path("bin/rails").read
assert_success "bin/spring binstub rake", stdout: "bin/rake: upgraded"
assert_equal expected, app.path("bin/rake").read
end

test "binstub remove with new binstub variations" do
Expand Down