1
1
require File . expand_path ( '../../teststrap' , __FILE__ )
2
2
3
- context "DAV::FileStorage" do
4
- URI = Addressable ::URI
3
+ module FileStorageTest
4
+ context "DAV::FileStorage" do
5
+ URI = Addressable ::URI
5
6
6
- root = File . join Dir . tmpdir
7
+ root = File . join Dir . tmpdir
7
8
8
- key = 'example.com/foo bar/baz'
9
- encoded_key = URI . encode_component key , URI ::CharacterClasses ::PATH
9
+ key = 'example.com/foo bar/baz'
10
+ encoded_key = URI . encode_component key , URI ::CharacterClasses ::PATH
10
11
11
- path = File . join key . split ( '/' )
12
+ path = File . join key . split ( '/' )
12
13
13
- setup { DAV ::FileStorage }
14
+ setup { DAV ::FileStorage }
14
15
15
- context "without prefix" do
16
- setup { topic . new }
16
+ context "without prefix" do
17
+ setup { topic . new }
17
18
18
- asserts 'get on non-existing key' do
19
- topic . get key
20
- end . nil
19
+ asserts 'get on non-existing key' do
20
+ topic . get key
21
+ end . nil
21
22
22
- asserts 'delete on non-existing key' do
23
- topic . delete key
24
- end . nil
23
+ asserts 'delete on non-existing key' do
24
+ topic . delete key
25
+ end . nil
25
26
26
- asserts '@memory' do
27
- topic . memory
28
- end . kind_of Pathname
27
+ asserts '@memory' do
28
+ topic . memory
29
+ end . kind_of Pathname
29
30
30
- asserts 'set on key' do
31
- topic . set key , 'value-1'
32
- end . equals 'value-1'
31
+ asserts 'set on key' do
32
+ topic . set key , 'value-1'
33
+ end . equals 'value-1'
33
34
34
- asserts 'stores values in files in tmp dir' do
35
- File . file? File . join ( root , 'file_storage.rb' , path )
36
- end
37
-
38
- asserts 'get on existing key' do
39
- topic . set key , 'value-2'
40
- topic . get key
41
- end . equals 'value-2'
35
+ asserts 'stores values in files in tmp dir' do
36
+ File . file? File . join ( root , 'file_storage.rb' , path )
37
+ end
42
38
43
- asserts '#keys' do
44
- topic . keys
45
- end . equals [ key ]
39
+ asserts 'get on existing key' do
40
+ topic . set key , 'value-2'
41
+ topic . get key
42
+ end . equals 'value-2'
46
43
47
- denies '#keys with pattern "/foo"' do
48
- topic . keys '/foo'
49
- end . any
50
- asserts '#keys with pattern "example.com/*"' do
51
- topic . keys 'example.com/*'
52
- end . equals [ key ]
44
+ asserts '#keys' do
45
+ topic . keys
46
+ end . equals [ key ]
53
47
54
- asserts 'delete on existing key' do
55
- topic . set key , 'value-3'
56
- topic . delete key
57
- end . equals 'value-3'
48
+ asserts '#keys with pattern "/foo"' do
49
+ topic . keys '/foo'
50
+ end . empty
51
+ asserts '#keys with pattern "example.com/*"' do
52
+ topic . keys 'example.com/*'
53
+ end . equals [ key ]
58
54
59
- asserts 'get a nil value ' do
60
- topic . set key , nil
61
- topic . get key
62
- end . nil
55
+ asserts 'delete on existing key ' do
56
+ topic . set key , 'value-3'
57
+ topic . delete key
58
+ end . equals 'value-3'
63
59
64
- asserts 'get on deleted key' do
65
- topic . get key
66
- end . nil
60
+ asserts 'get a nil value' do
61
+ topic . set key , nil
62
+ topic . get key
63
+ end . nil
67
64
68
- end
65
+ asserts 'get on deleted key' do
66
+ topic . get key
67
+ end . nil
69
68
70
- context "with prefix" do
71
- setup do
72
- topic . new :prefix => 'DELETE-ME'
73
69
end
74
70
75
- asserts 'creates DELETE-ME dir in current working dir' do
76
- full_path = File . join Dir . tmpdir , 'DELETE-ME'
71
+ context "with prefix" do
72
+ setup do
73
+ topic . new :prefix => 'DELETE-ME'
74
+ end
75
+
76
+ asserts 'creates DELETE-ME dir in current working dir' do
77
+ full_path = File . join Dir . tmpdir , 'DELETE-ME'
77
78
78
- File . directory? ( full_path ) . tap do |exist |
79
- FileUtils . rmtree full_path if exist
79
+ File . directory? ( full_path ) . tap do |exist |
80
+ FileUtils . rmtree full_path if exist
81
+ end
80
82
end
81
- end
82
83
83
- end
84
+ end
84
85
85
- context "with root" do
86
- setup { topic . new :root => File . join ( root , 'DELETE-ME' ) }
86
+ context "with root" do
87
+ setup { topic . new :root => File . join ( root , 'DELETE-ME' ) }
87
88
88
- asserts ' creates DELETE-ME-TOO dir in root' do
89
- full_path = File . join root , 'DELETE-ME'
89
+ asserts " creates DELETE-ME dir in #{ root } " do
90
+ full_path = File . join root , 'DELETE-ME'
90
91
91
- File . directory? ( full_path ) . tap do |exist |
92
- FileUtils . rmtree full_path if exist
92
+ File . directory? ( full_path ) . tap do |exist |
93
+ FileUtils . rmtree full_path if exist
94
+ end
93
95
end
96
+
94
97
end
95
98
96
99
end
97
-
98
- end
100
+ end
0 commit comments