Merge pull request #10191 from fnordfish/feature/ask_version_match

add `Vagrant.version?` helper method
This commit is contained in:
Brian Cain 2018-09-07 10:36:38 -07:00 committed by GitHub
commit 798c673408
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 2 deletions

View File

@ -195,6 +195,17 @@ module Vagrant
puts "be removed in the next version of Vagrant."
end
# This checks if Vagrant is installed in a specific version.
#
# Example:
#
# Vagrant.version?(">= 2.1.0")
#
def self.version?(*requirements)
req = Gem::Requirement.new(*requirements)
req.satisfied_by?(Gem::Version.new(VERSION))
end
# This allows a Vagrantfile to specify the version of Vagrant that is
# required. You can specify a list of requirements which will all be checked
# against the running Vagrant version.
@ -211,8 +222,7 @@ module Vagrant
logger = Log4r::Logger.new("vagrant::root")
logger.info("Version requirements from Vagrantfile: #{requirements.inspect}")
req = Gem::Requirement.new(*requirements)
if req.satisfied_by?(Gem::Version.new(VERSION))
if version?(*requirements)
logger.info(" - Version requirements satisfied!")
return
end

View File

@ -101,6 +101,16 @@ describe Vagrant do
end
end
describe "version?" do
it "should succeed if valid range" do
expect(described_class.version?(Vagrant::VERSION)).to be(true)
end
it "should not succeed if bad range" do
expect(described_class.version?("> #{Vagrant::VERSION}")).to be(false)
end
end
describe "original_env" do
before do
ENV["VAGRANT_OLD_ENV_foo"] = "test"