Skip to content

Commit

Permalink
- gem dep can fetch remote dependencies for non-latest gems again.
Browse files Browse the repository at this point in the history
+ Added Gem::Requirement#specific? and Gem::Dependency#specific?
  • Loading branch information
drbrain committed May 5, 2011
1 parent 38b817f commit 89fd0e3
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/rubygems/commands/dependency_command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ def execute
fetcher = Gem::SpecFetcher.fetcher

# REFACTOR: fetcher.find_specs_matching => specs
specs_and_sources = fetcher.find_matching(dependency, false, true,
specs_and_sources = fetcher.find_matching(dependency,
dependency.specific?, true,
dependency.prerelease?)

specs.concat specs_and_sources.map { |spec_tuple, source_uri|
Expand Down
7 changes: 7 additions & 0 deletions lib/rubygems/dependency.rb
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,13 @@ def matching_specs platform_only = false
matches = matches.sort_by { |s| s.sort_obj } # HACK: shouldn't be needed
end

##
# True if the dependency will not always match the latest version.

def specific?
@requirement.specific?
end

def to_specs
matches = matching_specs true

Expand Down
9 changes: 9 additions & 0 deletions lib/rubygems/requirement.rb
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,15 @@ def satisfied_by? version
alias :=== :satisfied_by?
alias :=~ :satisfied_by?

##
# True if the requirement will not always match the latest version.

def specific?
return true if @requirements.length > 1 # GIGO, > 1, > 2 is silly

not %w[> >=].include? @requirements.first.first # grab the operator
end

def to_s # :nodoc:
as_list.join ", "
end
Expand Down
18 changes: 18 additions & 0 deletions test/rubygems/test_gem_commands_dependency_command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,24 @@ def test_execute_remote
assert_equal '', @ui.error
end

def test_execute_remote_version
@fetcher = Gem::FakeFetcher.new
Gem::RemoteFetcher.fetcher = @fetcher

util_setup_spec_fetcher @a1, @a2

@cmd.options[:args] = %w[a]
@cmd.options[:domain] = :remote
@cmd.options[:version] = req '= 1'

use_ui @ui do
@cmd.execute
end

assert_equal "Gem a-1\n\n", @ui.output
assert_equal '', @ui.error
end

def test_execute_prerelease
@fetcher = Gem::FakeFetcher.new
Gem::RemoteFetcher.fetcher = @fetcher
Expand Down
7 changes: 7 additions & 0 deletions test/rubygems/test_gem_dependency.rb
Original file line number Diff line number Diff line change
Expand Up @@ -166,5 +166,12 @@ def test_prerelease_eh

assert d.prerelease?
end

def test_specific
refute dep('a', '> 1').specific?

assert dep('a', '= 1').specific?
end

end

13 changes: 13 additions & 0 deletions test/rubygems/test_gem_requirement.rb
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,19 @@ def test_satisfied_by_boxed
refute_satisfied_by "2.0", "~> 1.4.4"
end

def test_specific
refute req('> 1') .specific?
refute req('>= 1').specific?

assert req('!= 1').specific?
assert req('< 1') .specific?
assert req('<= 1').specific?
assert req('= 1') .specific?
assert req('~> 1').specific?

assert req('> 1', '> 2').specific? # GIGO
end

def test_bad
refute_satisfied_by "", "> 0.1"
refute_satisfied_by "1.2.3", "!= 1.2.3"
Expand Down

0 comments on commit 89fd0e3

Please sign in to comment.