summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAgrim Mittal <agrimmittal97@gmail.com>2018-03-20 12:43:07 +0530
committerAgrim Mittal <agrimmittal97@gmail.com>2018-07-02 11:00:23 +0530
commitc3cff89906583c834ff04491a7e57c196b7e341a (patch)
tree28a210fee40c31fd5c54a6bf6ebfc292d630f4fc
parent1ecfd96b544e75af75e0b530f7501840075c0c45 (diff)
downloadbundler-c3cff89906583c834ff04491a7e57c196b7e341a.tar.gz
Add tests for version specifications
-rw-r--r--lib/bundler/dsl.rb4
-rw-r--r--spec/commands/add_spec.rb30
-rw-r--r--spec/commands/install_spec.rb22
3 files changed, 46 insertions, 10 deletions
diff --git a/lib/bundler/dsl.rb b/lib/bundler/dsl.rb
index f22571cd63..00c9b68276 100644
--- a/lib/bundler/dsl.rb
+++ b/lib/bundler/dsl.rb
@@ -108,9 +108,9 @@ module Bundler
return if dep.type == :development
# If no version is specified on adding gem
- if "#{dep.requirement}" == ">= 0"
+ 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}`."
+ "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}). " \
diff --git a/spec/commands/add_spec.rb b/spec/commands/add_spec.rb
index 181d3719a6..00986e7bb2 100644
--- a/spec/commands/add_spec.rb
+++ b/spec/commands/add_spec.rb
@@ -173,15 +173,29 @@ RSpec.describe "bundle add" do
end
end
- it "throws an error if a gem is added which is already specified in Gemfile" do
- install_gemfile <<-G
- source "file://#{gem_repo2}"
- gem "rack", "1.0"
- G
+ context "throws an error if a gem is added which is already specified in Gemfile" do
+ it "with version requirements" do
+ install_gemfile <<-G
+ source "file://#{gem_repo2}"
+ gem "rack", "1.0"
+ G
+
+ bundle "add 'rack' --version=1.1"
- bundle "add 'rack'"
+ 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
+ install_gemfile <<-G
+ source "file://#{gem_repo2}"
+ gem "rack", "1.0"
+ G
- 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"
+ 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 85593ee0ff..16c49fc074 100644
--- a/spec/commands/install_spec.rb
+++ b/spec/commands/install_spec.rb
@@ -321,6 +321,28 @@ 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
+ install_gemfile <<-G
+ source "file://#{gem_repo2}"
+ gem "rack"
+ gem "rack"
+ 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")
+ 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
+
+ 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 "gracefully handles error when rubygems server is unavailable" do
install_gemfile <<-G, :artifice => nil
source "file://#{gem_repo1}"