Sha256: 3b6526e54059ba093403bbf4aebafe94be7fa8cccdd1d3ab9e65be759389b441

Contents?: true

Size: 663 Bytes

Versions: 3

Compression:

Stored size: 663 Bytes

Contents

require 'tmpdir'

class TempDir
  attr_accessor :path

  def initialize(root, subpath)
    @path = File.join(root, subpath)
    Dir.mkdir(@path)
  end

  def tree
    #`cd #{@path}; tree -pugAD`
    #`cd #{@path}; find . -printf "%A@ %p\n"`
    `cd #{@path}; find . -printf "%p\n"`
  end

  def mkdir(path)
    Dir.mkdir(File.join(@path, path))
  end

  def file(path, contents)
    filename = File.join(@path, path)
    File.open(filename, 'w') {|f| f.write(contents)}
    filename
  end

  def eql? other
    tree == other.tree
  end

  def to_s
    tree
  end

  def self.create(&block)
    Dir.mktmpdir do |dir|
      yield new(dir, "test")
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
hosts_file-1.0.3 spec/spec_helper.rb
hosts_file-0.0.2 spec/spec_helper.rb
hosts_file-0.0.1 spec/spec_helper.rb