diff options
author | Andre Arko <andre@arko.net> | 2014-04-13 14:05:56 -0700 |
---|---|---|
committer | Andre Arko <andre@arko.net> | 2014-04-13 14:07:03 -0700 |
commit | 1ed2c909489927cc1e80e68196709d9e86a5a3eb (patch) | |
tree | 0e5a9a9a09d51e7c8b4fec98cb736127bf2c3248 | |
parent | 112c3f418d95a9e876792e0e62bc886e44e65e55 (diff) | |
download | bundler-1ed2c909489927cc1e80e68196709d9e86a5a3eb.tar.gz |
cache gems even if they are ruby builtins
-rw-r--r-- | lib/bundler/source/rubygems.rb | 19 | ||||
-rw-r--r-- | spec/cache/gems_spec.rb | 39 |
2 files changed, 29 insertions, 29 deletions
diff --git a/lib/bundler/source/rubygems.rb b/lib/bundler/source/rubygems.rb index 59cea2261b..2ee605fa94 100644 --- a/lib/bundler/source/rubygems.rb +++ b/lib/bundler/source/rubygems.rb @@ -70,8 +70,7 @@ module Bundler # Download the gem to get the spec, because some specs that are returned # by rubygems.org are broken and wrong. if spec.source_uri - path = Fetcher.download_gem_from_uri(spec, spec.source_uri) - s = Bundler.rubygems.spec_from_gem(path, Bundler.settings["trust-policy"]) + s = Bundler.rubygems.spec_from_gem(fetch_gem(spec), Bundler.settings["trust-policy"]) spec.__swap__(s) end @@ -126,11 +125,12 @@ module Bundler end def cache(spec, custom_path = nil) - # Gems bundled with Ruby don't have .gem files cached locally, but it doesn't matter - # since they're always going to be installed on this Ruby version. - return if builtin_gem?(spec) - - cached_path = cached_gem(spec) + if builtin_gem?(spec) + remote_spec = remote_specs.search(spec).first + cached_path = fetch_gem(remote_spec) + else + cached_path = cached_gem(spec) + end raise GemNotFound, "Missing gem file '#{spec.full_name}.gem'." unless cached_path return if File.dirname(cached_path) == Bundler.app_cache.to_s Bundler.ui.info " * #{File.basename(cached_path)}" @@ -289,6 +289,11 @@ module Bundler end end + def fetch_gem(spec) + return false unless spec.source_uri + Fetcher.download_gem_from_uri(spec, spec.source_uri) + end + def builtin_gem?(spec) # Ruby 2.1, where all included gems have this summary return true if spec.summary =~ /is bundled with Ruby/ diff --git a/spec/cache/gems_spec.rb b/spec/cache/gems_spec.rb index 9b6c3979af..3ba98b7730 100644 --- a/spec/cache/gems_spec.rb +++ b/spec/cache/gems_spec.rb @@ -74,39 +74,34 @@ describe "bundle cache" do end end - describe "when there is a built-in gem" do - let(:version) { "1.0.0" } - + describe "when there is a built-in gem", :ruby => "2.0" do before :each do build_repo2 do - build_gem "builtin_gem", version do |s| - s.summary = "This builtin_gem is bundled with Ruby" - end - - build_gem "remote_gem", version do |s| - s.summary = "Totally normal gem" - end + build_gem "builtin_gem", "1.0.2" end - build_gem "builtin_gem", version, :to_system => true do |s| + build_gem "builtin_gem", "1.0.2", :to_system => true do |s| s.summary = "This builtin_gem is bundled with Ruby" end - install_gemfile <<-G - source "file://#{gem_repo2}" - gem 'builtin_gem', '#{version}' - gem 'remote_gem', '#{version}' - G + FileUtils.rm("#{system_gem_path}/cache/builtin_gem-1.0.2.gem") + end - FileUtils.rm("#{system_gem_path}/cache/builtin_gem-#{version}.gem") + it "uses builtin gems" do + install_gemfile %|gem 'builtin_gem', '1.0.2'| + should_be_installed("builtin_gem 1.0.2") end - it "caches normal gems successfully" do - bundle :cache, :exitstatus => true + it "caches remote and builtin gems" do + install_gemfile <<-G + source "file://#{gem_repo2}" + gem 'builtin_gem', '1.0.2' + gem 'rack', '1.0.0' + G - expect(exitstatus).to be_zero - expect(bundled_app("vendor/cache/builtin_gem-#{version}.gem")).to_not exist - expect(bundled_app("vendor/cache/remote_gem-#{version}.gem")).to exist + bundle :cache + expect(bundled_app("vendor/cache/rack-1.0.0.gem")).to exist + expect(bundled_app("vendor/cache/builtin_gem-1.0.2.gem")).to exist end end |