diff options
-rw-r--r-- | lib/bundler/cli/info.rb | 28 | ||||
-rw-r--r-- | spec/commands/info_spec.rb | 4 |
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 |