summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTerence Lee <hone02@gmail.com>2013-08-19 19:36:09 -0700
committerTerence Lee <hone02@gmail.com>2013-08-24 15:15:28 -0700
commite1ff1b281e4fe9932e6ff127f756f5acb03968ec (patch)
treeb2fd581e221c015521d3794ee622d693d00211fd
parent47964a138d964af49e0834806a9ef7930f322d0c (diff)
downloadbundler-e1ff1b281e4fe9932e6ff127f756f5acb03968ec.tar.gz
patchlevel support for ruby DSL
-rw-r--r--lib/bundler/definition.rb2
-rw-r--r--lib/bundler/ruby_dsl.rb2
-rw-r--r--lib/bundler/ruby_version.rb15
-rw-r--r--spec/other/bundle_ruby_spec.rb180
-rw-r--r--spec/other/platform_spec.rb200
-rw-r--r--spec/support/platforms.rb4
6 files changed, 324 insertions, 79 deletions
diff --git a/lib/bundler/definition.rb b/lib/bundler/definition.rb
index be0246fbfe..4e538e6199 100644
--- a/lib/bundler/definition.rb
+++ b/lib/bundler/definition.rb
@@ -380,6 +380,8 @@ module Bundler
"Your Ruby version is #{actual}, but your Gemfile specified #{expected}"
when :engine_version
"Your #{system_ruby_version.engine} version is #{actual}, but your Gemfile specified #{ruby_version.engine} #{expected}"
+ when :patchlevel
+ "Your Ruby patchlevel is #{actual}, but your Gemfile specified #{expected}"
end
raise RubyVersionMismatch, msg
diff --git a/lib/bundler/ruby_dsl.rb b/lib/bundler/ruby_dsl.rb
index 87bb801dc7..b29fc019a7 100644
--- a/lib/bundler/ruby_dsl.rb
+++ b/lib/bundler/ruby_dsl.rb
@@ -5,7 +5,7 @@ module Bundler
raise GemfileError, "Please define :engine" if options[:engine_version] && options[:engine].nil?
raise GemfileError, "ruby_version must match the :engine_version for MRI" if options[:engine] == "ruby" && options[:engine_version] && ruby_version != options[:engine_version]
- @ruby_version = RubyVersion.new(ruby_version, options[:engine], options[:engine_version])
+ @ruby_version = RubyVersion.new(ruby_version, options[:patchlevel], options[:engine], options[:engine_version])
end
end
end
diff --git a/lib/bundler/ruby_version.rb b/lib/bundler/ruby_version.rb
index 9fff1431ad..bf44278b46 100644
--- a/lib/bundler/ruby_version.rb
+++ b/lib/bundler/ruby_version.rb
@@ -1,8 +1,8 @@
module Bundler
class RubyVersion
- attr_reader :version, :engine, :engine_version
+ attr_reader :version, :patchlevel, :engine, :engine_version
- def initialize(version, engine, engine_version)
+ def initialize(version, patchlevel, engine, engine_version)
# The parameters to this method must satisfy the
# following constraints, which are verified in
# the DSL:
@@ -20,10 +20,12 @@ module Bundler
# keep track of the engine specified by the user
@input_engine = engine
@engine_version = engine_version || version
+ @patchlevel = patchlevel
end
def to_s
output = "ruby #{version}"
+ output << "p#{patchlevel}" if patchlevel
output << " (#{engine} #{engine_version})" unless engine == "ruby"
output
@@ -32,7 +34,8 @@ module Bundler
def ==(other)
version == other.version &&
engine == other.engine &&
- engine_version == other.engine_version
+ engine_version == other.engine_version &&
+ patchlevel == other.patchlevel
end
# Returns a tuple of thsee things:
@@ -48,6 +51,8 @@ module Bundler
[ :version, version, other.version ]
elsif engine_version != other.engine_version && @input_engine
[ :engine_version, engine_version, other.engine_version ]
+ elsif patchlevel != other.patchlevel && @patchlevel
+ [ :patchlevel, patchlevel, other.patchlevel ]
else
nil
end
@@ -96,5 +101,9 @@ module Bundler
nil
end
end
+
+ def patchlevel
+ RUBY_PATCHLEVEL
+ end
end
end
diff --git a/spec/other/bundle_ruby_spec.rb b/spec/other/bundle_ruby_spec.rb
index 5bb563a74f..7d41a00d34 100644
--- a/spec/other/bundle_ruby_spec.rb
+++ b/spec/other/bundle_ruby_spec.rb
@@ -1,112 +1,142 @@
require "spec_helper"
describe "bundle_ruby" do
- it "returns the ruby version" do
- gemfile <<-G
- source "file://#{gem_repo1}"
- ruby "1.9.3", :engine => 'ruby', :engine_version => '1.9.3'
+ context "without patchlevel" do
+ it "returns the ruby version" do
+ gemfile <<-G
+ source "file://#{gem_repo1}"
+ ruby "1.9.3", :engine => 'ruby', :engine_version => '1.9.3'
- gem "foo"
- G
+ gem "foo"
+ G
- bundle_ruby
+ bundle_ruby
- expect(out).to eq("ruby 1.9.3")
- end
+ expect(out).to eq("ruby 1.9.3")
+ end
- it "engine defaults to MRI" do
- gemfile <<-G
- source "file://#{gem_repo1}"
- ruby "1.9.3"
+ it "engine defaults to MRI" do
+ gemfile <<-G
+ source "file://#{gem_repo1}"
+ ruby "1.9.3"
- gem "foo"
- G
+ gem "foo"
+ G
- bundle_ruby
+ bundle_ruby
- expect(out).to eq("ruby 1.9.3")
- end
+ expect(out).to eq("ruby 1.9.3")
+ end
- it "handles jruby" do
- gemfile <<-G
- source "file://#{gem_repo1}"
- ruby "1.8.7", :engine => 'jruby', :engine_version => '1.6.5'
+ it "handles jruby" do
+ gemfile <<-G
+ source "file://#{gem_repo1}"
+ ruby "1.8.7", :engine => 'jruby', :engine_version => '1.6.5'
- gem "foo"
- G
+ gem "foo"
+ G
- bundle_ruby
+ bundle_ruby
- expect(out).to eq("ruby 1.8.7 (jruby 1.6.5)")
- end
+ expect(out).to eq("ruby 1.8.7 (jruby 1.6.5)")
+ end
- it "handles rbx" do
- gemfile <<-G
- source "file://#{gem_repo1}"
- ruby "1.8.7", :engine => 'rbx', :engine_version => '1.2.4'
+ it "handles rbx" do
+ gemfile <<-G
+ source "file://#{gem_repo1}"
+ ruby "1.8.7", :engine => 'rbx', :engine_version => '1.2.4'
- gem "foo"
- G
+ gem "foo"
+ G
- bundle_ruby
+ bundle_ruby
- expect(out).to eq("ruby 1.8.7 (rbx 1.2.4)")
- end
+ expect(out).to eq("ruby 1.8.7 (rbx 1.2.4)")
+ end
- it "raises an error if engine is used but engine version is not" do
- gemfile <<-G
- source "file://#{gem_repo1}"
- ruby "1.8.7", :engine => 'rbx'
+ it "raises an error if engine is used but engine version is not" do
+ gemfile <<-G
+ source "file://#{gem_repo1}"
+ ruby "1.8.7", :engine => 'rbx'
- gem "foo"
- G
+ gem "foo"
+ G
- bundle_ruby :exitstatus => true
- expect(exitstatus).not_to eq(0)
+ bundle_ruby :exitstatus => true
+ expect(exitstatus).not_to eq(0)
- bundle_ruby
- expect(out).to eq("Please define :engine_version")
- end
+ bundle_ruby
+ expect(out).to eq("Please define :engine_version")
+ end
- it "raises an error if engine_version is used but engine is not" do
- gemfile <<-G
- source "file://#{gem_repo1}"
- ruby "1.8.7", :engine_version => '1.2.4'
+ it "raises an error if engine_version is used but engine is not" do
+ gemfile <<-G
+ source "file://#{gem_repo1}"
+ ruby "1.8.7", :engine_version => '1.2.4'
- gem "foo"
- G
+ gem "foo"
+ G
- bundle_ruby :exitstatus => true
- expect(exitstatus).not_to eq(0)
+ bundle_ruby :exitstatus => true
+ expect(exitstatus).not_to eq(0)
- bundle_ruby
- expect(out).to eq("Please define :engine")
- end
+ bundle_ruby
+ expect(out).to eq("Please define :engine")
+ end
+
+ it "raises an error if engine version doesn't match ruby version for MRI" do
+ gemfile <<-G
+ source "file://#{gem_repo1}"
+ ruby "1.8.7", :engine => 'ruby', :engine_version => '1.2.4'
- it "raises an error if engine version doesn't match ruby version for MRI" do
- gemfile <<-G
- source "file://#{gem_repo1}"
- ruby "1.8.7", :engine => 'ruby', :engine_version => '1.2.4'
+ gem "foo"
+ G
- gem "foo"
- G
+ bundle_ruby :exitstatus => true
+ expect(exitstatus).not_to eq(0)
- bundle_ruby :exitstatus => true
- expect(exitstatus).not_to eq(0)
+ bundle_ruby
+ expect(out).to eq("ruby_version must match the :engine_version for MRI")
+ end
- bundle_ruby
- expect(out).to eq("ruby_version must match the :engine_version for MRI")
+ it "should print if no ruby version is specified" do
+ gemfile <<-G
+ source "file://#{gem_repo1}"
+
+ gem "foo"
+ G
+
+ bundle_ruby
+
+ expect(out).to eq("No ruby version specified")
+ end
end
- it "should print if no ruby version is specified" do
- gemfile <<-G
- source "file://#{gem_repo1}"
+ context "when using patchlevel" do
+ it "returns the ruby version" do
+ gemfile <<-G
+ source "file://#{gem_repo1}"
+ ruby "1.9.3", :patchlevel => 429, :engine => 'ruby', :engine_version => '1.9.3'
+
+ gem "foo"
+ G
+
+ bundle_ruby
+
+ expect(out).to eq("ruby 1.9.3p429")
+ end
+
+ it "handles an engine" do
+ gemfile <<-G
+ source "file://#{gem_repo1}"
+ ruby "1.9.3", :patchlevel => 392, :engine => 'jruby', :engine_version => '1.7.4'
- gem "foo"
- G
+ gem "foo"
+ G
- bundle_ruby
+ bundle_ruby
- expect(out).to eq("No ruby version specified")
+ expect(out).to eq("ruby 1.9.3p392 (jruby 1.7.4)")
+ end
end
end
diff --git a/spec/other/platform_spec.rb b/spec/other/platform_spec.rb
index 127bf904f9..a483218773 100644
--- a/spec/other/platform_spec.rb
+++ b/spec/other/platform_spec.rb
@@ -25,6 +25,29 @@ Your current platform satisfies the Ruby version requirement.
G
end
+ it "returns all the output including the patchlevel" do
+ gemfile <<-G
+ source "file://#{gem_repo1}"
+
+ #{ruby_version_correct_patchlevel}
+
+ gem "foo"
+ G
+
+ bundle "platform"
+ expect(out).to eq(<<-G.chomp)
+Your platform is: #{RUBY_PLATFORM}
+
+Your app has gems that work on these platforms:
+* ruby
+
+Your Gemfile specifies a Ruby version requirement:
+* ruby #{RUBY_VERSION}p#{RUBY_PATCHLEVEL}
+
+Your current platform satisfies the Ruby version requirement.
+G
+ end
+
it "doesn't print ruby version requirement if it isn't specified" do
gemfile <<-G
source "file://#{gem_repo1}"
@@ -175,9 +198,11 @@ G
let(:ruby_version_correct) { "ruby \"#{RUBY_VERSION}\", :engine => \"#{local_ruby_engine}\", :engine_version => \"#{local_engine_version}\"" }
let(:ruby_version_correct_engineless) { "ruby \"#{RUBY_VERSION}\"" }
+ let(:ruby_version_correct_patchlevel) { "#{ruby_version_correct}, :patchlevel => #{RUBY_PATCHLEVEL}" }
let(:ruby_version_incorrect) { "ruby \"#{not_local_ruby_version}\", :engine => \"#{local_ruby_engine}\", :engine_version => \"#{not_local_ruby_version}\"" }
let(:engine_incorrect) { "ruby \"#{RUBY_VERSION}\", :engine => \"#{not_local_tag}\", :engine_version => \"#{RUBY_VERSION}\"" }
let(:engine_version_incorrect) { "ruby \"#{RUBY_VERSION}\", :engine => \"#{local_ruby_engine}\", :engine_version => \"#{not_local_engine_version}\"" }
+ let(:patchlevel_incorrect) { "#{ruby_version_correct}, :patchlevel => #{not_local_patchlevel}" }
def should_be_ruby_version_incorrect(opts = {:exitstatus => true})
expect(exitstatus).to eq(18) if opts[:exitstatus]
@@ -194,6 +219,12 @@ G
expect(out).to be_include("Your #{local_ruby_engine} version is #{local_engine_version}, but your Gemfile specified #{local_ruby_engine} #{not_local_engine_version}")
end
+ def should_be_patchlevel_incorrect(opts = {:exitstatus => true})
+ expect(exitstatus).to eq(18) if opts[:exitstatus]
+
+ expect(out).to be_include("Your Ruby patchlevel is #{RUBY_PATCHLEVEL}, but your Gemfile specified #{not_local_patchlevel}")
+ end
+
context "bundle install" do
it "installs fine when the ruby version matches" do
install_gemfile <<-G
@@ -219,6 +250,17 @@ G
end
end
+ it "installs fine when the patchlevel matches" do
+ install_gemfile <<-G
+ source "file://#{gem_repo1}"
+ gem "rack"
+
+ #{ruby_version_correct_patchlevel}
+ G
+
+ expect(bundled_app('Gemfile.lock')).to exist
+ end
+
it "doesn't install when the ruby version doesn't match" do
install_gemfile <<-G, :exitstatus => true
source "file://#{gem_repo1}"
@@ -256,6 +298,18 @@ G
should_be_engine_version_incorrect
end
end
+
+ it "doesn't install when patchlevel doesn't match" do
+ install_gemfile <<-G, :exitstatus => true
+ source "file://#{gem_repo1}"
+ gem "rack"
+
+ #{patchlevel_incorrect}
+ G
+
+ expect(bundled_app('Gemfile.lock')).not_to exist
+ should_be_patchlevel_incorrect
+ end
end
context "bundle check" do
@@ -349,6 +403,23 @@ G
should_be_engine_version_incorrect
end
end
+
+ it "fails when patchlevel doesn't match" do
+ install_gemfile <<-G, :exitstatus => true
+ source "file://#{gem_repo1}"
+ gem "rack"
+ G
+
+ gemfile <<-G
+ source "file://#{gem_repo1}"
+ gem "rack"
+
+ #{patchlevel_incorrect}
+ G
+
+ bundle :check, :exitstatus => true
+ should_be_patchlevel_incorrect
+ end
end
context "bundle update" do
@@ -445,6 +516,21 @@ G
should_be_engine_version_incorrect
end
end
+
+ it "fails when patchlevel doesn't match" do
+ gemfile <<-G, :exitstatus => true
+ source "file://#{gem_repo1}"
+ gem "rack"
+
+ #{patchlevel_incorrect}
+ G
+ update_repo2 do
+ build_gem "activesupport", "3.0"
+ end
+
+ bundle :update, :exitstatus => true
+ should_be_patchlevel_incorrect
+ end
end
context "bundle show" do
@@ -518,6 +604,21 @@ G
should_be_engine_version_incorrect
end
end
+
+ it "fails when patchlevel doesn't match" do
+ gemfile <<-G, :exitstatus => true
+ source "file://#{gem_repo1}"
+ gem "rack"
+
+ #{patchlevel_incorrect}
+ G
+ update_repo2 do
+ build_gem "activesupport", "3.0"
+ end
+
+ bundle "show rails", :exitstatus => true
+ should_be_patchlevel_incorrect
+ end
end
context "bundle cache" do
@@ -587,6 +688,18 @@ G
should_be_engine_version_incorrect
end
end
+
+ it "fails when patchlevel doesn't match" do
+ gemfile <<-G, :exitstatus => true
+ source "file://#{gem_repo1}"
+ gem "rack"
+
+ #{patchlevel_incorrect}
+ G
+
+ bundle :cache, :exitstatus => true
+ should_be_patchlevel_incorrect
+ end
end
context "bundle pack" do
@@ -656,6 +769,18 @@ G
should_be_engine_version_incorrect
end
end
+
+ it "fails when patchlevel doesn't match" do
+ gemfile <<-G, :exitstatus => true
+ source "file://#{gem_repo1}"
+ gem "rack"
+
+ #{patchlevel_incorrect}
+ G
+
+ bundle :pack, :exitstatus => true
+ should_be_patchlevel_incorrect
+ end
end
context "bundle exec" do
@@ -721,6 +846,18 @@ G
should_be_engine_version_incorrect
end
end
+
+ it "fails when patchlevel doesn't match" do
+ gemfile <<-G, :exitstatus => true
+ source "file://#{gem_repo1}"
+ gem "rack"
+
+ #{patchlevel_incorrect}
+ G
+
+ bundle "exec rackup", :exitstatus => true
+ should_be_patchlevel_incorrect
+ end
end
context "bundle console" do
@@ -812,6 +949,20 @@ G
should_be_engine_version_incorrect
end
end
+
+ it "fails when patchlevel doesn't match" do
+ gemfile <<-G, :exitstatus => true
+ source "file://#{gem_repo1}"
+ gem "rack"
+ gem "activesupport", :group => :test
+ gem "rack_middleware", :group => :development
+
+ #{patchlevel_incorrect}
+ G
+
+ bundle "console", :exitstatus => true
+ should_be_patchlevel_incorrect
+ end
end
context "Bundler.setup" do
@@ -944,6 +1095,35 @@ G
should_be_engine_version_incorrect(:exitstatus => false)
end
end
+
+ it "fails when patchlevel doesn't match" do
+ install_gemfile <<-G
+ source "file://#{gem_repo1}"
+ gem "yard"
+ gem "rack"
+
+ #{patchlevel_incorrect}
+ G
+
+ puts File.read(bundled_app("Gemfile"))
+ File.read(bundled_app("Gemfile.lock"))
+
+ FileUtils.rm(bundled_app("Gemfile.lock"))
+
+ ruby <<-R
+ require 'rubygems'
+ require 'bundler'
+
+ begin
+ Bundler.setup
+ rescue Bundler::RubyVersionMismatch => e
+ puts e.message
+ end
+ R
+
+ expect(bundled_app("Gemfile.lock")).not_to exist
+ should_be_patchlevel_incorrect(:exitstatus => false)
+ end
end
context "bundle outdated" do
@@ -1054,5 +1234,25 @@ G
should_be_engine_version_incorrect
end
end
+
+ it "fails when the patchlevel doesn't match" do
+ simulate_ruby_engine "jruby" do
+ update_repo2 do
+ build_gem "activesupport", "3.0"
+ update_git "foo", :path => lib_path("foo")
+ end
+
+ gemfile <<-G
+ source "file://#{gem_repo2}"
+ gem "activesupport", "2.3.5"
+ gem "foo", :git => "#{lib_path('foo')}"
+
+ #{patchlevel_incorrect}
+ G
+
+ bundle "outdated", :exitstatus => true
+ should_be_patchlevel_incorrect
+ end
+ end
end
end
diff --git a/spec/support/platforms.rb b/spec/support/platforms.rb
index 7636395dd2..b574d63ccb 100644
--- a/spec/support/platforms.rb
+++ b/spec/support/platforms.rb
@@ -86,5 +86,9 @@ module Spec
def not_local_ruby_version
"1.12"
end
+
+ def not_local_patchlevel
+ 9999
+ end
end
end