summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndre Arko <andre@arko.net>2015-05-13 12:01:41 -0700
committerAndre Arko <andre@arko.net>2015-05-13 12:01:41 -0700
commit654e44a1febe1ebc89a43bb986a21f4efa653c6c (patch)
tree7a28e7849ba37df5229bc9af982b33405e6fe770
parentac66cd244af2541eb8f4fc5f6a7dec3ad24cdb09 (diff)
downloadbundler-654e44a1febe1ebc89a43bb986a21f4efa653c6c.tar.gz
validate gemspec specifications (with a test)
closes #3639
-rw-r--r--lib/bundler/dsl.rb23
-rw-r--r--spec/bundler/dsl_spec.rb14
2 files changed, 34 insertions, 3 deletions
diff --git a/lib/bundler/dsl.rb b/lib/bundler/dsl.rb
index c4a9f05d16..cd0c80b3ff 100644
--- a/lib/bundler/dsl.rb
+++ b/lib/bundler/dsl.rb
@@ -48,9 +48,10 @@ module Bundler
case gemspecs.size
when 1
- spec = Bundler.load_gemspec(gemspecs.first)
- raise InvalidOption, "There was an error loading the gemspec at #{gemspecs.first}." unless spec
+ spec = load_valid_gemspec(gemspecs.first)
+
gem spec.name, :path => path, :glob => glob
+
group(development_group) do
spec.development_dependencies.each do |dep|
gem dep.name, *(dep.requirement.as_list + [:type => :development])
@@ -59,7 +60,8 @@ module Bundler
when 0
raise InvalidOption, "There are no gemspecs at #{expanded_path}."
else
- raise InvalidOption, "There are multiple gemspecs at #{expanded_path}. Please use the :name option to specify which one."
+ raise InvalidOption, "There are multiple gemspecs at #{expanded_path}. " \
+ "Please use the :name option to specify which one should be used."
end
end
@@ -358,6 +360,21 @@ module Bundler
end
end
+ def load_valid_gemspec(path)
+ spec = Bundler.load_gemspec(path)
+
+ unless spec
+ raise InvalidOption, "There was an error loading the gemspec at " \
+ "#{path}. Make sure you can build the gem, then try again."
+ end
+
+ spec.validate
+ spec
+ rescue Gem::InvalidSpecificationException => e
+ raise InvalidOption, "The gemspec at #{path} is not valid. " \
+ "The validation error was '#{e.message}'"
+ end
+
class DSLError < GemfileError
# @return [String] the description that should be presented to the user.
#
diff --git a/spec/bundler/dsl_spec.rb b/spec/bundler/dsl_spec.rb
index 5c6be9efca..ca97d0c6ca 100644
--- a/spec/bundler/dsl_spec.rb
+++ b/spec/bundler/dsl_spec.rb
@@ -187,4 +187,18 @@ describe Bundler::Dsl do
to raise_error(Bundler::GemfileError, /There was an error parsing `Gemfile`: can't modify frozen String. Bundler cannot continue./)
end
end
+
+ describe "#gemspec" do
+ it "errors on invalid specs" do
+ File.open(bundled_app("foo.gemspec"), "w") do |f|
+ f.write <<-G
+ Gem::Specification.new do |s|
+ s.name = "foo"
+ end
+ G
+ end
+ expect(Bundler).to receive(:default_gemfile).and_return(bundled_app("Gemfile"))
+ expect { subject.gemspec }.to raise_error(Bundler::InvalidOption).with_message(/missing value for attribute version/)
+ end
+ end
end