summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAgrim Mittal <agrimmittal97@gmail.com>2018-03-23 17:47:30 +0530
committerAgrim Mittal <agrimmittal97@gmail.com>2018-07-02 11:00:23 +0530
commit29dcd379aab9b5ffa7e2151fcbe1aec376b0d360 (patch)
tree7521af8701b60663122343ecbacd8a12a8b22519
parentc3cff89906583c834ff04491a7e57c196b7e341a (diff)
downloadbundler-29dcd379aab9b5ffa7e2151fcbe1aec376b0d360.tar.gz
Add failing tests for install command and fix error message for add
-rw-r--r--lib/bundler/dsl.rb17
-rw-r--r--spec/commands/add_spec.rb5
-rw-r--r--spec/commands/install_spec.rb34
3 files changed, 33 insertions, 23 deletions
diff --git a/lib/bundler/dsl.rb b/lib/bundler/dsl.rb
index 00c9b68276..f001b46551 100644
--- a/lib/bundler/dsl.rb
+++ b/lib/bundler/dsl.rb
@@ -103,24 +103,21 @@ module Bundler
# if there's already a dependency with this name we try to prefer one
if current = @dependencies.find {|d| d.name == dep.name }
deleted_dep = @dependencies.delete(current) if current.type == :development
+
if current.requirement != dep.requirement
unless deleted_dep
return if dep.type == :development
# If no version is specified on adding gem
- if dep.requirement.to_s == ">= 0"
- raise GemfileError, "Gem `#{current.name}` is already added.\n" \
- "If you want to update the gem version, run `bundle update #{current.name}`"
- else
- raise GemfileError, "You cannot specify the same gem twice with different version requirements.\n" \
- "You specified: #{current.name} (#{current.requirement}) and #{dep.name} (#{dep.requirement}). " \
- "If you want to update the gem version, run `bundle update #{current.name}`. You may need to change the version requirement specified in the Gemfile if it's too restrictive"
- end
- end
+ raise GemfileError, "Gem `#{current.name}` is already added" if dep.requirement.to_s == ">= 0"
+ raise GemfileError, "You cannot specify the same gem twice with different version requirements.\n" \
+ "You specified: #{current.name} (#{current.requirement}) and #{dep.name} (#{dep.requirement}). " \
+ "If you want to update the gem version, run `bundle update #{current.name}`. You may need to change the version requirement specified in the Gemfile if it's too restrictive"
+ end
else
Bundler.ui.warn "Your Gemfile lists the gem #{current.name} (#{current.requirement}) more than once.\n" \
- "You should probably keep only one of them.\n" \
+ "Remove any duplicate entries and specify the gem only once (per group).\n" \
"While it's not a problem now, it could cause errors if you change the version of one of them later."
end
diff --git a/spec/commands/add_spec.rb b/spec/commands/add_spec.rb
index 00986e7bb2..5410abf6e9 100644
--- a/spec/commands/add_spec.rb
+++ b/spec/commands/add_spec.rb
@@ -182,8 +182,8 @@ RSpec.describe "bundle add" do
bundle "add 'rack' --version=1.1"
- expect(out).to include "You cannot specify the same gem twice with different version requirements"
- expect(out).to include "If you want to update the gem version, run `bundle update rack`. You may need to change the version requirement specified in the Gemfile if it's too restrictive"
+ expect(out).to include("You cannot specify the same gem twice with different version requirements")
+ expect(out).to include("If you want to update the gem version, run `bundle update rack`. You may need to change the version requirement specified in the Gemfile if it's too restrictive")
end
it "without version requirements" do
@@ -195,7 +195,6 @@ RSpec.describe "bundle add" do
bundle "add 'rack'"
expect(out).to include("Gem `rack` is already added.")
- expect(out).to include("If you want to update the gem version, run `bundle update rack`.")
end
end
end
diff --git a/spec/commands/install_spec.rb b/spec/commands/install_spec.rb
index 16c49fc074..5af7cfb232 100644
--- a/spec/commands/install_spec.rb
+++ b/spec/commands/install_spec.rb
@@ -321,7 +321,7 @@ RSpec.describe "bundle install with gem sources" do
expect(File.exist?(bundled_app("Gemfile.lock"))).to eq(true)
end
- it "throws an error if a gem is added twice in Gemfile without version requirements" do
+ it "throws a warning if a gem is added twice in Gemfile without version requirements" do
install_gemfile <<-G
source "file://#{gem_repo2}"
gem "rack"
@@ -329,18 +329,32 @@ RSpec.describe "bundle install with gem sources" do
G
expect(out).to include("Your Gemfile lists the gem rack (>= 0) more than once.")
- expect(out).to include("You should probably keep only one of them")
+ expect(out).to include("Remove any duplicate entries and specify the gem only once (per group).")
+ expect(out).to include("While it's not a problem now, it could cause errors if you change the version of one of them later.")
end
- it "throws an error if a gem is added twice in Gemfile with version requirements" do
- install_gemfile <<-G
- source "file://#{gem_repo2}"
- gem "rack", "1.0"
- gem "rack", "1.1"
- G
+ context "throws an error if a gem is added twice in Gemfile with version requirements" do
+ it "version of one dependency is not specified" do
+ install_gemfile <<-G
+ source "file://#{gem_repo2}"
+ gem "rack", "1.0"
+ gem "rack"
+ G
+
+ expect(out).to include("Gem `rack` is already added")
+ end
- expect(out).to include("You cannot specify the same gem twice with different version requirements")
- expect(out).to include("If you want to update the gem version, run `bundle update rack`. You may need to change the version requirement specified in the Gemfile if it's too restrictive")
+ it "version of both dependencies are specified" do
+ install_gemfile <<-G
+ source "file://#{gem_repo2}"
+ gem "rack", "1.0"
+ gem "rack", "1.1"
+ G
+ p out
+ expect(out).to include("You cannot specify the same gem twice with different version requirements")
+ expect(out).to include("You specified: rack (= 1.0) and rack (= 1.1).")
+ expect(out).to include("Remove any duplicate entries and specify the gem only once (per group).")
+ end
end
it "gracefully handles error when rubygems server is unavailable" do