Sha256: e3b9f2d088db41cb1e0c1cfcf7aea23eb0773ae0c112622b95fd8b931b9d3e54

Contents?: true

Size: 750 Bytes

Versions: 1

Compression:

Stored size: 750 Bytes

Contents

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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
pluginscan-0.9.0 spec/support/file_helpers.rb