Skip to content

Commit 0d91997

Browse files
manabeaihsbt
authored andcommitted
[rubygems/rubygems] Improve error message when path and gemspec point to the same gem in Gemfile
rubygems/rubygems@e47a9064be
1 parent a9db92f commit 0d91997

File tree

4 files changed

+31
-1
lines changed

4 files changed

+31
-1
lines changed

lib/bundler/dsl.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ def add_dependency(name, version = nil, options = {})
290290
@dependencies.delete(current)
291291
elsif dep.gemspec_dev_dep?
292292
return
293-
elsif current.source != dep.source
293+
elsif current.source.to_s != dep.source.to_s
294294
raise GemfileError, "You cannot specify the same gem twice coming from different sources.\n" \
295295
"You specified that #{name} (#{dep.requirement}) should come from " \
296296
"#{current.source || "an unspecified source"} and #{dep.source}\n"

lib/bundler/source/gemspec.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ def initialize(options)
1010
super
1111
@gemspec = options["gemspec"]
1212
end
13+
14+
def to_s
15+
"gemspec at `#{@path}`"
16+
end
1317
end
1418
end
1519
end

lib/bundler/source/path.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ def to_s
5353
"source at `#{@path}`"
5454
end
5555

56+
alias_method :identifier, :to_s
57+
5658
alias_method :to_gemfile, :path
5759

5860
def hash

spec/bundler/commands/install_spec.rb

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -615,6 +615,30 @@
615615
expect(err).to include("Two gemspec development dependencies have conflicting requirements on the same gem: rubocop (~> 1.36.0) and rubocop (~> 2.0). Bundler cannot continue.")
616616
end
617617

618+
it "errors out if a gem is specified in a gemspec and in the Gemfile" do
619+
gem = tmp("my-gem-1")
620+
621+
build_lib "rubocop", path: gem do |s|
622+
s.add_development_dependency "rubocop", "~> 1.0"
623+
end
624+
625+
build_repo4 do
626+
build_gem "rubocop"
627+
end
628+
629+
gemfile <<~G
630+
source "https://gem.repo4"
631+
632+
gem "rubocop", :path => "#{gem}"
633+
gemspec path: "#{gem}"
634+
G
635+
636+
bundle :install, raise_on_error: false
637+
638+
expect(err).to include("There was an error parsing `Gemfile`: You cannot specify the same gem twice coming from different sources.")
639+
expect(err).to include("You specified that rubocop (>= 0) should come from source at `#{gem}` and gemspec at `#{gem}`")
640+
end
641+
618642
it "does not warn if a gem is added once in Gemfile and also inside a gemspec as a development dependency, with same requirements, and different sources" do
619643
build_lib "my-gem", path: bundled_app do |s|
620644
s.add_development_dependency "activesupport"

0 commit comments

Comments
 (0)