summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorColby Swandale <colby@taplaboratories.com>2017-02-19 12:44:49 +1100
committerColby Swandale <colby@taplaboratories.com>2017-02-19 12:44:49 +1100
commitb1b9557046a8eccaf16e842e6eb53aba7be48ab4 (patch)
treea4ac5487dae511ccd2e8ef918f559a92f4b9224e
parent1f5e97cdfeee1ca1578b2b42dca41bfa10363be6 (diff)
downloadbundler-b1b9557046a8eccaf16e842e6eb53aba7be48ab4.tar.gz
cleanup and add output for default gem
-rw-r--r--lib/bundler/cli/info.rb28
-rw-r--r--spec/commands/info_spec.rb4
2 files changed, 21 insertions, 11 deletions
diff --git a/lib/bundler/cli/info.rb b/lib/bundler/cli/info.rb
index 20a682fe48..250a16abb2 100644
--- a/lib/bundler/cli/info.rb
+++ b/lib/bundler/cli/info.rb
@@ -10,21 +10,30 @@ module Bundler
end
def run
- begin
- gem = Gem::Specification.find_by_name(gem_name)
- spec = gem if gem.default_gem?
- rescue Gem::MissingSpecError
- nil
- end
-
- spec ||= Bundler::CLI::Common.select_spec(gem_name, :regex_match)
- return unless spec
+ 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)
end
private
+ def spec_for_gem(gem_name)
+ spec = Bundler.definition.specs.find { |s| s.name == gem_name }
+ spec ||= default_gem_spec(gem_name)
+ end
+
+ def default_gem_spec(gem_name)
+ return nil unless Gem::Specification.respond_to?(:find_all_by_name)
+ gem_spec = Gem::Specification.find_all_by_name(gem_name).last
+ return gem_spec if gem_spec && gem_spec.default_gem?
+ end
+
+ def spec_not_found(gem_name)
+ raise GemNotFound, Bundler::CLI::Common.gem_not_found_message(gem_name, Bundler.definition.dependencies)
+ end
+
def print_gem_path(spec)
Bundler.ui.info spec.full_gem_path
end
@@ -35,6 +44,7 @@ module Bundler
gem_info << "\tSummary: #{spec.summary}\n" if spec.summary
gem_info << "\tHomepage: #{spec.homepage}\n" if spec.homepage
gem_info << "\tPath: #{spec.full_gem_path}\n"
+ gem_info << "\tDefault Gem: yes" if spec.respond_to?(:default_gem?) && spec.default_gem?
Bundler.ui.info gem_info
end
end
diff --git a/spec/commands/info_spec.rb b/spec/commands/info_spec.rb
index b4ff08b277..9c12868f47 100644
--- a/spec/commands/info_spec.rb
+++ b/spec/commands/info_spec.rb
@@ -26,10 +26,10 @@ RSpec.describe "bundle info" do
end
context "given a default gem shippped in ruby" do
- it "prints information about the default gem" do
+ it "prints information about the default gem", :if => (RUBY_VERSION >= "1.9") do
bundle "info rdoc"
expect(out).to include("* rdoc")
- expect(out).to match(%r{gems\/rdoc\-})
+ expect(out).to include("Default Gem: yes")
end
end