forked from ttilley/fssm
/
path_spec.rb
75 lines (62 loc) · 2.25 KB
/
path_spec.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
68
69
70
71
72
73
74
75
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
describe "The File System State Monitor" do
describe "paths" do
it "should accept a valid filesystem directory" do
lambda {FSSM::Path.new("#{@watch_root}")}.should_not raise_error
end
it "should not accept an invalid filesystem directory" do
lambda {FSSM::Path.new('/does/not/exist/kthxbye')}.should raise_error
end
it "should default the path to the current directory" do
path = FSSM::Path.new
here = Pathname.new('.').realpath
"#{here}".should == "#{path}"
end
it "should accept an optional glob array parameter" do
path = FSSM::Path.new('.', ['**/*.yml'])
path.glob.should == ['**/*.yml']
end
it "should accept an optional glob string parameter" do
path = FSSM::Path.new('.', '**/*.yml')
path.glob.should == ['**/*.yml']
end
it "should default the glob to ['**/*']" do
path = FSSM::Path.new
path.glob.should == ['**/*']
end
it "should accept a callback for update events" do
path = FSSM::Path.new
callback = lambda {|base, relative| return true}
path.update(callback)
(path.update).should == callback
end
it "should accept a callback for delete events" do
path = FSSM::Path.new
callback = lambda {|base, relative| return true}
path.delete(callback)
(path.delete).should == callback
end
it "should accept a callback for create events" do
path = FSSM::Path.new
callback = lambda {|base, relative| return true}
path.create(callback)
(path.create).should == callback
end
it "should accept a configuration block" do
path = FSSM::Path.new "#{@watch_root}" do
glob '**/*.yml'
update {|base, relative| 'success'}
delete {|base, relative| 'success'}
create {|base, relative| 'success'}
end
"#{path}".should == "#{@watch_root}"
path.glob.should == ['**/*.yml']
path.update.should be_a_kind_of(Proc)
path.delete.should be_a_kind_of(Proc)
path.create.should be_a_kind_of(Proc)
path.update.call('', '').should == 'success'
path.delete.call('', '').should == 'success'
path.create.call('', '').should == 'success'
end
end
end