diff options
author | Homu <homu@barosl.com> | 2016-06-11 05:29:09 +0900 |
---|---|---|
committer | Homu <homu@barosl.com> | 2016-06-11 05:29:09 +0900 |
commit | 6ebda982776d2c8ae0f38401fbaab47a231d75e1 (patch) | |
tree | b2e353407d1ed68eb1ab2f5f02433105da3f5a0d | |
parent | 4b57850495e49a0305e738ee09b499d163f1ffa1 (diff) | |
parent | 4f8a41a3e8aaf0697c9b1d57cceee26df212841e (diff) | |
download | bundler-6ebda982776d2c8ae0f38401fbaab47a231d75e1.tar.gz |
Auto merge of #4603 - bundler:seg-allow-unlocking-when-removing-ruby, r=indirect
[Definition] Allow unlocking when removing the ruby version requirement
Closes #4595. Closes #4627.
\c @RochesterinNYC
-rw-r--r-- | lib/bundler/definition.rb | 8 | ||||
-rw-r--r-- | lib/bundler/ruby_version.rb | 24 | ||||
-rw-r--r-- | spec/bundler/ruby_version_spec.rb | 34 | ||||
-rw-r--r-- | spec/commands/install_spec.rb | 4 | ||||
-rw-r--r-- | spec/install/gemfile/ruby_spec.rb | 64 | ||||
-rw-r--r-- | spec/other/platform_spec.rb | 4 | ||||
-rw-r--r-- | spec/runtime/setup_spec.rb | 2 | ||||
-rw-r--r-- | spec/support/helpers.rb | 9 |
8 files changed, 141 insertions, 8 deletions
diff --git a/lib/bundler/definition.rb b/lib/bundler/definition.rb index 02f8ee0957..d4af6b70e7 100644 --- a/lib/bundler/definition.rb +++ b/lib/bundler/definition.rb @@ -85,6 +85,14 @@ module Bundler @unlock[:gems] ||= [] @unlock[:sources] ||= [] + @unlock[:ruby] ||= if @ruby_version && @locked_ruby_version + unless locked_ruby_version_object = RubyVersion.from_string(@locked_ruby_version) + raise LockfileError, "Failed to create a `RubyVersion` object from " \ + "`#{@locked_ruby_version}` found in #{lockfile} -- try running `bundle update --ruby`." + end + @ruby_version.diff(locked_ruby_version_object) + end + @unlocking ||= @unlock[:ruby] || (!@locked_ruby_version ^ !@ruby_version) current_platform = Bundler.rubygems.platforms.map {|p| generic(p) }.compact.last add_platform(current_platform) diff --git a/lib/bundler/ruby_version.rb b/lib/bundler/ruby_version.rb index 5936eca830..d0e9c50af2 100644 --- a/lib/bundler/ruby_version.rb +++ b/lib/bundler/ruby_version.rb @@ -38,6 +38,22 @@ module Bundler output end + # @private + PATTERN = / + ruby\s + ([\d.]+) # ruby version + (?:p(\d+))? # optional patchlevel + (?:\s\((\S+)\s(.+)\))? # optional engine info + /xo + + # Returns a RubyVersion from the given string. + # @param [String] the version string to match. + # @return [RubyVersion,Nil] The version if the string is a valid RubyVersion + # description, and nil otherwise. + def self.from_string(string) + new($1, $2, $3, $4) if string =~ PATTERN + end + def single_version_string to_s(gem_version) end @@ -64,7 +80,7 @@ module Bundler # 2. ruby_version # 3. engine_version def diff(other) - raise ArgumentError, "Can only diff with a RubyVersion" unless other.is_a?(RubyVersion) + raise ArgumentError, "Can only diff with a RubyVersion, not a #{other.class}" unless other.is_a?(RubyVersion) if engine != other.engine && @input_engine [:engine, engine, other.engine] elsif versions.empty? || !matches?(versions, other.gem_version) @@ -87,9 +103,11 @@ module Bundler # not defined in ruby 1.8.7 "ruby" end + # :sob: mocking RUBY_VERSION breaks stuff on 1.8.7 + ruby_version = ENV.fetch("BUNDLER_SPEC_RUBY_VERSION") { RUBY_VERSION }.dup ruby_engine_version = case ruby_engine when "ruby" - RUBY_VERSION.dup + ruby_version when "rbx" Rubinius::VERSION.dup when "jruby" @@ -97,7 +115,7 @@ module Bundler else raise BundlerError, "RUBY_ENGINE value #{RUBY_ENGINE} is not recognized" end - @ruby_version ||= RubyVersion.new(RUBY_VERSION.dup, RUBY_PATCHLEVEL.to_s, ruby_engine, ruby_engine_version) + @ruby_version ||= RubyVersion.new(ruby_version, RUBY_PATCHLEVEL.to_s, ruby_engine, ruby_engine_version) end def to_gem_version_with_patchlevel diff --git a/spec/bundler/ruby_version_spec.rb b/spec/bundler/ruby_version_spec.rb index 414ec3c3c8..abcd0303d0 100644 --- a/spec/bundler/ruby_version_spec.rb +++ b/spec/bundler/ruby_version_spec.rb @@ -56,6 +56,40 @@ describe "Bundler::RubyVersion and its subclasses" do end end end + + describe ".from_string" do + shared_examples_for "returning" do + it "returns the original RubyVersion" do + expect(described_class.from_string(subject.to_s)).to eq(subject) + end + end + + include_examples "returning" + + context "no patchlevel" do + let(:patchlevel) { nil } + + include_examples "returning" + end + + context "engine is ruby" do + let(:engine) { "ruby" } + let(:engine_version) { version } + + include_examples "returning" + end + + context "with multiple requirements" do + let(:engine_version) { ["> 9", "< 11"] } + let(:version) { ["> 8", "< 10"] } + let(:patchlevel) { nil } + + it "returns nil" do + expect(described_class.from_string(subject.to_s)).to be_nil + end + end + end + describe "#to_s" do it "should return info string with the ruby version, patchlevel, engine, and engine version" do expect(subject.to_s).to eq("ruby 2.0.0p645 (jruby 2.0.1)") diff --git a/spec/commands/install_spec.rb b/spec/commands/install_spec.rb index efefdbef4f..d7617cb370 100644 --- a/spec/commands/install_spec.rb +++ b/spec/commands/install_spec.rb @@ -391,7 +391,7 @@ describe "bundle install with gem sources" do L end - it "does not update Gemfile.lock with updated ruby versions" do + it "updates Gemfile.lock with updated incompatible ruby version" do install_gemfile <<-G, :expect_err => true ::RUBY_VERSION = '2.2.3' ::RUBY_PATCHLEVEL = 100 @@ -408,7 +408,7 @@ describe "bundle install with gem sources" do DEPENDENCIES RUBY VERSION - ruby 2.1.3p100 + ruby 2.2.3p100 BUNDLED WITH #{Bundler::VERSION} diff --git a/spec/install/gemfile/ruby_spec.rb b/spec/install/gemfile/ruby_spec.rb index d3536289eb..d250e78693 100644 --- a/spec/install/gemfile/ruby_spec.rb +++ b/spec/install/gemfile/ruby_spec.rb @@ -2,6 +2,10 @@ require "spec_helper" describe "ruby requirement" do + def locked_ruby_version + Bundler::RubyVersion.from_string(Bundler::LockfileParser.new(lockfile).ruby_version) + end + # As discovered by https://github.com/bundler/bundler/issues/4147, there is # no test coverage to ensure that adding a gem is possible with a ruby # requirement. This test verifies the fix, committed in bfbad5c5. @@ -22,4 +26,64 @@ describe "ruby requirement" do expect(exitstatus).to eq(0) if exitstatus should_be_installed "rack-obama 1.0" end + + it "allows removing the ruby version requirement" do + install_gemfile <<-G + source "file://#{gem_repo1}" + ruby "~> #{RUBY_VERSION}" + gem "rack" + G + + expect(lockfile).to include("RUBY VERSION") + + install_gemfile <<-G + source "file://#{gem_repo1}" + gem "rack" + G + + should_be_installed "rack 1.0.0" + expect(lockfile).not_to include("RUBY VERSION") + end + + it "allows changing the ruby version requirement to something compatible" do + install_gemfile <<-G + source "file://#{gem_repo1}" + ruby ">= 1.0.0" + gem "rack" + G + + expect(locked_ruby_version).to eq(Bundler::RubyVersion.system) + + simulate_ruby_version "5100" + + install_gemfile <<-G + source "file://#{gem_repo1}" + ruby ">= 1.0.1" + gem "rack" + G + + should_be_installed "rack 1.0.0" + expect(locked_ruby_version).to eq(Bundler::RubyVersion.system) + end + + it "allows changing the ruby version requirement to something incompatible" do + install_gemfile <<-G + source "file://#{gem_repo1}" + ruby ">= 1.0.0" + gem "rack" + G + + expect(locked_ruby_version).to eq(Bundler::RubyVersion.system) + + simulate_ruby_version "5100" + + install_gemfile <<-G + source "file://#{gem_repo1}" + ruby ">= 5000.0" + gem "rack" + G + + should_be_installed "rack 1.0.0" + expect(locked_ruby_version.versions).to eq(["5100"]) + end end diff --git a/spec/other/platform_spec.rb b/spec/other/platform_spec.rb index 8d546fca57..a219853e2f 100644 --- a/spec/other/platform_spec.rb +++ b/spec/other/platform_spec.rb @@ -376,7 +376,7 @@ G bundle :check expect(exitstatus).to eq(0) if exitstatus - expect(out).to eq("The Gemfile's dependencies are satisfied") + expect(out).to eq("Resolving dependencies...\nThe Gemfile's dependencies are satisfied") end it "checks fine with any engine" do @@ -395,7 +395,7 @@ G bundle :check expect(exitstatus).to eq(0) if exitstatus - expect(out).to eq("The Gemfile's dependencies are satisfied") + expect(out).to eq("Resolving dependencies...\nThe Gemfile's dependencies are satisfied") end end diff --git a/spec/runtime/setup_spec.rb b/spec/runtime/setup_spec.rb index f9528199cc..14377ed17e 100644 --- a/spec/runtime/setup_spec.rb +++ b/spec/runtime/setup_spec.rb @@ -1032,7 +1032,7 @@ describe "Bundler.setup" do L if ruby_version - lock += "\n RUBY VERSION\n #{ruby_version}\n" + lock += "\n RUBY VERSION\n ruby #{ruby_version}\n" end lock += <<-L diff --git a/spec/support/helpers.rb b/spec/support/helpers.rb index 75ee592826..ff41dfbfa4 100644 --- a/spec/support/helpers.rb +++ b/spec/support/helpers.rb @@ -347,6 +347,15 @@ module Spec ENV["BUNDLER_SPEC_PLATFORM"] = old if block_given? end + def simulate_ruby_version(version) + return if version == RUBY_VERSION + old = ENV["BUNDLER_SPEC_RUBY_VERSION"] + ENV["BUNDLER_SPEC_RUBY_VERSION"] = version + yield if block_given? + ensure + ENV["BUNDLER_SPEC_RUBY_VERSION"] = old if block_given? + end + def simulate_ruby_engine(engine, version = "1.6.0") return if engine == local_ruby_engine |