blob: a36817fb4eaecbcd1070251a8ce34c23bd7e4b33 (
plain)
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
|
module FileSpecs
def self.configure_types
return if @configured
@file = tmp("test.txt")
@dir = Dir.pwd
@fifo = tmp("test_fifo")
@link = tmp("test_link")
platform_is_not :windows do
@block = `find /dev /devices -type b 2>/dev/null`.split("\n").first
@char = `{ tty || find /dev /devices -type c; } 2>/dev/null`.split("\n").last
end
@configured = true
end
def self.normal_file
touch(@file)
yield @file
ensure
rm_r @file
end
def self.directory
yield @dir
end
def self.fifo
File.mkfifo(@fifo)
yield @fifo
ensure
rm_r @fifo
end
def self.block_device
raise "Could not find a block device" unless @block
yield @block
end
def self.character_device
raise "Could not find a character device" unless @char
yield @char
end
def self.symlink
touch(@file)
File.symlink(@file, @link)
yield @link
ensure
rm_r @file, @link
end
def self.socket
require 'socket'
name = tmp("ftype_socket.socket")
rm_r name
socket = UNIXServer.new name
begin
yield name
ensure
socket.close
rm_r name
end
end
end
|