require 'fileutils' module FileHelpers def setup_tempdir(name = 'tmp') FileUtils.rm_rf(name) FileUtils.mkdir(name) end def add_non_php_file(tempdir = 'tmp') FileUtils.touch("#{tempdir}/file#{rand(999)}.html") end def add_php_file(base_path = 'tmp', contents = nil, name = nil) name ||= "file#{rand(999)}.php" path = "#{base_path}/#{name}" create_file(path, contents) path end def create_file(path, contents) return create_empty_file(path) unless contents file = File.new(path, 'w') file.write(contents) file.close end def create_empty_file(path) FileUtils.touch(path) end def add_directory(tempdir = 'tmp', name = 'foo') FileUtils.mkdir("#{tempdir}/#{name}") end end