social_snippet 0.0.9 → 0.0.10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (70) hide show
  1. checksums.yaml +8 -8
  2. data/.travis.yml +11 -4
  3. data/README.md +6 -6
  4. data/Rakefile +19 -1
  5. data/lib/social_snippet.rb +11 -0
  6. data/lib/social_snippet/api/install_repository_api.rb +23 -82
  7. data/lib/social_snippet/api/manifest_api.rb +3 -3
  8. data/lib/social_snippet/api/update_repository_api.rb +34 -35
  9. data/lib/social_snippet/command_line/sspm/sub_commands/install_command.rb +7 -7
  10. data/lib/social_snippet/config.rb +18 -8
  11. data/lib/social_snippet/core.rb +13 -0
  12. data/lib/social_snippet/document.rb +2 -0
  13. data/lib/social_snippet/document_backend.rb +2 -0
  14. data/lib/social_snippet/document_backend/yaml_document.rb +252 -0
  15. data/lib/social_snippet/document_backend/yaml_document/query.rb +45 -0
  16. data/lib/social_snippet/repository.rb +2 -2
  17. data/lib/social_snippet/repository/driver_factory.rb +42 -0
  18. data/lib/social_snippet/repository/drivers.rb +3 -2
  19. data/lib/social_snippet/repository/drivers/driver_base.rb +100 -0
  20. data/lib/social_snippet/repository/drivers/entry.rb +11 -0
  21. data/lib/social_snippet/repository/drivers/git_driver.rb +100 -0
  22. data/lib/social_snippet/repository/models.rb +15 -0
  23. data/lib/social_snippet/repository/models/package.rb +97 -0
  24. data/lib/social_snippet/repository/models/repository.rb +94 -0
  25. data/lib/social_snippet/repository/repository_manager.rb +79 -67
  26. data/lib/social_snippet/resolvers/base_resolver.rb +13 -17
  27. data/lib/social_snippet/rspec/test_document.rb +305 -0
  28. data/lib/social_snippet/rspec/test_driver.rb +76 -0
  29. data/lib/social_snippet/rspec/test_storage.rb +459 -0
  30. data/lib/social_snippet/storage.rb +1 -0
  31. data/lib/social_snippet/storage_backend.rb +3 -0
  32. data/lib/social_snippet/storage_backend/file_system_storage.rb +71 -0
  33. data/lib/social_snippet/storage_backend/storage_base.rb +35 -0
  34. data/lib/social_snippet/version.rb +8 -3
  35. data/spec/helpers/codeclimate_helper.rb +1 -1
  36. data/spec/helpers/fakefs_helper.rb +10 -0
  37. data/spec/helpers/social_snippet_helper.rb +117 -0
  38. data/spec/lib/api/insert_snippet_spec.rb +95 -2
  39. data/spec/lib/api/update_repository_spec.rb +196 -0
  40. data/spec/lib/command_line/sspm_install_spec.rb +169 -180
  41. data/spec/lib/command_line/sspm_update_spec.rb +56 -0
  42. data/spec/lib/config_spec.rb +6 -8
  43. data/spec/lib/core_spec.rb +21 -38
  44. data/spec/lib/file_system_storage_spec.rb +170 -0
  45. data/spec/lib/insert_resolver_spec.rb +15 -2
  46. data/spec/lib/registry_client_spec.rb +6 -9
  47. data/spec/lib/repository/driver_base_spec.rb +89 -0
  48. data/spec/lib/repository/git_driver_spec.rb +10 -0
  49. data/spec/lib/repository/package_spec.rb +172 -0
  50. data/spec/lib/repository/repository_factory_spec.rb +67 -22
  51. data/spec/lib/repository/repository_manager_spec.rb +71 -114
  52. data/spec/lib/repository/repository_spec.rb +191 -0
  53. data/spec/lib/yaml_document_spec.rb +14 -0
  54. data/spec/spec_helper.rb +8 -93
  55. data/test/config_test.rb +6 -7
  56. data/test/driver_base_test.rb +201 -0
  57. data/test/git_driver_test.rb +51 -0
  58. data/test/insert_snippet_test.rb +256 -349
  59. data/test/repository_manager_test.rb +7 -16
  60. data/test/yaml_document_test.rb +97 -0
  61. metadata +44 -16
  62. data/lib/social_snippet/repository/drivers/base_repository.rb +0 -189
  63. data/lib/social_snippet/repository/drivers/git_repository.rb +0 -74
  64. data/lib/social_snippet/repository/repository_factory.rb +0 -59
  65. data/lib/social_snippet/repository/repository_installer.rb +0 -85
  66. data/spec/lib/repository/base_repository_spec.rb +0 -104
  67. data/spec/lib/repository/git_repository_spec.rb +0 -83
  68. data/spec/lib/repository/repository_installer_spec.rb +0 -63
  69. data/test/base_repository_test.rb +0 -375
  70. data/test/git_repository_test.rb +0 -114
@@ -32,7 +32,6 @@ module SocialSnippet
32
32
  move_context_by_tag! new_context, t
33
33
  overwrite_tag_in_same_repository! new_context, t
34
34
  update_tag_path_by_context! new_context, t
35
- resolve_tag_repo_ref! t
36
35
  end
37
36
 
38
37
  resolve_tag_repo_ref! t
@@ -47,13 +46,6 @@ module SocialSnippet
47
46
 
48
47
  private
49
48
 
50
- def resolve_tag_repo_ref!(t)
51
- if t.has_repo?
52
- repo = core.repo_manager.find_repository_by_tag(t)
53
- t.set_ref repo.latest_version(t.ref)
54
- end
55
- end
56
-
57
49
  def move_context_by_tag!(context, tag)
58
50
  if tag.has_repo?
59
51
  if tag.has_ref?
@@ -83,16 +75,20 @@ module SocialSnippet
83
75
 
84
76
  # Resolve tag's ref
85
77
  def resolve_tag_repo_ref!(tag)
86
- repo = core.repo_manager.find_repository_by_tag(tag)
87
-
88
- # not found
89
- return if repo.nil?
90
-
91
- if tag.has_ref? === false || tag.ref != repo.latest_version(tag.ref)
92
- if repo.has_versions?
93
- tag.set_ref repo.latest_version(tag.ref)
78
+ return unless tag.has_repo?
79
+ repo = core.repo_manager.find_repository(tag.repo)
80
+ # set latest version
81
+ if tag.has_ref? === false
82
+ if repo.has_package_versions?
83
+ tag.set_ref repo.latest_package_version
94
84
  else
95
- tag.set_ref repo.short_commit_id
85
+ tag.set_ref repo.current_ref
86
+ end
87
+ else
88
+ unless repo.has_ref?(tag.ref)
89
+ new_ref = repo.latest_version(tag.ref)
90
+ raise "error" if new_ref.nil?
91
+ tag.set_ref new_ref
96
92
  end
97
93
  end
98
94
  end
@@ -0,0 +1,305 @@
1
+ RSpec.configure do
2
+
3
+ shared_context :TestDocument do
4
+
5
+ class TestDocument1 < ::SocialSnippet::Document
6
+ field :field_string, :type => String
7
+ field :field_array, :type => Array, :default => ::Array.new
8
+ field :field_hash, :type => Hash, :default => ::Hash.new
9
+ end
10
+
11
+ class TestDocument2 < ::SocialSnippet::Document
12
+ field :field_string, :type => String
13
+ field :field_array, :type => Array, :default => ::Array.new
14
+ field :field_hash, :type => Hash, :default => ::Hash.new
15
+ end
16
+
17
+ describe "find by regexp" do
18
+
19
+ context "create items" do
20
+
21
+ before do
22
+ TestDocument1.create :field_string => "a"
23
+ TestDocument1.create :field_string => "A"
24
+ TestDocument1.create :field_string => "abc"
25
+ TestDocument1.create :field_string => "b"
26
+ TestDocument1.create :field_string => "bc"
27
+ TestDocument1.create :field_string => "c"
28
+ end
29
+
30
+ context "where /^a/" do
31
+
32
+ let(:result) { TestDocument1.where :field_string => /^a/ }
33
+
34
+ context "map result" do
35
+ subject do
36
+ result.map {|item| item.field_string }
37
+ end
38
+ it { should include "a" }
39
+ it { should_not include "A" }
40
+ it { should include "abc" }
41
+ it { should_not include "b" }
42
+ it { should_not include "bc" }
43
+ it { should_not include "c" }
44
+ end
45
+
46
+ end
47
+
48
+ end
49
+
50
+ end # find by regexp
51
+
52
+ describe "#add_to_set" do
53
+
54
+ context "create item" do
55
+
56
+ let(:item) { TestDocument2.create }
57
+ it { expect(item.field_array).to be_empty }
58
+
59
+ context "add_to_set value" do
60
+
61
+ before { item.add_to_set :field_array => "value" }
62
+ it { expect(item.field_array.length).to eq 1 }
63
+ it { expect(item.field_array).to include "value" }
64
+
65
+ context "add_to_set new_value" do
66
+
67
+ before { item.add_to_set :field_array => "new-value" }
68
+ it { expect(item.field_array.length).to eq 2 }
69
+ it { expect(item.field_array).to include "value" }
70
+ it { expect(item.field_array).to include "new-value" }
71
+
72
+ context "add_to_set value (duplicated value)" do
73
+
74
+ before { item.add_to_set :field_array => "value" }
75
+ it { expect(item.field_array.length).to eq 2 }
76
+ it { expect(item.field_array).to include "value" }
77
+ it { expect(item.field_array).to include "new-value" }
78
+
79
+ context "find item.id" do
80
+
81
+ let(:found_item) { TestDocument2.find(item.id) }
82
+ it { expect(item.field_array.length).to eq 2 }
83
+ it { expect(item.field_array).to include "value" }
84
+ it { expect(item.field_array).to include "new-value" }
85
+
86
+ end
87
+
88
+ end
89
+
90
+ end
91
+
92
+ end
93
+
94
+ end
95
+
96
+ end #add_to_set
97
+
98
+ describe "#update_attributes!" do
99
+
100
+ context "create item" do
101
+ let(:item) { TestDocument1.create :field_string => "value" }
102
+ subject { item.field_string }
103
+ it { should eq "value" }
104
+ context "find item.id" do
105
+ subject { TestDocument1.find item.id }
106
+ it { expect(subject.field_string).to eq "value" }
107
+ end
108
+ context "item.update_attributes! field_string => new-value" do
109
+ before { item.update_attributes! :field_string => "new-value" }
110
+ it { should eq "new-value" }
111
+ context "find item.id" do
112
+ subject { TestDocument1.find item.id }
113
+ it { expect(subject.field_string).to eq "new-value" }
114
+ end
115
+ end
116
+ end
117
+
118
+ end
119
+
120
+ describe "#push" do
121
+
122
+ context "create item" do
123
+
124
+ let(:item) { TestDocument1.create }
125
+ it { expect(item.field_array).to be_empty }
126
+
127
+ context "push item" do
128
+
129
+ before { item.push :field_array => "val" }
130
+ it { expect(item.field_array).to_not be_empty }
131
+ it { expect(item.field_array).to include "val" }
132
+
133
+ context "pull item" do
134
+
135
+ before { item.pull :field_array => "val" }
136
+ it { expect(item.field_array).to be_empty }
137
+
138
+ end
139
+
140
+ end
141
+
142
+ end
143
+
144
+ end #push
145
+
146
+ describe "#count" do
147
+
148
+ subject { TestDocument1.count }
149
+ it { should eq 0 }
150
+
151
+ context "create a item" do
152
+
153
+ before { TestDocument1.create(:field_string => "item") }
154
+ it { should eq 1 }
155
+
156
+ context "find_or_create_by item" do
157
+
158
+ before { TestDocument1.find_or_create_by(:field_string => "item") }
159
+ it { should eq 1 }
160
+
161
+ context "create another item" do
162
+ before { TestDocument1.create(:field_string => "item") }
163
+ it { should eq 2 }
164
+ end
165
+
166
+ end
167
+
168
+ end
169
+
170
+ end
171
+
172
+ describe "#exists?" do
173
+
174
+ subject { TestDocument1.exists? }
175
+ it { should be_falsey }
176
+
177
+ context "TestDocument2.exists?" do
178
+ subject { TestDocument2.exists? }
179
+ it { should be_falsey }
180
+ end
181
+
182
+ context "create a item" do
183
+
184
+ before { TestDocument1.create(:field_string => "item1") }
185
+ it { should be_truthy }
186
+
187
+ context "TestDocument2.exists?" do
188
+ subject { TestDocument2.exists? }
189
+ it { should be_falsey }
190
+ end
191
+
192
+ end # create a item
193
+
194
+ end #exists?
195
+
196
+ describe "#find_by" do
197
+
198
+ context "find_or_create_by :field_string => abc" do
199
+
200
+ before do
201
+ doc = TestDocument1.find_or_create_by(:field_string => "abc")
202
+ doc.field_array.push "val1"
203
+ doc.field_array.push "val2"
204
+ doc.field_array.push "val3"
205
+ doc.field_hash["key"] = "val"
206
+ doc.save!
207
+ end
208
+
209
+ context "find_by :field_string => abc" do
210
+ let(:item) { TestDocument1.find_by :field_string => "abc" }
211
+ it { expect(item.field_string).to eq "abc" }
212
+ it { expect(item.field_array.length).to eq 3 }
213
+ it { expect(item.field_array).to include "val1" }
214
+ it { expect(item.field_array).to include "val2" }
215
+ it { expect(item.field_array).to include "val3" }
216
+ it { expect(item.field_hash["key"]).to include "val" }
217
+ end
218
+
219
+ context "find_by :field_string => not_found" do
220
+ subject do
221
+ lambda { TestDocument1.find_by :field_string => "not_found" }
222
+ end
223
+ it { should raise_error }
224
+ end
225
+
226
+ end
227
+
228
+ end #find_by
229
+
230
+ describe "test field" do
231
+
232
+ let(:doc) do
233
+ TestDocument1.new
234
+ end
235
+
236
+ context "doc.field_string = test" do
237
+ before { doc.field_string = "test" }
238
+ it { expect(doc.field_string).to eq "test" }
239
+ end
240
+
241
+ context "doc.field_array.push item" do
242
+ before { doc.field_array.push "item" }
243
+ it { expect(doc.field_array).to include "item" }
244
+ end
245
+
246
+ context "doc.field_hash[key] = value" do
247
+ before { doc.field_hash["key"] = "value" }
248
+ it { expect(doc.field_hash["key"]).to eq "value" }
249
+ end
250
+
251
+ end # test field
252
+
253
+ describe "test persistence" do
254
+
255
+ context "create item" do
256
+
257
+ before do
258
+ item = TestDocument1.create(:id => "item")
259
+ item.field_string = "this is string"
260
+ item.field_array.push "this is array"
261
+ item.field_hash["key"] = "this is hash"
262
+ item.save!
263
+ end
264
+
265
+ context "check existance" do
266
+ context "TestDocument1.where(:id => item).exists?" do
267
+ subject { TestDocument1.where(:id => "item").exists? }
268
+ it { should be_truthy }
269
+ end
270
+ context "TestDocument2.where(:id => item).exists?" do
271
+ subject { TestDocument2.where(:id => "item").exists? }
272
+ it { should be_falsey }
273
+ end
274
+ end
275
+
276
+ context "find item" do
277
+ context "in document-1" do
278
+ subject { TestDocument1.find "item" }
279
+ it { expect(subject.field_string).to eq "this is string" }
280
+ it { expect(subject.field_array).to include "this is array" }
281
+ it { expect(subject.field_hash["key"]).to eq "this is hash" }
282
+ end
283
+ context "in document-2" do
284
+ example do
285
+ expect { TestDocument2.find "item" }.to raise_error
286
+ end
287
+ end
288
+ end
289
+
290
+ context "remove item" do
291
+ before { TestDocument1.find("item").remove }
292
+ context "re-find item" do
293
+ subject { TestDocument1.where(:id => "item").exists? }
294
+ it { should be_falsey }
295
+ end
296
+ end
297
+
298
+ end # create item
299
+
300
+ end # test persistence
301
+
302
+ end # [shared] TestDocument
303
+
304
+ end
305
+
@@ -0,0 +1,76 @@
1
+ RSpec.configure do
2
+
3
+ # need to set let(:driver_class) { ... }
4
+ shared_context :TestDriver do
5
+
6
+ describe "test driver class", :without_fakefs => true do
7
+
8
+ context "handle github repo" do
9
+
10
+ let(:repo_url) { "git://github.com/social-snippet/example-repo.git" }
11
+
12
+ subject(:driver) do
13
+ driver_class.new repo_url
14
+ end
15
+
16
+ context "driver.fetch" do
17
+
18
+ before { driver.fetch }
19
+
20
+ describe "#each_file" do
21
+ context "get files" do
22
+ let(:files) { ::Hash.new }
23
+ before do
24
+ driver.each_file("1.0.2") do |file|
25
+ files[file.path] = file.data
26
+ end
27
+ end
28
+ context "check files" do
29
+ subject { files }
30
+ it { should include "README.md" }
31
+ it { should include "snippet.json" }
32
+ it { should include "src/func.cpp" }
33
+ it { should include "src/func/sub_func_1.cpp" }
34
+ it { should include "src/func/sub_func_2.cpp" }
35
+ it { should include "src/func/sub_func_3.cpp" }
36
+ it { expect(files["snippet.json"]).to match "example-repo" }
37
+ it { expect(files["src/func/sub_func_1.cpp"]).to match "int sub_func_1()" }
38
+ end
39
+ end
40
+ end
41
+
42
+ describe "#refs" do
43
+ subject { driver.refs }
44
+ it { should include "master" }
45
+ it { should include "1.0.0" }
46
+ it { should include "1.0.1" }
47
+ end #refs
48
+
49
+ describe "#versions" do
50
+ subject { driver.versions }
51
+ it { should_not include "master" }
52
+ it { should include "1.0.0" }
53
+ it { should include "1.0.1" }
54
+ end #versions
55
+
56
+ describe "#latest_version" do
57
+ context "latest_version 1.0" do
58
+ subject { driver.latest_version("1.0") }
59
+ it { should eq "1.0.2" }
60
+ end
61
+ context "latest_version 9.9" do
62
+ subject { driver.latest_version("9.9") }
63
+ it { should eq nil }
64
+ end
65
+ end #latest_version
66
+
67
+ end # driver.fetch
68
+
69
+ end # github repo
70
+
71
+ end #
72
+
73
+ end # [shared] TestDriver
74
+
75
+ end
76
+
@@ -0,0 +1,459 @@
1
+ RSpec.configure do
2
+
3
+ shared_context :TestStorage do
4
+
5
+ describe "test storage class" do
6
+
7
+ let(:storage) { ::SocialSnippet::Storage.new }
8
+
9
+ describe "no entry" do
10
+
11
+ context "read not_found.txt" do
12
+ subject do
13
+ lambda { storage.read "not_found.txt" }
14
+ end
15
+ it { should raise_error ::Errno::ENOENT }
16
+ end
17
+
18
+ context "rm path/to/not_found" do
19
+ subject do
20
+ lambda { storage.rm "path/to/not_found.txt" }
21
+ end
22
+ it { should raise_error ::Errno::ENOENT }
23
+ end
24
+
25
+ context "touch not_found/path/to/file" do
26
+ subject do
27
+ lambda { storage.touch "not_found/path/to/file" }
28
+ end
29
+ it { should raise_error ::Errno::ENOENT }
30
+ end
31
+
32
+ context "rm_r path/to/not_found" do
33
+ subject do
34
+ lambda { storage.rm_r "path/to/not_found" }
35
+ end
36
+ it { should raise_error ::Errno::ENOENT }
37
+ end
38
+
39
+ context "cd path/to/not_found" do
40
+ subject do
41
+ lambda { storage.cd "path/to/not_found" }
42
+ end
43
+ it { should raise_error ::Errno::ENOENT }
44
+ end
45
+
46
+ context "prepare file" do
47
+ before do
48
+ storage.mkdir_p "path/to"
49
+ storage.touch "path/to/file"
50
+ end
51
+ context "cd path/to/file" do
52
+ subject do
53
+ lambda { storage.cd "path/to/file"; p storage.pwd; p storage.file?(storage.pwd) }
54
+ end
55
+ # TODO: it { should raise_error ::Errno::ENOTDIR }
56
+ end
57
+ end
58
+
59
+ end # no entry
60
+
61
+ describe "#glob" do
62
+
63
+ context "prepare storage" do
64
+
65
+ before do
66
+ storage.mkdir_p "/path/to/dir1"
67
+ storage.mkdir_p "/path/to/dir2"
68
+ storage.mkdir_p "/path/to/dir2/subdir1"
69
+ storage.mkdir_p "/path/to/dir2/subdir2"
70
+ storage.mkdir_p "/path/to/dir3"
71
+ storage.touch "/path/to/file1.c"
72
+ storage.touch "/path/to/dir1/file2.c"
73
+ storage.touch "/path/to/dir1/file3.c"
74
+ storage.touch "/path/to/dir2/file4.rb"
75
+ storage.touch "/path/to/dir2/file5.c"
76
+ storage.touch "/path/to/dir3/file6.cpp"
77
+ storage.touch "/path/to/dir2/subdir1/file7.c"
78
+ storage.touch "/path/to/dir2/subdir2/file8.rb"
79
+ end
80
+
81
+ context "glob /path/to/dir1" do
82
+ subject { storage.glob "/path/to/dir1" }
83
+ it { expect(subject.length).to eq 1 }
84
+ it { should include "/path/to/dir1" }
85
+ it { should_not include "/path/to/dir2" }
86
+ it { should_not include "/path/to/dir3" }
87
+ it { should_not include "/path/to/file1.c" }
88
+ end
89
+
90
+ context "glob /path/to/*.c" do
91
+ subject { storage.glob "/path/to/*.c" }
92
+ it { expect(subject.length).to eq 1 }
93
+ it { should_not include "/path/to/" }
94
+ it { should_not include "/path/to/dir2" }
95
+ it { should_not include "/path/to/dir3" }
96
+ it { should include "/path/to/file1.c" }
97
+ it { should_not include "/path/to/dir1/file2.c" }
98
+ it { should_not include "/path/to/dir1/file3.c" }
99
+ it { should_not include "/path/to/dir2/file5.c" }
100
+ it { should_not include "/path/to/dir3/file6.cpp" }
101
+ it { should_not include "/path/to/dir2/subdir1/file7.c" }
102
+ end
103
+
104
+ context "glob /path/to/**/*.c" do
105
+ subject { storage.glob "/path/to/**/*.c" }
106
+ it { expect(subject.length).to eq 5 }
107
+ it { should_not include "/path/to/" }
108
+ it { should_not include "/path/to/dir2" }
109
+ it { should_not include "/path/to/dir3" }
110
+ it { should include "/path/to/file1.c" }
111
+ it { should include "/path/to/dir1/file2.c" }
112
+ it { should include "/path/to/dir1/file3.c" }
113
+ it { should include "/path/to/dir2/file5.c" }
114
+ it { should_not include "/path/to/dir3/file6.cpp" }
115
+ it { should include "/path/to/dir2/subdir1/file7.c" }
116
+ end
117
+
118
+ context "glob /path/to/dir2/**/*.c" do
119
+ subject { storage.glob "/path/to/dir2/**/*.c" }
120
+ it { expect(subject.length).to eq 2 }
121
+ it { should_not include "/path/to/" }
122
+ it { should_not include "/path/to/dir2" }
123
+ it { should_not include "/path/to/dir3" }
124
+ it { should_not include "/path/to/file1.c" }
125
+ it { should_not include "/path/to/dir1/file2.c" }
126
+ it { should_not include "/path/to/dir1/file3.c" }
127
+ it { should include "/path/to/dir2/file5.c" }
128
+ it { should_not include "/path/to/dir3/file6.cpp" }
129
+ it { should include "/path/to/dir2/subdir1/file7.c" }
130
+ end
131
+
132
+ context "glob /path/to/**/*.cpp" do
133
+ subject { storage.glob "/path/to/**/*.cpp" }
134
+ it { expect(subject.length).to eq 1 }
135
+ it { should_not include "/path/to/" }
136
+ it { should_not include "/path/to/dir2" }
137
+ it { should_not include "/path/to/dir3" }
138
+ it { should_not include "/path/to/file1.c" }
139
+ it { should_not include "/path/to/dir1/file2.c" }
140
+ it { should_not include "/path/to/dir1/file3.c" }
141
+ it { should_not include "/path/to/dir2/file5.c" }
142
+ it { should include "/path/to/dir3/file6.cpp" }
143
+ it { should_not include "/path/to/dir2/subdir1/file7.c" }
144
+ end
145
+
146
+ context "glob /path/to/**/*.rb" do
147
+ subject { storage.glob "/path/to/**/*.rb" }
148
+ it { expect(subject.length).to eq 2 }
149
+ it { should_not include "/path/to/" }
150
+ it { should_not include "/path/to/dir2" }
151
+ it { should_not include "/path/to/dir3" }
152
+ it { should_not include "/path/to/file1.c" }
153
+ it { should_not include "/path/to/dir1/file2.c" }
154
+ it { should_not include "/path/to/dir1/file3.c" }
155
+ it { should include "/path/to/dir2/file4.rb" }
156
+ it { should_not include "/path/to/dir2/file5.c" }
157
+ it { should_not include "/path/to/dir3/file6.cpp" }
158
+ it { should_not include "/path/to/dir2/subdir1/file7.c" }
159
+ it { should include "/path/to/dir2/subdir2/file8.rb" }
160
+ end
161
+
162
+ context "glob /path/to/dir2/**/*.rb" do
163
+ subject { storage.glob "/path/to/dir2/**/*.rb" }
164
+ it { expect(subject.length).to eq 2 }
165
+ it { should_not include "/path/to/" }
166
+ it { should_not include "/path/to/dir2" }
167
+ it { should_not include "/path/to/dir3" }
168
+ it { should_not include "/path/to/file1.c" }
169
+ it { should_not include "/path/to/dir1/file2.c" }
170
+ it { should_not include "/path/to/dir1/file3.c" }
171
+ it { should include "/path/to/dir2/file4.rb" }
172
+ it { should_not include "/path/to/dir2/file5.c" }
173
+ it { should_not include "/path/to/dir3/file6.cpp" }
174
+ it { should_not include "/path/to/dir2/subdir1/file7.c" }
175
+ it { should include "/path/to/dir2/subdir2/file8.rb" }
176
+ end
177
+
178
+ end
179
+
180
+ end #glob
181
+
182
+ describe "change workdir" do
183
+
184
+ let!(:root_dir) { storage.pwd }
185
+
186
+ context "mkdir path/to/dir" do
187
+
188
+ subject { storage.pwd }
189
+
190
+ before { storage.mkdir_p "path/to/dir" }
191
+
192
+ context "cd path/to" do
193
+
194
+ before { storage.cd "path/to" }
195
+ it { should eq ::File.join(root_dir, "path", "to") }
196
+
197
+ context "cd ../" do
198
+
199
+ before { storage.cd "../" }
200
+ it { should eq ::File.join(root_dir, "path") }
201
+
202
+ context "storage.cd ./" do
203
+
204
+ before { storage.cd "./" }
205
+ it { should eq ::File.join(root_dir, "path") }
206
+
207
+ context "storage.cd ./to/dir" do
208
+ before { storage.cd "to/dir" }
209
+ it { should eq ::File.join(root_dir, "path", "to", "dir") }
210
+ end
211
+
212
+ end
213
+
214
+ end
215
+
216
+ end
217
+
218
+ context "touch path/to/dir/file" do
219
+ before { storage.touch "path/to/dir/file" }
220
+ context "cd path/to/dir" do
221
+ before { storage.cd "path/to/dir" }
222
+ context "read file" do
223
+ subject { storage.file? "file" }
224
+ it { should be_truthy }
225
+ end
226
+ context "read file from root" do
227
+ before { storage.cd root_dir }
228
+ subject { storage.file? "path/to/dir/file" }
229
+ it { should be_truthy }
230
+ end
231
+ end
232
+ end
233
+
234
+ end # mkdir path/to/dir
235
+
236
+ context "mkdir path" do
237
+
238
+ before { storage.mkdir "path" }
239
+
240
+ context "cd path" do
241
+
242
+ before { storage.cd "path" }
243
+
244
+ context "mkdir to" do
245
+
246
+ before { storage.mkdir "to" }
247
+
248
+ context "cd to" do
249
+
250
+ before { storage.cd "to" }
251
+
252
+ context "mkdir dir" do
253
+
254
+ before { storage.mkdir "dir" }
255
+
256
+ context "cd root" do
257
+
258
+ before { storage.cd root_dir }
259
+
260
+ context "directory? path/to/dir" do
261
+ subject { storage.directory? "path/to/dir" }
262
+ it { should be_truthy }
263
+ end
264
+
265
+ end
266
+
267
+ end
268
+
269
+ context "write file, data" do
270
+
271
+ before { storage.write "file", "data" }
272
+
273
+ context "cd root" do
274
+
275
+ before { storage.cd root_dir }
276
+
277
+ context "read path/to/file" do
278
+ subject { storage.read "path/to/file" }
279
+ it { should eq "data" }
280
+ end
281
+
282
+ end
283
+
284
+ end
285
+
286
+ end
287
+
288
+ end
289
+
290
+ end
291
+
292
+ end
293
+
294
+ end # change workdir
295
+
296
+ describe "duplication" do
297
+
298
+ context "mkdir /lib" do
299
+
300
+ before { storage.mkdir "/lib" }
301
+
302
+ context "touch /lib/entity" do
303
+
304
+ before { storage.touch "/lib/entity" }
305
+
306
+ context "mkdir /lib/entity" do
307
+
308
+ subject do
309
+ lambda { storage.mkdir "/lib/entity" }
310
+ end
311
+
312
+ it { should raise_error ::Errno::EEXIST }
313
+
314
+ end
315
+
316
+ end
317
+
318
+ context "mkdir /lib/entity" do
319
+
320
+ before { storage.mkdir "/lib/entity" }
321
+
322
+ context "touch /lib/entity" do
323
+
324
+ subject do
325
+ lambda { storage.touch "/lib/entity" }
326
+ end
327
+
328
+ it { should_not raise_error }
329
+
330
+ end
331
+
332
+ context "write /lib/entity, data" do
333
+
334
+ subject do
335
+ lambda { storage.write "/lib/entity", "data" }
336
+ end
337
+
338
+ it { should raise_error ::Errno::EISDIR }
339
+
340
+ end
341
+
342
+ end
343
+
344
+ end # mkdir /lib
345
+
346
+ end # duplication
347
+
348
+ context "mkdir_p /path/to" do
349
+
350
+ before { storage.mkdir_p "/path/to" }
351
+
352
+ context "exists? /path/to" do
353
+ before { storage.exists? "/path/to" }
354
+ it { should be_truthy }
355
+ end
356
+
357
+ context "file? /path/to" do
358
+ subject { storage.file? "/path/to" }
359
+ it { should be_falsey }
360
+ end
361
+
362
+ context "directory? /path/to" do
363
+ subject { storage.directory? "/path/to" }
364
+ it { should be_truthy }
365
+ end
366
+
367
+ context "write /path/to/file, data" do
368
+ before { storage.write "/path/to/file", "data" }
369
+ context "read /path/to/file" do
370
+ subject { storage.read "/path/to/file" }
371
+ it { should eq "data" }
372
+ end
373
+ end
374
+
375
+ context "touch /path/to/file" do
376
+
377
+ before { storage.touch "/path/to/file" }
378
+
379
+ context "exists? /path/to/file" do
380
+ subject { storage.exists? "/path/to/file" }
381
+ it { should be_truthy }
382
+ end
383
+
384
+ context "file? /path/to/file" do
385
+ subject { storage.file? "/path/to/file" }
386
+ it { should be_truthy }
387
+ end
388
+
389
+ context "directory? /path/to/file" do
390
+ subject { storage.directory? "/path/to/file" }
391
+ it { should be_falsey }
392
+ end
393
+
394
+ context "rm_r /path/to" do
395
+
396
+ before { storage.rm_r "/path/to" }
397
+
398
+ context "exists? /path/to" do
399
+ subject { storage.exists? "/path/to" }
400
+ it { should be_falsey }
401
+ end
402
+
403
+ context "file? /path/to" do
404
+ subject { storage.file? "/path/to" }
405
+ it { should be_falsey }
406
+ end
407
+
408
+ context "directory? /path/to" do
409
+ subject { storage.directory? "/path/to" }
410
+ it { should be_falsey }
411
+ end
412
+
413
+ context "exists? /path/to/file" do
414
+ subject { storage.exists? "/path/to/file" }
415
+ it { should be_falsey }
416
+ end
417
+
418
+ context "file? /path/to/file" do
419
+ subject { storage.file? "/path/to/file" }
420
+ it { should be_falsey }
421
+ end
422
+
423
+ context "directory? /path/to/file" do
424
+ subject { storage.directory? "/path/to/file" }
425
+ it { should be_falsey }
426
+ end
427
+
428
+ end
429
+
430
+ context "rm /path/to/file" do
431
+
432
+ before { storage.rm "/path/to/file" }
433
+
434
+ context "exists? /path/to/file" do
435
+ subject { storage.exists? "/path/to/file" }
436
+ it { should be_falsey }
437
+ end
438
+
439
+ context "file? /path/to/file" do
440
+ subject { storage.file? "/path/to/file" }
441
+ it { should be_falsey }
442
+ end
443
+
444
+ context "directory? /path/to/file" do
445
+ subject { storage.directory? "/path/to/file" }
446
+ it { should be_falsey }
447
+ end
448
+
449
+ end # rm /path/to/file
450
+
451
+ end # touch /path/to/file
452
+
453
+ end # mkdir_p /path/to
454
+
455
+ end # test storage class
456
+
457
+ end # [shared] TestStorage
458
+
459
+ end