diff options
author | Andre Arko <andre@arko.net> | 2016-06-06 23:02:31 -0700 |
---|---|---|
committer | Samuel Giddins <segiddins@segiddins.me> | 2016-07-10 12:07:57 -0300 |
commit | 7b4277831e73b49e9b6c3262e73ff8f0a1f8fb9d (patch) | |
tree | 8b8948abd2763578a5fd15a04fe0787058a0581c | |
parent | a4169b08b22af64cccb84fb0f6f96c13b8a69c6c (diff) | |
download | bundler-7b4277831e73b49e9b6c3262e73ff8f0a1f8fb9d.tar.gz |
respect required_ruby_versions when present
Not only does this test mean that we’re sure the method works, I like
how the method is structured now a lot better too :grin:
-rw-r--r-- | lib/bundler/resolver.rb | 13 | ||||
-rw-r--r-- | spec/install/gems/resolving_spec.rb | 45 |
2 files changed, 38 insertions, 20 deletions
diff --git a/lib/bundler/resolver.rb b/lib/bundler/resolver.rb index e1df04efb1..50a391e592 100644 --- a/lib/bundler/resolver.rb +++ b/lib/bundler/resolver.rb @@ -122,14 +122,11 @@ module Bundler @source ||= first.source end - def for?(platform, required_ruby_version) - if spec = @specs[platform] - if required_ruby_version && spec.respond_to?(:required_ruby_version) && spec_required_ruby_version = spec.required_ruby_version - spec_required_ruby_version.satisfied_by?(required_ruby_version.to_gem_version_with_patchlevel) - else - true - end - end + def for?(platform, ruby_version) + spec = @specs[platform] + return false unless spec + return true if ruby_version.nil? || !spec.is_a?(EndpointSpecification) + spec.required_ruby_version.satisfied_by?(ruby_version.to_gem_version_with_patchlevel) end def to_s diff --git a/spec/install/gems/resolving_spec.rb b/spec/install/gems/resolving_spec.rb index 74acf9a918..87e747d9e2 100644 --- a/spec/install/gems/resolving_spec.rb +++ b/spec/install/gems/resolving_spec.rb @@ -103,25 +103,46 @@ describe "bundle install with gem sources" do end end - describe "when some gems require a different version of ruby" do - it "does not try to install those gems" do - update_repo gem_repo1 do - build_gem "require_ruby" do |s| - s.required_ruby_version = "> 9000" + describe "when a required ruby version" do + context "allows only an older version" do + it "installs the older version" do + update_repo gem_repo1 do + build_gem "rack", "9001.0.0" do |s| + s.required_ruby_version = "> 9000" + end end + + install_gemfile <<-G, :artifice => "compact_index" + ruby "#{RUBY_VERSION}" + source "file://#{gem_repo1}" + gem 'rack' + G + + expect(out).to_not include("rack-9001.0.0 requires ruby version > 9000") + should_be_installed("rack 1.0") end + end - install_gemfile <<-G, :artifice => "compact_index" - source "file://#{gem_repo1}" - gem 'require_ruby' - G + context "allows no gems" do + it "does not try to install those gems" do + update_repo gem_repo1 do + build_gem "require_ruby" do |s| + s.required_ruby_version = "> 9000" + end + end - expect(out).to_not include("Gem::InstallError: require_ruby requires Ruby version > 9000") - expect(out).to include("require_ruby-1.0 requires ruby version > 9000, which is incompatible with the current version, #{Bundler::RubyVersion.system}") + install_gemfile <<-G, :artifice => "compact_index" + source "file://#{gem_repo1}" + gem 'require_ruby' + G + + expect(out).to_not include("Gem::InstallError: require_ruby requires Ruby version > 9000") + expect(out).to include("require_ruby-1.0 requires ruby version > 9000, which is incompatible with the current version, #{Bundler::RubyVersion.system}") + end end end - describe "when some gems require a different version of rubygems" do + describe "when a required rubygems version disallows a gem" do it "does not try to install those gems" do update_repo gem_repo1 do build_gem "require_rubygems" do |s| |