Sha256: b3f7c481bf96286b21d8b70f82204a5e0a15af52f97ce72634da7c15eb2c0e5e

Contents?: true

Size: 1.93 KB

Versions: 1

Compression:

Stored size: 1.93 KB

Contents

# -*- coding: utf-8 -*-
require File.join(File.dirname(__FILE__), "..", "spec_helper")

describe DirTreeWalker do

  it "should ignore files and directory" do
    dtp = DirTreeWalker.new(".")

    dtp.ignore(/^\./)
    dtp.ignore_file?(".thumbnails").should be_true
    dtp.ignore_dir?(".thumbnails").should be_true

    dtp.ignore_dir("thumbnails")
    dtp.ignore_dir?(".thumbnails").should be_true
    dtp.ignore_dir?("thumbnails").should be_true
    dtp.ignore_dir?("pippo").should be_false

    dtp.ignore_file("xvpics")
    dtp.ignore_file?("xvpics").should be_true

    dtp.ignore("sub")
    dtp.ignore_file?("[Dsube]").should be_false
    dtp.ignore_dir?("[Dsube]").should be_false
  end

  it "should accept option :ignore" do
    dtp = DirTreeWalker.new :ignore => /^\./

    dtp.ignore_file?(".thumbnails").should be_true
    dtp.ignore_dir?(".thumbnails").should be_true
  end

  it "should accept option :ignore" do
    dtp = DirTreeWalker.new :ignore => ".git"

    dtp.ignore_file?(".git").should be_true
    dtp.ignore_dir?(".git").should be_true
  end

  it "should accumulate file names" do
    dir_tree_walker = DirTreeWalker.new(File.join(FIXTURES, "test_dir_1"))

    accumulator     = []
    visitor         = BlockTreeNodeVisitor.new { |pathname| accumulator << File.basename(pathname) }
    dir_tree_walker.run(visitor)
    accumulator.length.should == 9
    accumulator.sort.should == %w{ test_dir_1 dir.1 dir.1.2 file.1.2.1 file.1.1 dir.2 file.2.1 .dir_with_dot dummy.txt }.sort
  end

  it "should accumulate file names 2" do
    dir_tree_walker = DirTreeWalker.new(File.join(FIXTURES, "test_dir_2"))
    dir_tree_walker.ignore("sub")

    accumulator = []
    visitor     = BlockTreeNodeVisitor.new { |pathname| accumulator << File.basename(pathname) }
    dir_tree_walker.run(visitor)
    accumulator.length.should == 2
    accumulator.sort.should == %w{ [Dsube] test_dir_2 }.sort
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
treevisitor-0.1.6 spec/treevisitor/directory_walker_spec.rb