From eb8bb8d5ec2e4a5b09256822adbb3892f3fb90b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Rodr=C3=ADguez?= Date: Sat, 9 Mar 2019 17:29:26 +0100 Subject: [PATCH 01/10] Use exact path to gem in `bundle info` specs For consistency with `bundle show` specs. --- spec/commands/info_spec.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/spec/commands/info_spec.rb b/spec/commands/info_spec.rb index 70a304823ad..c2eaa94380b 100644 --- a/spec/commands/info_spec.rb +++ b/spec/commands/info_spec.rb @@ -13,8 +13,8 @@ bundle "info rails" expect(out).to include "* rails (2.3.2) \tSummary: This is just a fake gem for testing -\tHomepage: http://example.com" - expect(out).to match(%r{Path\: .*\/rails\-2\.3\.2}) +\tHomepage: http://example.com +\tPath: #{default_bundle_path("gems", "rails-2.3.2")}" end context "given a gem that is not installed" do @@ -50,7 +50,7 @@ context "given --path option" do it "prints the path to the gem" do bundle "info rails" - expect(out).to match(%r{.*\/rails\-2\.3\.2}) + expect(out).to eq(default_bundle_path("gems", "rails-2.3.2").to_s) end end end From 844e3499ac3b5c584d40b83ca177b7d6d885beb6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Rodr=C3=ADguez?= Date: Sat, 9 Mar 2019 17:36:42 +0100 Subject: [PATCH 02/10] Remove duplicated spec This case `bundle info rails` is already tested at the beginning of the file. Plus, the description is misleading since no `--path` option is given here. --- spec/commands/info_spec.rb | 7 ------- 1 file changed, 7 deletions(-) diff --git a/spec/commands/info_spec.rb b/spec/commands/info_spec.rb index c2eaa94380b..76cbda2612e 100644 --- a/spec/commands/info_spec.rb +++ b/spec/commands/info_spec.rb @@ -46,12 +46,5 @@ expect(out).to_not include("Homepage:") end end - - context "given --path option" do - it "prints the path to the gem" do - bundle "info rails" - expect(out).to eq(default_bundle_path("gems", "rails-2.3.2").to_s) - end - end end end From b00b3a3569b037bfbfbcb5ee1c1d84788db892ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Rodr=C3=ADguez?= Date: Sat, 9 Mar 2019 17:39:27 +0100 Subject: [PATCH 03/10] Slight tweak to some other specs To be just like how current `bundle show` is tested. --- spec/commands/info_spec.rb | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/spec/commands/info_spec.rb b/spec/commands/info_spec.rb index 76cbda2612e..48ed4bd528c 100644 --- a/spec/commands/info_spec.rb +++ b/spec/commands/info_spec.rb @@ -9,7 +9,7 @@ G end - it "prints information about the current gem" do + it "prints information if gem exists in bundle" do bundle "info rails" expect(out).to include "* rails (2.3.2) \tSummary: This is just a fake gem for testing @@ -17,11 +17,9 @@ \tPath: #{default_bundle_path("gems", "rails-2.3.2")}" end - context "given a gem that is not installed" do - it "prints missing gem error" do - bundle "info foo" - expect(err).to eq "Could not find gem 'foo'." - end + it "complains if gem not in bundle" do + bundle "info missing" + expect(err).to eq("Could not find gem 'missing'.") end context "given a default gem shippped in ruby", :ruby_repo do From e70f79e577969a50754d6c7f4d51d33b1932051c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Rodr=C3=ADguez?= Date: Sat, 9 Mar 2019 17:41:25 +0100 Subject: [PATCH 04/10] Bring specs from `bundle show` Skip for now the functionality not currently supported in `bundle info`. --- spec/commands/info_spec.rb | 89 +++++++++++++++++++++++++++++++++++++- 1 file changed, 88 insertions(+), 1 deletion(-) diff --git a/spec/commands/info_spec.rb b/spec/commands/info_spec.rb index 48ed4bd528c..c771623a91f 100644 --- a/spec/commands/info_spec.rb +++ b/spec/commands/info_spec.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true RSpec.describe "bundle info" do - context "info from specific gem in gemfile" do + context "with a standard Gemfile" do before do install_gemfile <<-G source "file://#{gem_repo1}" @@ -9,6 +9,16 @@ G end + it "creates a Gemfile.lock when invoked with a gem name" do + skip "'bundle info rails' does not create a lock file automatically like 'bundle show rails' does" + + FileUtils.rm("Gemfile.lock") + + bundle "info rails" + + expect(bundled_app("Gemfile.lock")).to exist + end + it "prints information if gem exists in bundle" do bundle "info rails" expect(out).to include "* rails (2.3.2) @@ -17,6 +27,17 @@ \tPath: #{default_bundle_path("gems", "rails-2.3.2")}" end + it "prints path if gem exists in bundle" do + bundle "info rails --path" + expect(out).to eq(default_bundle_path("gems", "rails-2.3.2").to_s) + end + + it "prints the path to the running bundler" do + skip "'bundle info bundler --path' currently prints a different (incorrect) path from the old alternative 'bundle show rails'" + bundle "info bundler --path" + expect(out).to eq(root.to_s) + end + it "complains if gem not in bundle" do bundle "info missing" expect(err).to eq("Could not find gem 'missing'.") @@ -45,4 +66,70 @@ end end end + + context "with a git repo in the Gemfile" do + before :each do + @git = build_git "foo", "1.0" + end + + it "prints out git info" do + install_gemfile <<-G + gem "foo", :git => "#{lib_path("foo-1.0")}" + G + expect(the_bundle).to include_gems "foo 1.0" + + bundle "info foo" + expect(out).to include("foo (1.0 #{@git.ref_for("master", 6)}") + end + + it "prints out branch names other than master" do + update_git "foo", :branch => "omg" do |s| + s.write "lib/foo.rb", "FOO = '1.0.omg'" + end + @revision = revision_for(lib_path("foo-1.0"))[0...6] + + install_gemfile <<-G + gem "foo", :git => "#{lib_path("foo-1.0")}", :branch => "omg" + G + expect(the_bundle).to include_gems "foo 1.0.omg" + + bundle "info foo" + expect(out).to include("foo (1.0 #{@git.ref_for("omg", 6)}") + end + + it "doesn't print the branch when tied to a ref" do + sha = revision_for(lib_path("foo-1.0")) + install_gemfile <<-G + gem "foo", :git => "#{lib_path("foo-1.0")}", :ref => "#{sha}" + G + + bundle "info foo" + expect(out).to include("foo (1.0 #{sha[0..6]})") + end + + it "handles when a version is a '-' prerelease", :rubygems => "2.1" do + @git = build_git("foo", "1.0.0-beta.1", :path => lib_path("foo")) + install_gemfile <<-G + gem "foo", "1.0.0-beta.1", :git => "#{lib_path("foo")}" + G + expect(the_bundle).to include_gems "foo 1.0.0.pre.beta.1" + + bundle! "info foo" + expect(out).to include("foo (1.0.0.pre.beta.1") + end + end + + context "with an invalid regexp for gem name" do + it "does not find the gem" do + install_gemfile <<-G + source "file://#{gem_repo1}" + gem "rails" + G + + invalid_regexp = "[]" + + bundle "show #{invalid_regexp}" + expect(err).to include("Could not find gem '#{invalid_regexp}'.") + end + end end From 309729f5bfde799aad6fb985d6239633de2cb450 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Rodr=C3=ADguez?= Date: Sat, 9 Mar 2019 17:47:54 +0100 Subject: [PATCH 05/10] Make `bundle info rails` create a lock file Just like `bundle show rails` did. --- lib/bundler/cli/info.rb | 5 +++++ spec/commands/info_spec.rb | 2 -- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/bundler/cli/info.rb b/lib/bundler/cli/info.rb index 958b5250677..6fd71597aaf 100644 --- a/lib/bundler/cli/info.rb +++ b/lib/bundler/cli/info.rb @@ -9,6 +9,11 @@ def initialize(options, gem_name) end def run + Bundler.ui.silence do + Bundler.definition.validate_runtime! + Bundler.load.lock + end + spec = spec_for_gem(gem_name) spec_not_found(gem_name) unless spec diff --git a/spec/commands/info_spec.rb b/spec/commands/info_spec.rb index c771623a91f..b87249f28f9 100644 --- a/spec/commands/info_spec.rb +++ b/spec/commands/info_spec.rb @@ -10,8 +10,6 @@ end it "creates a Gemfile.lock when invoked with a gem name" do - skip "'bundle info rails' does not create a lock file automatically like 'bundle show rails' does" - FileUtils.rm("Gemfile.lock") bundle "info rails" From 5f4ed556d849a3c34b81b964556cb1b0ba1fd587 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Rodr=C3=ADguez?= Date: Sat, 9 Mar 2019 17:57:50 +0100 Subject: [PATCH 06/10] Fix `bundle info bundler` path --- lib/bundler/cli/info.rb | 8 +++++++- spec/commands/info_spec.rb | 1 - 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/bundler/cli/info.rb b/lib/bundler/cli/info.rb index 6fd71597aaf..61d4001c6f9 100644 --- a/lib/bundler/cli/info.rb +++ b/lib/bundler/cli/info.rb @@ -39,7 +39,13 @@ def spec_not_found(gem_name) end def print_gem_path(spec) - Bundler.ui.info spec.full_gem_path + path = if spec.name == "bundler" + File.expand_path("../../../..", __FILE__) + else + spec.full_gem_path + end + + Bundler.ui.info path end def print_gem_info(spec) diff --git a/spec/commands/info_spec.rb b/spec/commands/info_spec.rb index b87249f28f9..7d9e8d30944 100644 --- a/spec/commands/info_spec.rb +++ b/spec/commands/info_spec.rb @@ -31,7 +31,6 @@ end it "prints the path to the running bundler" do - skip "'bundle info bundler --path' currently prints a different (incorrect) path from the old alternative 'bundle show rails'" bundle "info bundler --path" expect(out).to eq(root.to_s) end From e4f3bbc97ef4da58e626f67207575576f217617d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Rodr=C3=ADguez?= Date: Thu, 14 Mar 2019 16:56:24 +0100 Subject: [PATCH 07/10] Add missing spec to show command --- spec/commands/show_spec.rb | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/spec/commands/show_spec.rb b/spec/commands/show_spec.rb index 8e3d0194e66..f5e1743b8ea 100644 --- a/spec/commands/show_spec.rb +++ b/spec/commands/show_spec.rb @@ -172,6 +172,19 @@ expect(out).to include("Installing foo 1.0") end + context "with a valid regexp for gem name" do + it "presents alternatives" do + install_gemfile <<-G + source "file://#{gem_repo1}" + gem "rack" + gem "rack-obama" + G + + bundle "show rac" + expect(out).to eq "1 : rack\n2 : rack-obama\n0 : - exit -\n>" + end + end + context "with an invalid regexp for gem name" do it "does not find the gem" do install_gemfile <<-G From c0c5c08066051e1d74f2d863770d481d10915b2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Rodr=C3=ADguez?= Date: Thu, 14 Mar 2019 17:23:35 +0100 Subject: [PATCH 08/10] Port regexp feature from `bundle show` --- lib/bundler/cli/info.rb | 2 +- spec/commands/info_spec.rb | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/bundler/cli/info.rb b/lib/bundler/cli/info.rb index 61d4001c6f9..4bc66932d6d 100644 --- a/lib/bundler/cli/info.rb +++ b/lib/bundler/cli/info.rb @@ -25,7 +25,7 @@ def run def spec_for_gem(gem_name) spec = Bundler.definition.specs.find {|s| s.name == gem_name } - spec || default_gem_spec(gem_name) + spec || default_gem_spec(gem_name) || Bundler::CLI::Common.select_spec(gem_name, :regex_match) end def default_gem_spec(gem_name) diff --git a/spec/commands/info_spec.rb b/spec/commands/info_spec.rb index 7d9e8d30944..ebed80f922e 100644 --- a/spec/commands/info_spec.rb +++ b/spec/commands/info_spec.rb @@ -116,6 +116,19 @@ end end + context "with a valid regexp for gem name" do + it "presents alternatives" do + install_gemfile <<-G + source "file://#{gem_repo1}" + gem "rack" + gem "rack-obama" + G + + bundle "info rac" + expect(out).to eq "1 : rack\n2 : rack-obama\n0 : - exit -\n>" + end + end + context "with an invalid regexp for gem name" do it "does not find the gem" do install_gemfile <<-G From f5358681deda96e3862c6acae942fbf993f7b3ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Rodr=C3=ADguez?= Date: Thu, 14 Mar 2019 18:47:26 +0100 Subject: [PATCH 09/10] Remove incorrect `raise` The raise is using the name of the class on its message! ``` Could not find gem 'Bundler::CLI::Common'. ``` Since we've never received a WTF report about this, I'll assume this is just dead code and remove it. --- lib/bundler/cli/common.rb | 4 ---- 1 file changed, 4 deletions(-) diff --git a/lib/bundler/cli/common.rb b/lib/bundler/cli/common.rb index f22ef6ab714..9ea52baa6b2 100644 --- a/lib/bundler/cli/common.rb +++ b/lib/bundler/cli/common.rb @@ -49,10 +49,6 @@ def self.select_spec(name, regex_match = nil) end def self.ask_for_spec_from(specs) - if !$stdout.tty? && ENV["BUNDLE_SPEC_RUN"].nil? - raise GemNotFound, gem_not_found_message(name, Bundler.definition.dependencies) - end - specs.each_with_index do |spec, index| Bundler.ui.info "#{index.succ} : #{spec.name}", true end From 83d22e7deaf5c3347db4961a397a6a929ed66b73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Rodr=C3=ADguez?= Date: Thu, 14 Mar 2019 18:50:31 +0100 Subject: [PATCH 10/10] Don't raise if users choose to exit Just exit. --- lib/bundler/cli/info.rb | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/bundler/cli/info.rb b/lib/bundler/cli/info.rb index 4bc66932d6d..4733675e8cf 100644 --- a/lib/bundler/cli/info.rb +++ b/lib/bundler/cli/info.rb @@ -16,9 +16,10 @@ def run spec = spec_for_gem(gem_name) - spec_not_found(gem_name) unless spec - return print_gem_path(spec) if @options[:path] - print_gem_info(spec) + if spec + return print_gem_path(spec) if @options[:path] + print_gem_info(spec) + end end private