summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSamuel Giddins <segiddins@segiddins.me>2016-01-31 21:04:30 -0600
committerSamuel Giddins <segiddins@segiddins.me>2016-02-01 15:45:25 -0600
commitdb227665aab59316183c508b85571022ef59eb7a (patch)
treec4616179ed2fc3f5bc5671d8b909b708f81955cb
parent5792e658361374d52b9aa82548aac1f69e05fbc3 (diff)
downloadbundler-db227665aab59316183c508b85571022ef59eb7a.tar.gz
[RubyVersion] Add specs for versions with requirements
-rw-r--r--lib/bundler/ruby_version.rb7
-rw-r--r--spec/bundler/ruby_dsl_spec.rb77
-rw-r--r--spec/bundler/ruby_version_spec.rb20
3 files changed, 94 insertions, 10 deletions
diff --git a/lib/bundler/ruby_version.rb b/lib/bundler/ruby_version.rb
index a1f6402ed5..27ae42bfa1 100644
--- a/lib/bundler/ruby_version.rb
+++ b/lib/bundler/ruby_version.rb
@@ -1,7 +1,7 @@
# frozen_string_literal: true
module Bundler
class RubyVersion
- attr_reader :version, :patchlevel, :engine, :engine_version
+ attr_reader :version, :patchlevel, :engine, :engine_version, :gem_version
def initialize(version, patchlevel, engine, engine_version)
# The parameters to this method must satisfy the
@@ -17,6 +17,7 @@ module Bundler
# specified must match the version.
@version = version
+ @gem_version = Gem::Requirement.create(version).requirements.first.last
@input_engine = engine
@engine = engine || "ruby"
@engine_version = engine_version || version
@@ -46,10 +47,6 @@ module Bundler
].join("-")
end
- def gem_version
- Gem::Requirement.create(version).requirements.first.last
- end
-
# Returns a tuple of these things:
# [diff, this, other]
# The priority of attributes are
diff --git a/spec/bundler/ruby_dsl_spec.rb b/spec/bundler/ruby_dsl_spec.rb
new file mode 100644
index 0000000000..c507652966
--- /dev/null
+++ b/spec/bundler/ruby_dsl_spec.rb
@@ -0,0 +1,77 @@
+require "spec_helper"
+require "bundler/ruby_dsl"
+
+describe Bundler::RubyDsl do
+ class MockDSL
+ include Bundler::RubyDsl
+
+ attr_reader :ruby_version
+ end
+
+ let(:dsl) { MockDSL.new }
+ let(:ruby_version) { "2.0.0" }
+ let(:version) { "2.0.0" }
+ let(:engine) { "jruby" }
+ let(:engine_version) { "9000" }
+ let(:patchlevel) { "100" }
+ let(:options) do
+ { :patchlevel => patchlevel,
+ :engine => engine,
+ :engine_version => engine_version }
+ end
+
+ let(:invoke) do
+ proc do
+ dsl.ruby(ruby_version, options)
+ end
+ end
+
+ subject do
+ invoke.call
+ dsl.ruby_version
+ end
+
+ describe "#ruby_version" do
+ shared_examples_for "it stores the ruby version" do
+ it "stores the version" do
+ expect(subject.version).to eq(ruby_version)
+ expect(subject.gem_version.version).to eq(version)
+ end
+
+ it "stores the engine details" do
+ expect(subject.engine).to eq(engine)
+ expect(subject.engine_version).to eq(engine_version)
+ end
+
+ it "stores the patchlevel" do
+ expect(subject.patchlevel).to eq(patchlevel)
+ end
+ end
+
+ context "with a plain version" do
+ it_behaves_like "it stores the ruby version"
+ end
+
+ context "with a single requirement" do
+ let(:ruby_version) { ">= 2.0.0" }
+ it_behaves_like "it stores the ruby version"
+ end
+
+ context "with two requirements" do
+ let(:ruby_version) { ">= 2.0.0, < 3.0" }
+ it "raises an error" do
+ expect { subject }.to raise_error(Gem::Requirement::BadRequirementError)
+ end
+ end
+
+ context "with no options hash" do
+ let(:invoke) { proc { dsl.ruby(ruby_version) } }
+
+ let(:patchlevel) { nil }
+ let(:engine) { "ruby" }
+ let(:engine_version) { version }
+
+ it_behaves_like "it stores the ruby version"
+ end
+ end
+end
diff --git a/spec/bundler/ruby_version_spec.rb b/spec/bundler/ruby_version_spec.rb
index 9c9eda04dc..e8d308a2c8 100644
--- a/spec/bundler/ruby_version_spec.rb
+++ b/spec/bundler/ruby_version_spec.rb
@@ -115,12 +115,22 @@ describe "Bundler::RubyVersion and its subclasses" do
end
describe "#gem_version" do
- let(:gem_version_obj) { Gem::Version.new(version) }
-
- it "should return a Gem::Version instance with the correct version" do
- expect(ruby_version.gem_version).to eq(gem_version_obj)
- expect(ruby_version.gem_version.version).to eq("2.0.0")
+ let(:gem_version) { "2.0.0" }
+ let(:gem_version_obj) { Gem::Version.new(gem_version) }
+
+ shared_examples_for "it parses the version from the requirement string" do |version|
+ let(:version) { version }
+ it "should return the underlying version" do
+ expect(ruby_version.gem_version).to eq(gem_version_obj)
+ expect(ruby_version.gem_version.version).to eq(gem_version)
+ end
end
+
+ it_behaves_like "it parses the version from the requirement string", "2.0.0"
+ it_behaves_like "it parses the version from the requirement string", ">= 2.0.0"
+ it_behaves_like "it parses the version from the requirement string", "~> 2.0.0"
+ it_behaves_like "it parses the version from the requirement string", "< 2.0.0"
+ it_behaves_like "it parses the version from the requirement string", "= 2.0.0"
end
describe "#diff" do