File: directory.rb

package info (click to toggle)
jruby 1.7.26-1%2Bdeb9u1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 84,572 kB
  • sloc: ruby: 669,910; java: 253,056; xml: 35,152; ansic: 9,187; yacc: 7,267; cpp: 5,244; sh: 1,036; makefile: 345; jsp: 48; tcl: 40
file content (74 lines) | stat: -rw-r--r-- 1,863 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
describe :file_directory, :shared => true do
  before :each do
    @dir = tmp("file_directory")
    @file = tmp("file_directory.txt")

    mkdir_p @dir
    touch @file
  end

  after :each do
    rm_r @dir, @file
  end

  it "return true if the argument is a directory" do
    @object.send(@method, @dir).should be_true
  end

  it "returns false if the argument is not a directory" do
    @object.send(@method, @file).should be_false
  end

  ruby_version_is "1.9" do
    it "accepts an object that has a #to_path method" do
      @object.send(@method, mock_to_path(@dir)).should be_true
    end
  end

  it "raises a TypeError when passed an Integer" do
    lambda { @object.send(@method, 1) }.should raise_error(TypeError)
    lambda { @object.send(@method, bignum_value) }.should raise_error(TypeError)
  end

  it "raises a TypeError when passed nil" do
    lambda { @object.send(@method, nil) }.should raise_error(TypeError)
  end
end

describe :file_directory_io, :shared => true do
  before :each do
    @dir = tmp("file_directory_io")
    @file = tmp("file_directory_io.txt")

    mkdir_p @dir
    touch @file
  end

  after :each do
    rm_r @dir, @file
  end

  it "returns false if the argument is an IO that's not a directory" do
    @object.send(@method, STDIN).should be_false
  end

  it "return true if the argument is an IO that is a directory" do
    File.open(@dir, "r") do |f|
      @object.send(@method, f).should be_true
    end
  end

  it "calls #to_io to convert a non-IO object" do
    io = mock('FileDirectoryIO')
    io.should_receive(:to_io).and_return(STDIN)
    @object.send(@method, io).should be_false
  end

  ruby_version_is ""..."1.9" do
    it "raises a TypeError when passed a Dir instance" do
      Dir.open(@dir) do |d|
        lambda { @object.send(@method, d) }.should raise_error(TypeError)
      end
    end
  end
end