Sha256: 225930cfaf726375f66f02f55a3fc08754bc77a0f779b4c15cabdcce60ccc66b

Contents?: true

Size: 1.23 KB

Versions: 5

Compression:

Stored size: 1.23 KB

Contents

require '../test_helper'
require 'test/unit'
require 'tempfile'
require 'tmpdir'
require 'fileutils'
require 'grizzled/fileutil'

include Grizzled::FileUtil

class MakeDirTreeTester < Test::Unit::TestCase
  include GrizzledTestHelper

  def test_make_directory_tree
    tree = {"bmc" => {"moe" => {"a" => "aaaaaaaaaa",
                                "b" => "bbbbbbbbb"},
                      "larry" => "larry",
                      "curley" => "curley"}}
    Dir.mktmpdir('ziptest') do |tmpdir|
      make_directory_tree(tmpdir, tree)

      # Now, reload the directory tree, and ensure that the tree
      # matches what we created.
      new_tree = {}
      FileUtils.cd tmpdir do
        new_tree = dir_to_hash "bmc"
      end

      assert_equal tree, new_tree
    end
  end

  private

  def dir_to_hash(dir)

    def load_dir_hash(dir)
      h = {}
      Dir.new(dir).entries.each do |dirent|
        if dirent[0..0] != '.'
          path = File.join(dir, dirent)
          if File.directory? path
            FileUtils.cd dir do
              h[dirent] = load_dir_hash(dirent)
            end
          else
            h[dirent] = File.open(path).read
          end
        end
      end
      h
    end

    {dir => load_dir_hash(dir)}
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
grizzled-ruby-0.1.9 test/fileutil/tc_make_dir_tree.rb
grizzled-ruby-0.1.8 test/fileutil/tc_make_dir_tree.rb
grizzled-ruby-0.1.7 test/fileutil/tc_make_dir_tree.rb
grizzled-ruby-0.1.4 test/fileutil/tc_make_dir_tree.rb
grizzled-ruby-0.1.3 test/fileutil/tc_make_dir_tree.rb