summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames Wen <jrw2175@columbia.edu>2016-01-14 20:22:53 -0500
committerJames Wen <jrw2175@columbia.edu>2016-01-14 20:48:18 -0500
commitaa0dd2d4dbdb1d929ce19f15f2670e4fca9fe469 (patch)
tree08c1738f882dfe6c73309cb42da329a1974fc025
parente3d852f59fd16f682d858a7f596bd4e484308f70 (diff)
downloadbundler-aa0dd2d4dbdb1d929ce19f15f2670e4fca9fe469.tar.gz
Move `Bundler#ruby_version` functionality to `Bundler::RubyVersion#system`
- Part of design direction to move more functionality out of the `Bundler` top-level module.
-rw-r--r--lib/bundler.rb20
-rw-r--r--lib/bundler/definition.rb10
-rw-r--r--lib/bundler/fetcher.rb2
-rw-r--r--lib/bundler/installer/standalone.rb2
-rw-r--r--lib/bundler/ruby_version.rb20
-rw-r--r--spec/bundler/bundler_spec.rb101
-rw-r--r--spec/bundler/ruby_version_spec.rb101
7 files changed, 128 insertions, 128 deletions
diff --git a/lib/bundler.rb b/lib/bundler.rb
index 9c22f6ef63..146d343bd9 100644
--- a/lib/bundler.rb
+++ b/lib/bundler.rb
@@ -362,26 +362,6 @@ module Bundler
@git_present = Bundler.which("git") || Bundler.which("git.exe")
end
- def ruby_version
- ruby_engine = if defined?(RUBY_ENGINE) && !RUBY_ENGINE.nil?
- RUBY_ENGINE.dup
- else
- # not defined in ruby 1.8.7
- "ruby"
- end
- ruby_engine_version = case ruby_engine
- when "ruby"
- RUBY_VERSION.dup
- when "rbx"
- Rubinius::VERSION.dup
- when "jruby"
- JRUBY_VERSION.dup
- 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)
- end
-
def reset!
@definition = nil
end
diff --git a/lib/bundler/definition.rb b/lib/bundler/definition.rb
index f97a593ae3..2dc920316e 100644
--- a/lib/bundler/definition.rb
+++ b/lib/bundler/definition.rb
@@ -280,15 +280,15 @@ module Bundler
def locked_ruby_version
if @unlock[:ruby]
if ruby_version && !@locked_ruby_version
- return Bundler.ruby_version
+ return Bundler::RubyVersion.system
elsif ruby_version && @locked_ruby_version
- return Bundler.ruby_version
+ return Bundler::RubyVersion.system
elsif !ruby_version && @locked_ruby_version
return nil
end
else
if ruby_version && !@locked_ruby_version
- return Bundler.ruby_version
+ return Bundler::RubyVersion.system
elsif ruby_version && @locked_ruby_version
return @locked_ruby_version
elsif !ruby_version && @locked_ruby_version
@@ -404,7 +404,7 @@ module Bundler
def validate_ruby!
return unless ruby_version
- if diff = ruby_version.diff(Bundler.ruby_version)
+ if diff = ruby_version.diff(Bundler::RubyVersion.system)
problem, expected, actual = diff
msg = case problem
@@ -413,7 +413,7 @@ module Bundler
when :version
"Your Ruby version is #{actual}, but your Gemfile specified #{expected}"
when :engine_version
- "Your #{Bundler.ruby_version.engine} version is #{actual}, but your Gemfile specified #{ruby_version.engine} #{expected}"
+ "Your #{Bundler::RubyVersion.system.engine} version is #{actual}, but your Gemfile specified #{ruby_version.engine} #{expected}"
when :patchlevel
if !expected.is_a?(String)
"The Ruby patchlevel in your Gemfile must be a string"
diff --git a/lib/bundler/fetcher.rb b/lib/bundler/fetcher.rb
index af190bae21..c8c21a92ff 100644
--- a/lib/bundler/fetcher.rb
+++ b/lib/bundler/fetcher.rb
@@ -151,7 +151,7 @@ module Bundler
def user_agent
@user_agent ||= begin
- ruby = Bundler.ruby_version
+ ruby = Bundler::RubyVersion.system
agent = "bundler/#{Bundler::VERSION}"
agent << " rubygems/#{Gem::VERSION}"
diff --git a/lib/bundler/installer/standalone.rb b/lib/bundler/installer/standalone.rb
index 35ad98891e..40100b9540 100644
--- a/lib/bundler/installer/standalone.rb
+++ b/lib/bundler/installer/standalone.rb
@@ -33,7 +33,7 @@ module Bundler
end
def version_dir
- "#{Bundler.ruby_version.engine}/#{RbConfig::CONFIG["ruby_version"]}"
+ "#{Bundler::RubyVersion.system.engine}/#{RbConfig::CONFIG["ruby_version"]}"
end
def bundler_path
diff --git a/lib/bundler/ruby_version.rb b/lib/bundler/ruby_version.rb
index 8eefd80e1b..71ed828f71 100644
--- a/lib/bundler/ruby_version.rb
+++ b/lib/bundler/ruby_version.rb
@@ -67,6 +67,26 @@ module Bundler
end
end
+ def self.system
+ ruby_engine = if defined?(RUBY_ENGINE) && !RUBY_ENGINE.nil?
+ RUBY_ENGINE.dup
+ else
+ # not defined in ruby 1.8.7
+ "ruby"
+ end
+ ruby_engine_version = case ruby_engine
+ when "ruby"
+ RUBY_VERSION.dup
+ when "rbx"
+ Rubinius::VERSION.dup
+ when "jruby"
+ JRUBY_VERSION.dup
+ 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)
+ end
+
private
def matches?(requirement, version)
diff --git a/spec/bundler/bundler_spec.rb b/spec/bundler/bundler_spec.rb
index 00a1a85e5f..1b0addadb5 100644
--- a/spec/bundler/bundler_spec.rb
+++ b/spec/bundler/bundler_spec.rb
@@ -3,107 +3,6 @@ require "spec_helper"
require "bundler"
describe Bundler do
- describe "#ruby_version" do
- subject { Bundler.ruby_version }
-
- let(:bundler_ruby_version) { subject }
-
- before do
- Bundler.instance_variable_set("@ruby_version", nil)
- end
-
- it "should return an instance of Bundler::RubyVersion" do
- expect(subject).to be_kind_of(Bundler::RubyVersion)
- end
-
- it "memoizes the instance of Bundler::RubyVersion" do
- expect(Bundler::RubyVersion).to receive(:new).once.and_call_original
- 2.times { Bundler.ruby_version }
- end
-
- describe "#version" do
- it "should return a copy of the value of RUBY_VERSION" do
- expect(subject.version).to eq(RUBY_VERSION)
- expect(subject.version).to_not be(RUBY_VERSION)
- end
- end
-
- describe "#engine" do
- context "RUBY_ENGINE is defined" do
- before { stub_const("RUBY_ENGINE", "jruby") }
- before { stub_const("JRUBY_VERSION", "2.1.1") }
-
- it "should return a copy of the value of RUBY_ENGINE" do
- expect(subject.engine).to eq("jruby")
- expect(subject.engine).to_not be(RUBY_ENGINE)
- end
- end
-
- context "RUBY_ENGINE is not defined" do
- before { stub_const("RUBY_ENGINE", nil) }
-
- it "should return the string 'ruby'" do
- expect(subject.engine).to eq("ruby")
- end
- end
- end
-
- describe "#engine_version" do
- context "engine is ruby" do
- before do
- stub_const("RUBY_VERSION", "2.2.4")
- allow(Bundler).to receive(:ruby_engine).and_return("ruby")
- end
-
- it "should return a copy of the value of RUBY_VERSION" do
- expect(bundler_ruby_version.engine_version).to eq("2.2.4")
- expect(bundler_ruby_version.engine_version).to_not be(RUBY_VERSION)
- end
- end
-
- context "engine is rbx" do
- before do
- stub_const("RUBY_ENGINE", "rbx")
- stub_const("Rubinius::VERSION", "2.0.0")
- end
-
- it "should return a copy of the value of Rubinius::VERSION" do
- expect(bundler_ruby_version.engine_version).to eq("2.0.0")
- expect(bundler_ruby_version.engine_version).to_not be(Rubinius::VERSION)
- end
- end
-
- context "engine is jruby" do
- before do
- stub_const("RUBY_ENGINE", "jruby")
- stub_const("JRUBY_VERSION", "2.1.1")
- end
-
- it "should return a copy of the value of JRUBY_VERSION" do
- expect(bundler_ruby_version.engine_version).to eq("2.1.1")
- expect(bundler_ruby_version.engine_version).to_not be(JRUBY_VERSION)
- end
- end
-
- context "engine is some other ruby engine" do
- before do
- stub_const("RUBY_ENGINE", "not_supported_ruby_engine")
- allow(Bundler).to receive(:ruby_engine).and_return("not_supported_ruby_engine")
- end
-
- it "should raise a BundlerError with a 'not recognized' message" do
- expect { bundler_ruby_version.engine_version }.to raise_error(Bundler::BundlerError, "RUBY_ENGINE value not_supported_ruby_engine is not recognized")
- end
- end
- end
-
- describe "#patchlevel" do
- it "should return a string with the value of RUBY_PATCHLEVEL" do
- expect(subject.patchlevel).to eq(RUBY_PATCHLEVEL.to_s)
- end
- end
- end
-
describe "#load_gemspec_uncached" do
let(:app_gemspec_path) { tmp("test.gemspec") }
subject { Bundler.load_gemspec_uncached(app_gemspec_path) }
diff --git a/spec/bundler/ruby_version_spec.rb b/spec/bundler/ruby_version_spec.rb
index ee53ccdd45..d7ab0105fd 100644
--- a/spec/bundler/ruby_version_spec.rb
+++ b/spec/bundler/ruby_version_spec.rb
@@ -241,5 +241,106 @@ describe "Bundler::RubyVersion and its subclasses" do
it_behaves_like "there is a difference in the engine versions"
end
end
+
+ describe "#system" do
+ subject { Bundler::RubyVersion.system }
+
+ let(:bundler_system_ruby_version) { subject }
+
+ before do
+ Bundler::RubyVersion.instance_variable_set("@ruby_version", nil)
+ end
+
+ it "should return an instance of Bundler::RubyVersion" do
+ expect(subject).to be_kind_of(Bundler::RubyVersion)
+ end
+
+ it "memoizes the instance of Bundler::RubyVersion" do
+ expect(Bundler::RubyVersion).to receive(:new).once.and_call_original
+ 2.times { subject }
+ end
+
+ describe "#version" do
+ it "should return a copy of the value of RUBY_VERSION" do
+ expect(subject.version).to eq(RUBY_VERSION)
+ expect(subject.version).to_not be(RUBY_VERSION)
+ end
+ end
+
+ describe "#engine" do
+ context "RUBY_ENGINE is defined" do
+ before { stub_const("RUBY_ENGINE", "jruby") }
+ before { stub_const("JRUBY_VERSION", "2.1.1") }
+
+ it "should return a copy of the value of RUBY_ENGINE" do
+ expect(subject.engine).to eq("jruby")
+ expect(subject.engine).to_not be(RUBY_ENGINE)
+ end
+ end
+
+ context "RUBY_ENGINE is not defined" do
+ before { stub_const("RUBY_ENGINE", nil) }
+
+ it "should return the string 'ruby'" do
+ expect(subject.engine).to eq("ruby")
+ end
+ end
+ end
+
+ describe "#engine_version" do
+ context "engine is ruby" do
+ before do
+ stub_const("RUBY_VERSION", "2.2.4")
+ allow(Bundler).to receive(:ruby_engine).and_return("ruby")
+ end
+
+ it "should return a copy of the value of RUBY_VERSION" do
+ expect(bundler_system_ruby_version.engine_version).to eq("2.2.4")
+ expect(bundler_system_ruby_version.engine_version).to_not be(RUBY_VERSION)
+ end
+ end
+
+ context "engine is rbx" do
+ before do
+ stub_const("RUBY_ENGINE", "rbx")
+ stub_const("Rubinius::VERSION", "2.0.0")
+ end
+
+ it "should return a copy of the value of Rubinius::VERSION" do
+ expect(bundler_system_ruby_version.engine_version).to eq("2.0.0")
+ expect(bundler_system_ruby_version.engine_version).to_not be(Rubinius::VERSION)
+ end
+ end
+
+ context "engine is jruby" do
+ before do
+ stub_const("RUBY_ENGINE", "jruby")
+ stub_const("JRUBY_VERSION", "2.1.1")
+ end
+
+ it "should return a copy of the value of JRUBY_VERSION" do
+ expect(subject.engine_version).to eq("2.1.1")
+ expect(bundler_system_ruby_version.engine_version).to_not be(JRUBY_VERSION)
+ end
+ end
+
+ context "engine is some other ruby engine" do
+ before do
+ stub_const("RUBY_ENGINE", "not_supported_ruby_engine")
+ allow(Bundler).to receive(:ruby_engine).and_return("not_supported_ruby_engine")
+ end
+
+ it "should raise a BundlerError with a 'not recognized' message" do
+ expect { bundler_system_ruby_version.engine_version }.to raise_error(Bundler::BundlerError, "RUBY_ENGINE value not_supported_ruby_engine is not recognized")
+ end
+ end
+ end
+
+ describe "#patchlevel" do
+ it "should return a string with the value of RUBY_PATCHLEVEL" do
+ expect(subject.patchlevel).to eq(RUBY_PATCHLEVEL.to_s)
+ end
+ end
+ end
end
end