summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorColby Swandale <colby@taplaboratories.com>2017-07-25 16:48:59 +1000
committerColby Swandale <colby@taplaboratories.com>2017-07-25 16:50:12 +1000
commited70c04df3bbf505990fbd35e731543fd3e74205 (patch)
tree81ba6da740908213b705f3a9cc689d161d3b0172
parent219ea82fd4c84fcf047fc4cd957147600902288e (diff)
downloadbundler-colby/gem-empty-name-validation.tar.gz
add more clear error message for user when adding a gem in the Gemfile with an empty namecolby/gem-empty-name-validation
-rw-r--r--.rubocop_todo.yml5
-rw-r--r--lib/bundler/dsl.rb3
-rw-r--r--spec/bundler/dsl_spec.rb5
3 files changed, 13 insertions, 0 deletions
diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml
index 5ac75f17b9..287f0d23a9 100644
--- a/.rubocop_todo.yml
+++ b/.rubocop_todo.yml
@@ -268,6 +268,11 @@ Style/IfInsideElse:
- 'lib/bundler/cli/install.rb'
# Offense count: 1
+Style/IfUnlessModifier:
+ Exclude:
+ - 'lib/bundler/dsl.rb'
+
+# Offense count: 1
Style/IfUnlessModifierOfIfUnless:
Exclude:
- 'spec/support/helpers.rb'
diff --git a/lib/bundler/dsl.rb b/lib/bundler/dsl.rb
index e19097f57d..49e7ea47f9 100644
--- a/lib/bundler/dsl.rb
+++ b/lib/bundler/dsl.rb
@@ -345,6 +345,9 @@ repo_name ||= user_name
if name =~ /\s/
raise GemfileError, %('#{name}' is not a valid gem name because it contains whitespace)
end
+ if name.empty?
+ raise GemfileError, %(an empty gem name is not valid)
+ end
normalize_hash(opts)
diff --git a/spec/bundler/dsl_spec.rb b/spec/bundler/dsl_spec.rb
index 080723ac83..270ebe9680 100644
--- a/spec/bundler/dsl_spec.rb
+++ b/spec/bundler/dsl_spec.rb
@@ -110,6 +110,11 @@ RSpec.describe Bundler::Dsl do
to raise_error(Bundler::GemfileError, /is not a valid platform/)
end
+ it "rejects empty gem name" do
+ expect { subject.gem("") }.
+ to raise_error(Bundler::GemfileError, /an empty gem name is not valid/)
+ end
+
it "rejects with a leading space in the name" do
expect { subject.gem(" foo") }.
to raise_error(Bundler::GemfileError, /' foo' is not a valid gem name because it contains whitespace/)