RSpec was chosen to be used for acceptance tests for many reasons: * The tests are actually much cleaner now. It is clearer to see what is being tested, and what is being used for setup. * Matcher transition will be coming soon. This will really clean up a lot of the "assert" boilerplate all over. There was a lot of repetition in this area. * Shared examples will help greatly for testing common error cases for many commands. * The test runner for RSpec is simply much better. Being able to specify the exact test to run by line, for example, is a great help.
35 lines
697 B
Ruby
35 lines
697 B
Ruby
require 'fileutils'
|
|
require 'tempfile'
|
|
|
|
# This class provides an easy way of creating a temporary
|
|
# directory and having it removed when the application exits.
|
|
#
|
|
# TODO: This class doesn't currently delete the temporary
|
|
# directory on exit.
|
|
class Tempdir
|
|
attr_reader :path
|
|
|
|
def initialize(basename="vagrant")
|
|
@path = nil
|
|
|
|
# Loop and attempt to create a temporary directory until
|
|
# it succeeds.
|
|
while @path.nil?
|
|
file = Tempfile.new(basename)
|
|
@path = file.path
|
|
file.unlink
|
|
|
|
begin
|
|
Dir.mkdir(@path)
|
|
rescue
|
|
@path = nil
|
|
end
|
|
end
|
|
end
|
|
|
|
# This deletes the temporary directory.
|
|
def unlink
|
|
FileUtils.rm_rf(@path)
|
|
end
|
|
end
|