summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames Wen <jrw2175@columbia.edu>2016-01-12 00:06:01 -0500
committerJames Wen <jrw2175@columbia.edu>2016-01-14 00:28:06 -0500
commite3d852f59fd16f682d858a7f596bd4e484308f70 (patch)
tree4c8ee29784ab36d25841adf909f21e7e5ba6081e
parent0774ae07341c3f49381a56494b15397eb2acdcd0 (diff)
downloadbundler-e3d852f59fd16f682d858a7f596bd4e484308f70.tar.gz
Remove `Bundler::SystemRubyVersion`
- `Bundler::SystemRubyVersion` can easily be replaced by an instance of `Bundler::RubyVersion` that is constructed with the proper params
-rw-r--r--lib/bundler.rb19
-rw-r--r--lib/bundler/ruby_version.rb47
-rw-r--r--spec/bundler/bundler_spec.rb101
-rw-r--r--spec/bundler/ruby_version_spec.rb122
4 files changed, 118 insertions, 171 deletions
diff --git a/lib/bundler.rb b/lib/bundler.rb
index 20085c70ba..9c22f6ef63 100644
--- a/lib/bundler.rb
+++ b/lib/bundler.rb
@@ -48,7 +48,6 @@ module Bundler
autoload :StubSpecification, "bundler/stub_specification"
autoload :Source, "bundler/source"
autoload :SourceList, "bundler/source_list"
- autoload :SystemRubyVersion, "bundler/ruby_version"
autoload :RubyGemsGemInstaller, "bundler/rubygems_gem_installer"
autoload :UI, "bundler/ui"
@@ -364,7 +363,23 @@ module Bundler
end
def ruby_version
- @ruby_version ||= SystemRubyVersion.new
+ 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!
diff --git a/lib/bundler/ruby_version.rb b/lib/bundler/ruby_version.rb
index 18dca7162b..8eefd80e1b 100644
--- a/lib/bundler/ruby_version.rb
+++ b/lib/bundler/ruby_version.rb
@@ -73,51 +73,4 @@ module Bundler
Gem::Requirement.create(requirement).satisfied_by?(Gem::Version.new(version))
end
end
-
- # A subclass of RubyVersion that implements version,
- # engine and engine_version based upon the current
- # information in the system. It can be used anywhere
- # a RubyVersion object is expected, and can be
- # compared with a RubyVersion object.
- class SystemRubyVersion < RubyVersion
- def initialize(*)
- # override the default initialize, because
- # we will implement version, engine and
- # engine_version dynamically
- end
-
- def version
- RUBY_VERSION.dup
- end
-
- def gem_version
- @gem_version ||= Gem::Version.new(version)
- end
-
- def engine
- if defined?(RUBY_ENGINE) && !RUBY_ENGINE.nil?
- RUBY_ENGINE.dup
- else
- # not defined in ruby 1.8.7
- "ruby"
- end
- end
-
- def engine_version
- case 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
- end
-
- def patchlevel
- RUBY_PATCHLEVEL.to_s
- end
- end
end
diff --git a/spec/bundler/bundler_spec.rb b/spec/bundler/bundler_spec.rb
index 1b0addadb5..00a1a85e5f 100644
--- a/spec/bundler/bundler_spec.rb
+++ b/spec/bundler/bundler_spec.rb
@@ -3,6 +3,107 @@ 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 e0df4c56c0..ee53ccdd45 100644
--- a/spec/bundler/ruby_version_spec.rb
+++ b/spec/bundler/ruby_version_spec.rb
@@ -242,126 +242,4 @@ describe "Bundler::RubyVersion and its subclasses" do
end
end
end
-
- describe Bundler::SystemRubyVersion do
- subject { Bundler::SystemRubyVersion.new(version, patchlevel, engine, engine_version) }
-
- let(:system_ruby_version) { subject }
-
- describe "#initialize" do
- # Suppress "warning: instance variable @variable not initialized" warnings
- before do
- @verbose = $VERBOSE
- $VERBOSE = nil
- end
-
- after { $VERBOSE = @verbose }
-
- it "should not set any of the instance attributes" do
- expect(system_ruby_version.instance_variable_get(:@version)).to be_nil
- expect(system_ruby_version.instance_variable_get(:@patchlevel)).to be_nil
- expect(system_ruby_version.instance_variable_get(:@engine)).to be_nil
- expect(system_ruby_version.instance_variable_get(:@engine_version)).to be_nil
- end
- 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 "#gem_version" do
- before do
- @current_ruby_version = RUBY_VERSION
- gem_version_double = double(:gem_version)
- allow(Gem::Version).to receive(:new).with(RUBY_VERSION).and_return(gem_version_double)
- end
-
- it "should return a Gem::Version instance with the correct version" do
- gem_version = Gem::Version.new(RUBY_VERSION)
- expect(system_ruby_version.gem_version).to eq(gem_version)
- end
-
- it "memoizes the Gem::Version instance" do
- expect(Gem::Version).to receive(:new).with(@current_ruby_version).once.and_call_original
- 2.times { system_ruby_version.gem_version }
- end
- end
-
- describe "#engine" do
- context "RUBY_ENGINE is defined" do
- before { stub_const("RUBY_ENGINE", "2.2.4") }
-
- it "should return a copy of the value of RUBY_ENGINE" do
- expect(subject.engine).to eq("2.2.4")
- 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
- allow(system_ruby_version).to receive(:engine).and_return("ruby")
- stub_const("RUBY_VERSION", "2.2.4")
- end
-
- it "should return a copy of the value of RUBY_VERSION" do
- expect(system_ruby_version.engine_version).to eq("2.2.4")
- expect(system_ruby_version.engine_version).to_not be(RUBY_VERSION)
- end
- end
-
- context "engine is rbx" do
- before do
- allow(system_ruby_version).to receive(:engine).and_return("rbx")
- stub_const("Rubinius::VERSION", "2.0.0")
- end
-
- it "should return a copy of the value of Rubinius::VERSION" do
- expect(system_ruby_version.engine_version).to eq("2.0.0")
- expect(system_ruby_version.engine_version).to_not be(Rubinius::VERSION)
- end
- end
-
- context "engine is jruby" do
- before do
- allow(system_ruby_version).to receive(:engine).and_return("jruby")
- stub_const("JRUBY_VERSION", "2.1.1")
- end
-
- it "should return a copy of the value of JRUBY_VERSION" do
- expect(system_ruby_version.engine_version).to eq("2.1.1")
- expect(system_ruby_version.engine_version).to_not be(JRUBY_VERSION)
- end
- end
-
- context "engine is some other ruby engine" do
- before do
- allow(system_ruby_version).to receive(:engine).and_return("not_supported_ruby_engine")
- stub_const("RUBY_ENGINE", "not_supported_ruby_engine")
- end
-
- it "should raise a BundlerError with a 'not recognized' message" do
- expect { 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