From d8a4f95841f267d5ece05bfde41e8c2e172a9a2c Mon Sep 17 00:00:00 2001 From: Christopher Patuzzo Date: Mon, 7 May 2012 20:12:58 +0100 Subject: [PATCH] Add a new option: --all-versions --- lib/rubygems/commands/dependent_command.rb | 4 ++++ lib/rubygems/dependent.rb | 6 +++--- spec/dependent_spec.rb | 12 ++++++++++-- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/lib/rubygems/commands/dependent_command.rb b/lib/rubygems/commands/dependent_command.rb index 7f1b0ad..d8225a5 100644 --- a/lib/rubygems/commands/dependent_command.rb +++ b/lib/rubygems/commands/dependent_command.rb @@ -19,6 +19,10 @@ def initialize add_option('--parallel N', Integer, 'Make N requests in parallel') do |n, _| options[:parallel] = n end + + add_option('--all-versions', 'Check against all versions of gems') do + options[:all_versions] = true + end end def arguments diff --git a/lib/rubygems/dependent.rb b/lib/rubygems/dependent.rb index 4d7e7cb..80eea50 100644 --- a/lib/rubygems/dependent.rb +++ b/lib/rubygems/dependent.rb @@ -8,7 +8,7 @@ class Dependent def self.find(gem, options={}) # get all gems specs_and_sources = with_changed_gem_source(options[:source]) do - all_specs_and_sources + all_specs_and_sources(options[:all_versions]) end if options[:fetch_limit] @@ -62,14 +62,14 @@ def self.print_dot $stderr.flush if rand(20) == 0 # make progress visible end - def self.all_specs_and_sources + def self.all_specs_and_sources(all_versions = false) fetcher = Gem::SpecFetcher.fetcher all = true matching_platform = false prerelease = false matcher = Gem::Dependency.new(//, Gem::Requirement.default) # any name, any version specs_and_sources = fetcher.find_matching matcher, all, matching_platform, prerelease - uniq_by(specs_and_sources){|a| a.first.first } + all_versions ? specs_and_sources : uniq_by(specs_and_sources){|a| a.first.first } end # get unique elements from an array (last found is used) diff --git a/spec/dependent_spec.rb b/spec/dependent_spec.rb index f97cdde..aad19a1 100644 --- a/spec/dependent_spec.rb +++ b/spec/dependent_spec.rb @@ -27,9 +27,11 @@ def simplify(dependencies) dependencies.map{|name, deps| [name, deps.map{|d| d.name}] } end - def stub_source(gem_source = nil) + def stub_source(gem_source = nil, check_against_fixtures = true) gem_source ||= 'http://gemcutter.org' - Gem::SpecFetcher.fetcher.should_receive(:load_specs).with(URI.parse(gem_source), 'specs').and_return(fixture) + if check_against_fixtures + Gem::SpecFetcher.fetcher.should_receive(:load_specs).with(URI.parse(gem_source), 'specs').and_return(fixture) + end Gem.sources = [gem_source] end @@ -57,6 +59,12 @@ def stub_source(gem_source = nil) Gem::Dependent.find('hoe', :parallel => 3) end + it "obeys all versions option" do + stub_source(nil, false) + Gem::Dependent.should_receive(:all_specs_and_sources).with(true) + Gem::Dependent.find('hoe', :all_versions => true) + end + it "has a VERSION" do Gem::Dependent::VERSION.should =~ /^\d+\.\d+\.\d+$/ end