summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHomu <homu@barosl.com>2016-06-09 08:14:36 +0900
committerHomu <homu@barosl.com>2016-06-09 08:14:36 +0900
commit64edbb8e0f8cd2b73cefba36755d8c32c774ab0c (patch)
treed91cde9492be57a3e527737bbc3cada9c0accd2b
parent86d960e2b41be33fe2ab50e5d6da2fa276dbd51e (diff)
parent4c5d334bea9431ba51d3095e0d4fa16804d86268 (diff)
downloadbundler-64edbb8e0f8cd2b73cefba36755d8c32c774ab0c.tar.gz
Auto merge of #4625 - chalkos:bf-fix-4593, r=segiddins
Fixes specifying ruby patch level in gemfile and gemspec - [x] add failing spec - [x] add fix (with passing spec) and more specs to cover edge cases - [x] ~~change error message to a more meaningful one~~ fixed the bug and a meaningful error message is now being shown spec always passes on 2.2.0p0, probably because the patch version is 0
-rw-r--r--lib/bundler/resolver.rb2
-rw-r--r--lib/bundler/ruby_version.rb8
-rw-r--r--spec/bundler/ruby_version_spec.rb26
-rw-r--r--spec/install/gemspecs_spec.rb61
4 files changed, 96 insertions, 1 deletions
diff --git a/lib/bundler/resolver.rb b/lib/bundler/resolver.rb
index 918b3c977b..3d0f1ec080 100644
--- a/lib/bundler/resolver.rb
+++ b/lib/bundler/resolver.rb
@@ -125,7 +125,7 @@ module Bundler
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.gem_version)
+ spec_required_ruby_version.satisfied_by?(required_ruby_version.to_gem_version_with_patchlevel)
else
true
end
diff --git a/lib/bundler/ruby_version.rb b/lib/bundler/ruby_version.rb
index 92f9d4c396..5936eca830 100644
--- a/lib/bundler/ruby_version.rb
+++ b/lib/bundler/ruby_version.rb
@@ -100,6 +100,14 @@ module Bundler
@ruby_version ||= RubyVersion.new(RUBY_VERSION.dup, RUBY_PATCHLEVEL.to_s, ruby_engine, ruby_engine_version)
end
+ def to_gem_version_with_patchlevel
+ @gem_version_with_patch ||= begin
+ Gem::Version.create("#{@gem_version}.#{@patchlevel}")
+ rescue ArgumentError
+ @gem_version
+ end
+ end
+
private
def matches?(requirements, version)
diff --git a/spec/bundler/ruby_version_spec.rb b/spec/bundler/ruby_version_spec.rb
index 08a7e0e8e4..414ec3c3c8 100644
--- a/spec/bundler/ruby_version_spec.rb
+++ b/spec/bundler/ruby_version_spec.rb
@@ -452,5 +452,31 @@ describe "Bundler::RubyVersion and its subclasses" do
end
end
end
+
+ describe "#to_gem_version_with_patchlevel" do
+ shared_examples_for "the patchlevel is omitted" do
+ it "does not include a patch level" do
+ expect(subject.to_gem_version_with_patchlevel.to_s).to eq(version)
+ end
+ end
+
+ context "with nil patch number" do
+ let(:patchlevel) { nil }
+
+ it_behaves_like "the patchlevel is omitted"
+ end
+
+ context "with negative patch number" do
+ let(:patchlevel) { -1 }
+
+ it_behaves_like "the patchlevel is omitted"
+ end
+
+ context "with a valid patch number" do
+ it "uses the specified patchlevel as patchlevel" do
+ expect(subject.to_gem_version_with_patchlevel.to_s).to eq("#{version}.#{patchlevel}")
+ end
+ end
+ end
end
end
diff --git a/spec/install/gemspecs_spec.rb b/spec/install/gemspecs_spec.rb
index 4e2a18679a..a9721b296b 100644
--- a/spec/install/gemspecs_spec.rb
+++ b/spec/install/gemspecs_spec.rb
@@ -46,4 +46,65 @@ describe "bundle install" do
bundle :install, :artifice => "endpoint_marshal_fail" # force gemspec load
should_be_installed "activesupport 2.3.2"
end
+
+ context "when ruby version is specified in gemspec and gemfile" do
+ it "installs when patch level is not specified and the version matches" do
+ build_lib("foo", :path => bundled_app) do |s|
+ s.required_ruby_version = RUBY_VERSION
+ end
+
+ install_gemfile <<-G
+ ruby '#{RUBY_VERSION}', :engine_version => '#{RUBY_VERSION}', :engine => 'ruby'
+ gemspec
+ G
+ should_be_installed "foo 1.0"
+ end
+
+ it "installs when patch level is specified and the version still matches the current version" do
+ pending "this feature does not support dev ruby versions" if RUBY_PATCHLEVEL < 0
+ build_lib("foo", :path => bundled_app) do |s|
+ s.required_ruby_version = "#{RUBY_VERSION}.#{RUBY_PATCHLEVEL}"
+ end
+
+ install_gemfile <<-G
+ ruby '#{RUBY_VERSION}', :engine_version => '#{RUBY_VERSION}', :engine => 'ruby', :patchlevel => '#{RUBY_PATCHLEVEL}'
+ gemspec
+ G
+ should_be_installed "foo 1.0"
+ end
+
+ it "fails and complains about patchlevel on patchlevel mismatch" do
+ pending "this feature does not support dev ruby versions" if RUBY_PATCHLEVEL < 0
+ patchlevel = RUBY_PATCHLEVEL.to_i + 1
+ build_lib("foo", :path => bundled_app) do |s|
+ s.required_ruby_version = "#{RUBY_VERSION}.#{patchlevel}"
+ end
+
+ install_gemfile <<-G
+ ruby '#{RUBY_VERSION}', :engine_version => '#{RUBY_VERSION}', :engine => 'ruby', :patchlevel => '#{patchlevel}'
+ gemspec
+ G
+
+ expect(out).to include("Ruby patchlevel")
+ expect(out).to include("but your Gemfile specified")
+ expect(exitstatus).to eq(18) if exitstatus
+ end
+
+ it "fails and complains about version on version mismatch" do
+ version = Gem::Requirement.create(RUBY_VERSION).requirements.first.last.bump.version
+
+ build_lib("foo", :path => bundled_app) do |s|
+ s.required_ruby_version = version
+ end
+
+ install_gemfile <<-G
+ ruby '#{version}', :engine_version => '#{version}', :engine => 'ruby'
+ gemspec
+ G
+
+ expect(out).to include("Ruby version")
+ expect(out).to include("but your Gemfile specified")
+ expect(exitstatus).to eq(18) if exitstatus
+ end
+ end
end