-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathconstruct_test.rb
67 lines (55 loc) · 1.56 KB
/
construct_test.rb
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
require 'test_helper'
require 'tmpdir'
require 'English'
require 'construct'
class ConstructTest < Test::Unit::TestCase
include Construct
# add boolean flag to determine whether to switch into construct dir or not
testing "creating a construct container" do
test "should exist" do
within_construct do
assert File.directory?(File.join(Dir.tmpdir, "construct_container#{$PROCESS_ID}"))
end
end
test "should yield to its block" do
sensor = "no yield"
within_construct do
sensor = "yielded"
end
assert_equal "yielded", sensor
end
test "block argument should be container directory Pathname" do
within_construct do |container_path|
assert_equal((Pathname(Dir.tmpdir)+"construct_container#{$PROCESS_ID}"), container_path)
end
end
test "should not exist afterwards" do
path = nil
within_construct do |container_path|
path = container_path
end
assert !path.exist?
end
test "should remove entire tree afterwards" do
path = nil
within_construct do |container_path|
path = container_path
(container_path + "foo").mkdir
end
assert !path.exist?
end
test "should remove dir if block raises exception" do
path = nil
begin
within_construct do |container_path|
path = container_path
raise "something bad happens here"
end
rescue
end
assert !path.exist?
end
test "should not capture exceptions raised in block" do
end
end
end