File: path_spec.rb

package info (click to toggle)
ruby-fssm 0.2.10-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 380 kB
  • sloc: ruby: 1,082; makefile: 2
file content (96 lines) | stat: -rw-r--r-- 3,264 bytes parent folder | download | duplicates (6)
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
require "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 accept an optional option parameter" do
      lambda { FSSM::Path.new('.', '**/*.yml', :foo => :bar) }.should_not raise_error
    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

    it "should pass file type to callbacks as the third argument if :directories option is used" do
      path = FSSM::Path.new "#{@watch_root}", nil, :directories => true do
        glob '**/*.yml'
        update { |base, relative, type| [base, relative, type] }
        delete { |base, relative, type| [base, relative, type] }
        create { |base, relative, type| [base, relative, type] }
      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('b', 'r', 't').should == ['b', 'r', 't']
      path.delete.call('b', 'r', 't').should == ['b', 'r', 't']
      path.create.call('b', 'r', 't').should == ['b', 'r', 't']
    end
  end
end