Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Print a useful error if a gemspec require fails

In Ruby 1.9, LOAD_PATH doesn't include the directory the file is in.
Gemspecs that do relative requires work in 1.8, but raise LoadErrors
in 1.9. So the error tries to help people figure out what's wrong.
  • Loading branch information...
commit 2a24019b6e34fa92edbc52ccce57cb2d0481c005 1 parent a54ad01
@indirect indirect authored
View
1  lib/bundler.rb
@@ -43,6 +43,7 @@ class PathError < BundlerError; status_code(13) ; end
class GitError < BundlerError; status_code(11) ; end
class DeprecatedMethod < BundlerError; status_code(12) ; end
class DeprecatedOption < BundlerError; status_code(12) ; end
+ class GemspecError < BundlerError; status_code(14) ; end
class << self
attr_writer :ui, :bundle_path
View
11 lib/bundler/source.rb
@@ -187,7 +187,16 @@ def load_spec_files
Dir["#{path}/#{@glob}"].each do |file|
file = Pathname.new(file)
# Eval the gemspec from its parent directory
- if spec = Dir.chdir(file.dirname) { eval(File.read(file.basename), binding, file.expand_path.to_s) }
+ begin
+ spec = Dir.chdir(file.dirname) do
+ eval(File.read(file.basename), binding, file.expand_path.to_s)
+ end
+ rescue LoadError
+ raise GemspecError, "There was a LoadError while evaluating #{file.basename}.\n" +
+ "Does it try to require a relative path? That doesn't work in Ruby 1.9."
+ end
+
+ if spec
spec = Specification.from_gemspec(spec)
spec.loaded_from = file.to_s
spec.source = self
View
24 spec/runtime/environment_rb_spec.rb
@@ -105,7 +105,7 @@
end
describe "with a gemspec that requires other files" do
- before(:each) do
+ before :each do
build_git "bar", :gemspec => false do |s|
s.write "lib/bar/version.rb", %{BAR_VERSION = '1.0'}
s.write "bar.gemspec", <<-G
@@ -119,20 +119,22 @@
G
end
- install_gemfile <<-G
- gem "bar", :git => "#{lib_path('bar-1.0')}"
- G
- bundle :lock
+ gemfile %|gem "bar", :git => "#{lib_path('bar-1.0')}"|
end
it "evals each gemspec in the context of its parent directory" do
-
- run <<-R, :lite_runtime => true
- require 'bar'
- puts BAR
- R
+ bundle :install
+ bundle :lock
+ run "require 'bar'; puts BAR", :lite_runtime => true
out.should == "1.0"
- end
+ end if RUBY_VERSION < "1.9"
+
+ it "error if the gemspec tries a relative require" do
+ bundle :install
+ out.should include("was a LoadError")
+ out.should include("bar.gemspec")
+ out.should include("require a relative path")
+ end if RUBY_VERSION >= "1.9"
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.