Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

pass meaningfull options instead of flags

  • Loading branch information...
commit 03770e4aa77b9fc6b4c14b09dedd0b3f42e4adb5 1 parent 5f3ad21
Michael Grosser authored
4 lib/rubygems/commands/dependent_command.rb
@@ -44,7 +44,7 @@ def execute
44 44 requirements = dependencies.map do |dependency|
45 45 formatted_dependency(dependency)
46 46 end.join(', ')
47   - version = options[:all_versions] ? " (v#{version})" : nil
  47 + version = (options[:all_versions] ? " (v#{version})" : "")
48 48 puts "#{gem}#{version} #{requirements}"
49 49 end
50 50 rescue Object => e
@@ -58,4 +58,4 @@ def formatted_dependency(dependency)
58 58 type = " (#{dependency.type})" if dependency.type == :development
59 59 "#{dependency.requirement}#{type}"
60 60 end
61   -end
  61 +end
11 lib/rubygems/dependent.rb
@@ -7,7 +7,7 @@ class Dependent
7 7 def self.find(gem, options={})
8 8 # get all gems
9 9 specs_and_sources = with_changed_gem_source(options[:source]) do
10   - all_specs_and_sources(options[:all_versions])
  10 + all_specs_and_sources(:all_versions => options[:all_versions])
11 11 end
12 12
13 13 if options[:fetch_limit]
@@ -61,14 +61,19 @@ def self.print_dot
61 61 $stderr.flush if rand(20) == 0 # make progress visible
62 62 end
63 63
64   - def self.all_specs_and_sources(all_versions = false)
  64 + def self.all_specs_and_sources(options={})
65 65 fetcher = Gem::SpecFetcher.fetcher
66 66 all = true
67 67 matching_platform = false
68 68 prerelease = false
69 69 matcher = Gem::Dependency.new(//, Gem::Requirement.default) # any name, any version
70 70 specs_and_sources = fetcher.find_matching matcher, all, matching_platform, prerelease
71   - all_versions ? specs_and_sources : uniq_by(specs_and_sources){|a| a.first.first }
  71 +
  72 + if options[:all_versions]
  73 + specs_and_sources
  74 + else
  75 + uniq_by(specs_and_sources){|a| a.first.first }
  76 + end
72 77 end
73 78
74 79 # get unique elements from an array (last found is used)
18 spec/dependent_spec.rb
@@ -23,13 +23,13 @@
23 23 ]
24 24 }
25 25
26   - def simplify(dependencies)
  26 + def simplify_gem_results(dependencies)
27 27 dependencies.map{|name, version, deps| [name, deps.map{|d| d.name}] }
28 28 end
29 29
30   - def stub_source(gem_source = nil, check_against_fixtures = true)
31   - gem_source ||= 'http://gemcutter.org'
32   - if check_against_fixtures
  30 + def stub_source(options={})
  31 + gem_source = options[:source] || 'http://gemcutter.org'
  32 + if !options[:live]
33 33 Gem::SpecFetcher.fetcher.should_receive(:load_specs).with(URI.parse(gem_source), 'specs').and_return(fixture)
34 34 end
35 35 Gem.sources = [gem_source]
@@ -37,19 +37,19 @@ def stub_source(gem_source = nil, check_against_fixtures = true)
37 37
38 38 it 'finds dependencies for given gem' do
39 39 stub_source
40   - dependencies = simplify(Gem::Dependent.find('hoe'))
  40 + dependencies = simplify_gem_results(Gem::Dependent.find('hoe'))
41 41 dependencies.should == hoe_gems
42 42 end
43 43
44 44 it "obeys fetch-limit" do
45 45 stub_source
46   - dependencies = simplify(Gem::Dependent.find('hoe', :fetch_limit => 100))
  46 + dependencies = simplify_gem_results(Gem::Dependent.find('hoe', :fetch_limit => 100))
47 47 dependencies.should == hoe_gems.first(3)
48 48 end
49 49
50 50 it "can use given source" do
51 51 source = 'http://rubygems.org'
52   - stub_source(source)
  52 + stub_source(:source => source)
53 53 Gem::Dependent.find('hoe', :source => source)
54 54 end
55 55
@@ -60,8 +60,8 @@ def stub_source(gem_source = nil, check_against_fixtures = true)
60 60 end
61 61
62 62 it "obeys all versions option" do
63   - stub_source(nil, false)
64   - Gem::Dependent.should_receive(:all_specs_and_sources).with(true)
  63 + stub_source :live => true
  64 + Gem::Dependent.should_receive(:all_specs_and_sources).with(:all_versions => true)
65 65 Gem::Dependent.find('hoe', :all_versions => true)
66 66 end
67 67

0 comments on commit 03770e4

Please sign in to comment.
Something went wrong with that request. Please try again.