Skip to content
This repository has been archived by the owner on Apr 14, 2021. It is now read-only.

Bundler >= 1.9.0 fails to create gem plugins #3603

Merged
merged 1 commit into from
Apr 30, 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
4 changes: 2 additions & 2 deletions lib/bundler/cli/gem.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ def run
underscored_name = name.tr('-', '_')
namespaced_path = name.tr('-', '/')
constant_name = name.gsub(/-[_-]*(?![_-]|$)/){ '::' }.gsub(/([_-]+|(::)|^)(.|$)/){ $2.to_s + $3.upcase }

constant_array = constant_name.split('::')

git_user_name = `git config user.name`.chomp
git_user_email = `git config user.email`.chomp

Expand Down Expand Up @@ -188,7 +188,7 @@ def ensure_safe_gem_name name, constant_array
if name =~ /^\d/
Bundler.ui.error "Invalid gem name #{name} Please give a name which does not start with numbers."
exit 1
elsif Object.const_defined?(constant_array.first)
elsif constant_array.inject(Object) {|c, s| (c.const_defined?(s) && c.const_get(s)) || break }
Bundler.ui.error "Invalid gem name #{name} constant #{constant_array.join("::")} is already in use. Please choose another gem name."
exit 1
end
Expand Down
29 changes: 29 additions & 0 deletions spec/commands/newgem_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -605,6 +605,35 @@ def create_temporary_dir(dir)
end
end

describe "#ensure_safe_gem_name" do
before do
bundle "gem #{subject}"
end
after do
Bundler.clear_gemspec_cache
end

context "with an existing const name" do
subject { "gem" }
it { expect(out).to include("Invalid gem name #{subject}") }
end

context "with an existing hyphenated const name" do
subject { "gem-specification" }
it { expect(out).to include("Invalid gem name #{subject}") }
end

context "starting with an existing const name" do
subject { "gem-somenewconstantname" }
it { expect(out).not_to include("Invalid gem name #{subject}") }
end

context "ending with an existing const name" do
subject { "somenewconstantname-gem" }
it { expect(out).not_to include("Invalid gem name #{subject}") }
end
end

context "on first run" do
before do
in_app_root
Expand Down