summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/bundler/dsl.rb2
-rw-r--r--lib/bundler/source/gemspec.rb4
-rw-r--r--lib/bundler/source/path.rb2
-rw-r--r--spec/bundler/commands/install_spec.rb24
4 files changed, 31 insertions, 1 deletions
diff --git a/lib/bundler/dsl.rb b/lib/bundler/dsl.rb
index 4f9fbc55b1..0e36f52269 100644
--- a/lib/bundler/dsl.rb
+++ b/lib/bundler/dsl.rb
@@ -290,7 +290,7 @@ module Bundler
@dependencies.delete(current)
elsif dep.gemspec_dev_dep?
return
- elsif current.source != dep.source
+ elsif current.source.to_s != dep.source.to_s
raise GemfileError, "You cannot specify the same gem twice coming from different sources.\n" \
"You specified that #{name} (#{dep.requirement}) should come from " \
"#{current.source || "an unspecified source"} and #{dep.source}\n"
diff --git a/lib/bundler/source/gemspec.rb b/lib/bundler/source/gemspec.rb
index b59dce1d09..ed766dbe74 100644
--- a/lib/bundler/source/gemspec.rb
+++ b/lib/bundler/source/gemspec.rb
@@ -10,6 +10,10 @@ module Bundler
super
@gemspec = options["gemspec"]
end
+
+ def to_s
+ "gemspec at `#{@path}`"
+ end
end
end
end
diff --git a/lib/bundler/source/path.rb b/lib/bundler/source/path.rb
index 7511def230..76bd1c66c1 100644
--- a/lib/bundler/source/path.rb
+++ b/lib/bundler/source/path.rb
@@ -53,6 +53,8 @@ module Bundler
"source at `#{@path}`"
end
+ alias_method :identifier, :to_s
+
alias_method :to_gemfile, :path
def hash
diff --git a/spec/bundler/commands/install_spec.rb b/spec/bundler/commands/install_spec.rb
index e7c1f5e456..77c7dff0ce 100644
--- a/spec/bundler/commands/install_spec.rb
+++ b/spec/bundler/commands/install_spec.rb
@@ -615,6 +615,30 @@ RSpec.describe "bundle install with gem sources" do
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.")
end
+ it "errors out if a gem is specified in a gemspec and in the Gemfile" do
+ gem = tmp("my-gem-1")
+
+ build_lib "rubocop", path: gem do |s|
+ s.add_development_dependency "rubocop", "~> 1.0"
+ end
+
+ build_repo4 do
+ build_gem "rubocop"
+ end
+
+ gemfile <<~G
+ source "https://gem.repo4"
+
+ gem "rubocop", :path => "#{gem}"
+ gemspec path: "#{gem}"
+ G
+
+ bundle :install, raise_on_error: false
+
+ expect(err).to include("There was an error parsing `Gemfile`: You cannot specify the same gem twice coming from different sources.")
+ expect(err).to include("You specified that rubocop (>= 0) should come from source at `#{gem}` and gemspec at `#{gem}`")
+ end
+
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
build_lib "my-gem", path: bundled_app do |s|
s.add_development_dependency "activesupport"