summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHomu <homu@barosl.com>2016-01-31 20:30:39 +0900
committerHomu <homu@barosl.com>2016-01-31 20:30:39 +0900
commit6c2664fe442209d84d8b6954e7eba2b2fe034a21 (patch)
tree2b0bbeb20a0df30b7a12570f7342e7ca6bc727bc
parent19b2dcc0de829fb1e87c3f9091f5237706bc0955 (diff)
parentb061eeb4b6354ef547db9e32801e2e4d666bec15 (diff)
downloadbundler-6c2664fe442209d84d8b6954e7eba2b2fe034a21.tar.gz
Auto merge of #4250 - RochesterinNYC:improved-error-message-for-invalid-gemspec, r=indirect
Change behavior and improve clarity of error messages when local gems have invalid gemspecs Now, when a local gem's gemspec contains errors, an error is raised immediately and helpful message is provided. This message instructs the user to fix the gemspec before an attempt is made to fetch the local gem that has an incorrect gemspec. - Addresses #4248
-rw-r--r--lib/bundler.rb6
-rw-r--r--lib/bundler/cli/install.rb3
-rw-r--r--lib/bundler/friendly_errors.rb2
-rw-r--r--spec/bundler/bundler_spec.rb29
-rw-r--r--spec/commands/exec_spec.rb4
-rw-r--r--spec/install/gemfile/path_spec.rb5
6 files changed, 43 insertions, 6 deletions
diff --git a/lib/bundler.rb b/lib/bundler.rb
index 346310cd27..a9145cf92b 100644
--- a/lib/bundler.rb
+++ b/lib/bundler.rb
@@ -352,9 +352,9 @@ module Bundler
spec
end
rescue Gem::InvalidSpecificationException => e
- UI::Shell.new.warn "The gemspec at #{file} is not valid. " \
- "The validation error was '#{e.message}'"
- nil
+ error_message = "The gemspec at #{file} is not valid. Please fix this gemspec.\n" \
+ "The validation error was '#{e.message}'\n"
+ raise Gem::InvalidSpecificationException.new(error_message)
end
def clear_gemspec_cache
diff --git a/lib/bundler/cli/install.rb b/lib/bundler/cli/install.rb
index d114e2386c..4640ad9485 100644
--- a/lib/bundler/cli/install.rb
+++ b/lib/bundler/cli/install.rb
@@ -150,6 +150,9 @@ module Bundler
WARN
end
raise e
+ rescue Gem::InvalidSpecificationException => e
+ Bundler.ui.warn "You have one or more invalid gemspecs that need to be fixed."
+ raise e
end
private
diff --git a/lib/bundler/friendly_errors.rb b/lib/bundler/friendly_errors.rb
index 7f4ac4f085..fd98bf55e1 100644
--- a/lib/bundler/friendly_errors.rb
+++ b/lib/bundler/friendly_errors.rb
@@ -33,6 +33,8 @@ module Bundler
when Interrupt
Bundler.ui.error "\nQuitting..."
Bundler.ui.trace error
+ when Gem::InvalidSpecificationException
+ Bundler.ui.error error.message, :wrap => true
when SystemExit
else request_issue_report_for(error)
end
diff --git a/spec/bundler/bundler_spec.rb b/spec/bundler/bundler_spec.rb
index 1b0addadb5..923217da15 100644
--- a/spec/bundler/bundler_spec.rb
+++ b/spec/bundler/bundler_spec.rb
@@ -73,5 +73,34 @@ describe Bundler do
$VERBOSE = verbose
end
end
+
+ context "validate is true" do
+ subject { Bundler.load_gemspec_uncached(app_gemspec_path, true) }
+
+ context "and there are gemspec validation errors" do
+ let(:ui_shell) { double(:ui_shell) }
+
+ before do
+ allow(Bundler::UI::Shell).to receive(:new).and_return(ui_shell)
+ allow(Bundler.rubygems).to receive(:validate) {
+ raise Gem::InvalidSpecificationException.new("TODO is not an author")
+ }
+ end
+
+ it "should raise a Gem::InvalidSpecificationException and produce a helpful warning message" do
+ File.open(app_gemspec_path, "wb") do |file|
+ file.puts <<-GEMSPEC.gsub(/^\s+/, "")
+ Gem::Specification.new do |gem|
+ gem.author = "TODO"
+ end
+ GEMSPEC
+ end
+
+ expect { subject }.to raise_error(Gem::InvalidSpecificationException,
+ "The gemspec at #{app_gemspec_path} is not valid. "\
+ "Please fix this gemspec.\nThe validation error was 'TODO is not an author'\n")
+ end
+ end
+ end
end
end
diff --git a/spec/commands/exec_spec.rb b/spec/commands/exec_spec.rb
index ce7f41dc65..05c1109ee7 100644
--- a/spec/commands/exec_spec.rb
+++ b/spec/commands/exec_spec.rb
@@ -341,8 +341,8 @@ describe "bundle exec" do
bundle "exec irb", :expect_err => true
- expect(out).to match("The gemspec at #{lib_path("foo-1.0").join("foo.gemspec")} is not valid")
- expect(out).to match('"TODO" is not a summary')
+ expect(err).to match("The gemspec at #{lib_path("foo-1.0").join("foo.gemspec")} is not valid")
+ expect(err).to match('"TODO" is not a summary')
end
end
diff --git a/spec/install/gemfile/path_spec.rb b/spec/install/gemfile/path_spec.rb
index 86179350d9..ee45bf3efd 100644
--- a/spec/install/gemfile/path_spec.rb
+++ b/spec/install/gemfile/path_spec.rb
@@ -157,8 +157,11 @@ describe "bundle install with explicit source paths" do
gem "foo", :path => "#{lib_path("foo-1.0")}"
G
- expect(out).to match(/missing value for attribute version/)
expect(out).to_not include("ERROR REPORT")
+ expect(out).to_not include("Your Gemfile has no gem server sources.")
+ expect(out).to match(/is not valid. Please fix this gemspec./)
+ expect(out).to match(/The validation error was 'missing value for attribute version'/)
+ expect(out).to match(/You have one or more invalid gemspecs that need to be fixed/)
end
it "supports gemspec syntax" do