diff options
author | Joseph Smith <joseph@opscode.com> | 2013-06-17 16:00:28 -0700 |
---|---|---|
committer | Joseph Smith <joseph@opscode.com> | 2013-06-17 16:00:28 -0700 |
commit | 3f0c2a79b18b11b173b3731cdfb4f213d2308ce1 (patch) | |
tree | 0dd295a2ce772e4468431898bdc630c10d0f7f2b | |
parent | 238751bee5363b472f65f729df938d6b1f8b0d2c (diff) | |
download | chef-10-stable-mixlib-shellout-test.tar.gz |
travis fixes for 1010-stable-mixlib-shellout-test
-rw-r--r-- | chef/lib/chef/provider/package/rubygems.rb | 2 | ||||
-rw-r--r-- | chef/spec/unit/provider/package/rubygems_spec.rb | 31 |
2 files changed, 32 insertions, 1 deletions
diff --git a/chef/lib/chef/provider/package/rubygems.rb b/chef/lib/chef/provider/package/rubygems.rb index b451450a8c..bdba72b733 100644 --- a/chef/lib/chef/provider/package/rubygems.rb +++ b/chef/lib/chef/provider/package/rubygems.rb @@ -121,7 +121,7 @@ class Chef # Compatibility note: Rubygems 1.x uses Gem::Format, 2.0 moved this # code into Gem::Package. def spec_from_file(file) - if defined?(Gem::Format) + if defined?(Gem::Format) and Gem::Package.respond_to?(:open) Gem::Format.from_file_by_path(file).spec else Gem::Package.new(file).spec diff --git a/chef/spec/unit/provider/package/rubygems_spec.rb b/chef/spec/unit/provider/package/rubygems_spec.rb index d883a7f882..7f41eb4cef 100644 --- a/chef/spec/unit/provider/package/rubygems_spec.rb +++ b/chef/spec/unit/provider/package/rubygems_spec.rb @@ -106,6 +106,37 @@ describe Chef::Provider::Package::Rubygems::CurrentGemEnvironment do 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 + + context "when rubygems was upgraded from 1.8->2.0" do + # https://github.com/rubygems/rubygems/issues/404 + # tl;dr rubygems 1.8 and 2.0 can both be in the load path, which means that + # require "rubygems/format" will load even though rubygems 2.0 doesn't have + # that file. + + before do + if defined?(Gem::Format) + # tests are running under rubygems 1.8, or 2.0 upgraded from 1.8 + @remove_gem_format = false + else + Gem.const_set(:Format, Object.new) + @remove_gem_format = true + end + Gem::Package.stub!(:respond_to?).with(:open).and_return(false) + end + + after do + if @remove_gem_format + Gem.send(:remove_const, :Format) + end + end + + it "finds a matching gem candidate version on rubygems 2.0+ with some rubygems 1.8 code loaded" do + package = mock("Gem::Package", :spec => "a gemspec from package") + Gem::Package.should_receive(:new).with("/path/to/package.gem").and_return(package) + @gem_env.spec_from_file("/path/to/package.gem").should == "a gemspec from package" + end + + end context "when rubygems was upgraded from 1.8->2.0" do # https://github.com/rubygems/rubygems/issues/404 |