Additional fixes + tests for shell expansion [GH-633]

This commit is contained in:
Mitchell Hashimoto 2012-01-11 22:56:15 -08:00
parent 9a242ba718
commit f0b77d2f30
2 changed files with 38 additions and 1 deletions

View File

@ -6,7 +6,7 @@ module Vagrant
# simply does a file copy.
class File < Base
def self.match?(uri)
::File.exists?(uri)
::File.file?(::File.expand_path(uri))
end
def prepare(source_url)

View File

@ -1,5 +1,7 @@
require File.expand_path("../../../base", __FILE__)
require "tempfile"
describe Vagrant::Downloaders::File do
let(:ui) { double("ui") }
let(:instance) { described_class.new(ui) }
@ -12,6 +14,23 @@ describe Vagrant::Downloaders::File do
it "should not match non-existent files" do
described_class.match?(File.join(__FILE__, "nowaywaywaywayayway")).should_not be
end
it "should match files where the path needs to be expanded" do
old_home = ENV["HOME"]
begin
# Create a temporary file
temp = Tempfile.new("vagrant")
# Set our home directory to be this directory so we can use
# "~" paths
ENV["HOME"] = File.dirname(temp.path)
# Test that we can find the temp file
described_class.match?("~/#{File.basename(temp.path)}").should be
ensure
ENV["HOME"] = old_home
end
end
end
describe "preparing" do
@ -28,6 +47,24 @@ describe Vagrant::Downloaders::File do
expect { instance.prepare(path) }.to raise_error(Vagrant::Errors::DownloaderFileDoesntExist)
end
it "should find files that use shell expansions" do
old_home = ENV["HOME"]
begin
# Create a temporary file
temp = Tempfile.new("vagrant")
# Set our home directory to be this directory so we can use
# "~" paths
ENV["HOME"] = File.dirname(temp.path)
# Test that we can find the temp file
expect { instance.prepare("~/#{File.basename(temp.path)}") }.
to_not raise_error
ensure
ENV["HOME"] = old_home
end
end
end
describe "downloading" do