diff options
author | danielsdeleo <dan@opscode.com> | 2013-02-24 13:28:16 -0800 |
---|---|---|
committer | Bryan McLellan <btm@opscode.com> | 2013-05-30 09:18:48 -0700 |
commit | 4a503042e37fe17e50c937fb501dd31ccec5d2b1 (patch) | |
tree | a658371d70a7a425c876800863d69dcc4bc9e1ac | |
parent | 604a563e8000e0c5af51bc61f1997c8987dc46aa (diff) | |
download | chef-4a503042e37fe17e50c937fb501dd31ccec5d2b1.tar.gz |
[CHEF-3933] support new gem dependency installer return type
in rubygems commit 432fc4818bbf14dfa5e49bbc1950eaa6d3fde133, return type
of dependency_installer's #find_gems_with_sources is changed to return a
Gem::AvailableSet collection instead of an ordered Array.
-rw-r--r-- | chef/lib/chef/provider/package/rubygems.rb | 21 | ||||
-rw-r--r-- | chef/spec/unit/provider/package/rubygems_spec.rb | 12 |
2 files changed, 27 insertions, 6 deletions
diff --git a/chef/lib/chef/provider/package/rubygems.rb b/chef/lib/chef/provider/package/rubygems.rb index 2a778fdb14..5b47532597 100644 --- a/chef/lib/chef/provider/package/rubygems.rb +++ b/chef/lib/chef/provider/package/rubygems.rb @@ -165,14 +165,23 @@ class Chef # Find the newest gem version available from Gem.sources that satisfies # the constraints of +gem_dependency+ def find_newest_remote_version(gem_dependency, *sources) - # DependencyInstaller sorts the results such that the last one is - # always the one it considers best. - spec_with_source = dependency_installer.find_gems_with_sources(gem_dependency).last + available_gems = dependency_installer.find_gems_with_sources(gem_dependency) + spec, source = if available_gems.respond_to?(:last) + # DependencyInstaller sorts the results such that the last one is + # always the one it considers best. + spec_with_source = available_gems.last + spec_with_source && spec_with_source + else + # Rubygems 2.0 returns a Gem::Available set, which is a + # collection of AvailableSet::Tuple structs + available_gems.pick_best! + best_gem = available_gems.set.first + best_gem && [best_gem.spec, best_gem.source] + end - spec = spec_with_source && spec_with_source[0] - version = spec && spec_with_source[0].version + version = spec && spec.version if version - logger.debug { "#{@new_resource} found gem #{spec.name} version #{version} for platform #{spec.platform} from #{spec_with_source[1]}" } + logger.debug { "#{@new_resource} found gem #{spec.name} version #{version} for platform #{spec.platform} from #{source}" } version else source_list = sources.compact.empty? ? "[#{Gem.sources.to_a.join(', ')}]" : "[#{sources.join(', ')}]" diff --git a/chef/spec/unit/provider/package/rubygems_spec.rb b/chef/spec/unit/provider/package/rubygems_spec.rb index b3b7a030db..d7941af76d 100644 --- a/chef/spec/unit/provider/package/rubygems_spec.rb +++ b/chef/spec/unit/provider/package/rubygems_spec.rb @@ -95,6 +95,18 @@ describe Chef::Provider::Package::Rubygems::CurrentGemEnvironment do @gem_env.candidate_version_from_remote(Gem::Dependency.new('rspec', '>= 0')).should == Gem::Version.new('1.3.0') end + it "finds a matching gem candidate version on rubygems 2.0.0+" do + dep = Gem::Dependency.new('rspec', '>= 0') + dep_installer = Gem::DependencyInstaller.new + @gem_env.stub!(:dependency_installer).and_return(dep_installer) + best_gem = mock("best gem match", :spec => gemspec("rspec", Gem::Version.new("1.3.0")), :source => "https://rubygems.org") + available_set = mock("Gem::AvailableSet test double") + available_set.should_receive(:pick_best!) + available_set.should_receive(:set).and_return([best_gem]) + dep_installer.should_receive(:find_gems_with_sources).with(dep).and_return(available_set) + @gem_env.candidate_version_from_remote(Gem::Dependency.new('rspec', '>= 0')).should == Gem::Version.new('1.3.0') + end + it "gives the candidate version as nil if none is found" do dep = Gem::Dependency.new('rspec', '>= 0') latest = [] |