diff --git a/lib/vagrant/box_collection.rb b/lib/vagrant/box_collection.rb index 6e83ad4ee..24e1c7124 100644 --- a/lib/vagrant/box_collection.rb +++ b/lib/vagrant/box_collection.rb @@ -276,17 +276,16 @@ module Vagrant next if versiondir.basename.to_s.start_with?(".") version = versiondir.basename.to_s - Gem::Version.new(version) end.compact # Traverse through versions with the latest version first versions.sort.reverse.each do |v| - if !requirements.all? { |r| r.satisfied_by?(v) } + if !requirements.all? { |r| r.satisfied_by?(Gem::Version.new(v)) } # Unsatisfied version requirements next end - versiondir = box_directory.join(v.to_s) + versiondir = box_directory.join(v) providers.each do |provider| provider_dir = versiondir.join(provider.to_s) next if !provider_dir.directory? @@ -303,7 +302,7 @@ module Vagrant end return Box.new( - name, provider, v.to_s, provider_dir, + name, provider, v, provider_dir, metadata_url: metadata_url, ) end diff --git a/test/unit/vagrant/box_collection_test.rb b/test/unit/vagrant/box_collection_test.rb index f0e5e0edc..21a39ae70 100644 --- a/test/unit/vagrant/box_collection_test.rb +++ b/test/unit/vagrant/box_collection_test.rb @@ -194,6 +194,19 @@ describe Vagrant::BoxCollection, :skip_windows do expect(result.version).to eq("1.0") end + it "handles prerelease versions" do + # Create the "box" + environment.box3("foo", "0.1.0-alpha.1", :virtualbox) + environment.box3("foo", "0.1.0-alpha.2", :virtualbox) + + # Actual test + result = subject.find("foo", :virtualbox, ">= 0") + expect(result).to_not be_nil + expect(result).to be_kind_of(box_class) + expect(result.name).to eq("foo") + expect(result.version).to eq("0.1.0-alpha.2") + end + it "returns nil if a box's constraints can't be satisfied" do # Create the "box" environment.box3("foo", "0.1", :virtualbox)