summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDennis Suratna <dennis.suratna@gmail.com>2017-03-31 11:44:54 -0700
committerDennis Suratna <dennis.suratna@gmail.com>2017-04-10 15:46:27 +0700
commit5c42e22a1aacc3d0060c9d354be088586b1d46e6 (patch)
tree9c6d16e189f58c7d82c43f045aadb3e9c15db175
parent668e37e0840baf05d174e73eb695a7dc959227d1 (diff)
downloadbundler-5c42e22a1aacc3d0060c9d354be088586b1d46e6.tar.gz
Add negative testing
-rw-r--r--lib/bundler/cli/add.rb9
-rw-r--r--spec/commands/add_spec.rb24
2 files changed, 32 insertions, 1 deletions
diff --git a/lib/bundler/cli/add.rb b/lib/bundler/cli/add.rb
index 61a8f36d85..4664aadb0d 100644
--- a/lib/bundler/cli/add.rb
+++ b/lib/bundler/cli/add.rb
@@ -11,7 +11,14 @@ module Bundler
def run
version = @options[:version].nil? ? nil : @options[:version].split(",").map(&:strip)
- dependency = Bundler::Dependency.new(@gem_name, version, @options)
+
+ begin
+ dependency = Bundler::Dependency.new(@gem_name, version, @options)
+ rescue Gem::Requirement::BadRequirementError => e
+ Bundler.ui.error(e.message)
+ return
+ end
+
Injector.inject([dependency], :conservative_versioning => @options[:version].nil?) # Perform conservative versioning only when version is not specified
Installer.install(Bundler.root, Bundler.definition)
end
diff --git a/spec/commands/add_spec.rb b/spec/commands/add_spec.rb
index 451cc2ed2b..12a8155ac1 100644
--- a/spec/commands/add_spec.rb
+++ b/spec/commands/add_spec.rb
@@ -79,4 +79,28 @@ RSpec.describe "bundle add" do
expect(the_bundle).to include_gems "foo 2.0"
end
end
+
+ it "using combination of short form options works like long form" do
+ bundle "add 'foo' -s='file://#{gem_repo2}' -g='development' -v='~>1.0'"
+ expect(bundled_app("Gemfile").read).to match(%r{gem "foo", "~> 1.0", :group => \[:development\], :source => 'file:\/\/#{gem_repo2}'})
+ expect(the_bundle).to include_gems "foo 1.1"
+ end
+
+ it "shows error message when version is not formatted correctly" do
+ bundle "add 'foo' -v='~>1 . 0'"
+ expect(out).to match('Illformed requirement ["~>1 . 0"]')
+ end
+
+ it "shows error message when gem cannot be found" do
+ bundle "add 'werk_it'"
+ expect(out).to match("Could not find gem 'werk_it' in any of the gem sources listed in your Gemfile.")
+ end
+
+ it "shows error message when source cannot be reached" do
+ bundle "add 'baz' --source='http://badhostasdf'"
+ expect(out).to include("Could not reach host badhostasdf. Check your network connection and try again.")
+
+ bundle "add 'baz' --source='file://does/not/exist'"
+ expect(out).to include("Could not fetch specs from file://does/not/exist/")
+ end
end