diff options
author | Agrim Mittal <agrimmittal97@gmail.com> | 2018-04-07 22:51:42 +0530 |
---|---|---|
committer | Agrim Mittal <agrimmittal97@gmail.com> | 2018-07-02 11:00:23 +0530 |
commit | 772d04c237540b3cdd4e199fe822f0d47a783895 (patch) | |
tree | e7f8ad43670cd5f6517329699174c91d6610dc40 | |
parent | 0c3563fd91dba5281e84c5667488501161f4e87b (diff) | |
download | bundler-772d04c237540b3cdd4e199fe822f0d47a783895.tar.gz |
Fix failing specs
-rw-r--r-- | lib/bundler/dsl.rb | 14 | ||||
-rw-r--r-- | spec/commands/add_spec.rb | 9 | ||||
-rw-r--r-- | spec/commands/install_spec.rb | 6 |
3 files changed, 17 insertions, 12 deletions
diff --git a/lib/bundler/dsl.rb b/lib/bundler/dsl.rb index f001b46551..1ef6ec8e8d 100644 --- a/lib/bundler/dsl.rb +++ b/lib/bundler/dsl.rb @@ -108,15 +108,21 @@ module Bundler unless deleted_dep return if dep.type == :development - # If no version is specified on adding gem - raise GemfileError, "Gem `#{current.name}` is already added" if dep.requirement.to_s == ">= 0" + update_prompt = "" + + if File.basename(@gemfile) == "injected gems" + update_prompt = ". If you want to update the gem version, run `bundle update #{current.name}`. " \ + "You may also need to change the version requirement specified in the Gemfile if it's too restrictive" + end 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" + "You specified: #{current.name} (#{current.requirement}) and #{dep.name} (#{dep.requirement})" \ + "#{update_prompt}" 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 86bd74164d..0b403e2f25 100644 --- a/spec/commands/add_spec.rb +++ b/spec/commands/add_spec.rb @@ -193,9 +193,8 @@ RSpec.describe "bundle add" do bundle "add 'rack' --version=1.1" - expect(out).to include("Gem `rack` is already added.") 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("If you want to update the gem version, run `bundle update rack`. You may also need to change the version requirement specified in the Gemfile if it's too restrictive") end it "without version requirements" do @@ -206,9 +205,8 @@ RSpec.describe "bundle add" do bundle "add 'rack'" - expect(out).to include("Gem `rack` is already added.") 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("If you want to update the gem version, run `bundle update rack`. You may also need to change the version requirement specified in the Gemfile if it's too restrictive") end end @@ -221,9 +219,8 @@ RSpec.describe "bundle add" do bundle "add 'rack' --version=1.1" - expect(out).to include("Gem `rack` is already added.") 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("If you want to update the gem version, run `bundle update rack`. You may also need to change the version requirement specified in the Gemfile if it's too restrictive") end end end diff --git a/spec/commands/install_spec.rb b/spec/commands/install_spec.rb index f77864dd0f..394f672fef 100644 --- a/spec/commands/install_spec.rb +++ b/spec/commands/install_spec.rb @@ -345,8 +345,10 @@ RSpec.describe "bundle install with gem sources" do 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 + end - it "version of one dependency is not specified" do + context "throws an error if a gem is added twice in Gemfile" do + it "when version of one dependency is not specified" do install_gemfile <<-G source "file://#{gem_repo2}" gem "rack" @@ -357,7 +359,7 @@ RSpec.describe "bundle install with gem sources" do expect(out).to include("You specified: rack (>= 0) and rack (= 1.0).") end - it "different versions of both dependencies are specified" do + it "when different versions of both dependencies are specified" do install_gemfile <<-G source "file://#{gem_repo2}" gem "rack", "1.0" |