fast 0.1.3 → 0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,309 @@
1
+ require "fast"
2
+ require "zucker/os"
3
+
4
+ describe Fast::FilesystemObject do
5
+ describe "#normalize" do
6
+ context "string as a argument" do
7
+ it "should return the same string" do
8
+ the_object = stub "object"
9
+ the_object.extend Fast::FilesystemObject
10
+ the_object.normalize("hola").should == "hola"
11
+ end
12
+ end
13
+
14
+ context "symbol as a argument" do
15
+ it "should return the string representation of that symbol" do
16
+ the_object = stub "object"
17
+ the_object.extend Fast::FilesystemObject
18
+ the_object.normalize(:hola).should == "hola"
19
+ end
20
+ end
21
+
22
+ context "instance of the same class as argument" do
23
+ it "should return the #path of the instance" do
24
+ the_object = stub "object"
25
+ the_object.extend Fast::FilesystemObject
26
+ the_argument = stub "object"
27
+ the_argument.stub(:path).and_return "hola"
28
+ the_object.normalize(the_argument).should == "hola"
29
+ end
30
+ end
31
+
32
+ context "no argument passed" do
33
+ it "should fail" do
34
+ the_object = stub "object"
35
+ the_object.extend Fast::FilesystemObject
36
+ expect { the_object.normalize
37
+ }.to raise_error ArgumentError
38
+ end
39
+ end
40
+ end
41
+
42
+ describe "#path" do
43
+ context "the path is setted" do
44
+ it "should return the variable path" do
45
+ the_object = stub "object"
46
+ def the_object.add_path
47
+ @path = "hola"
48
+ end
49
+ the_object.add_path
50
+ the_object.extend Fast::FilesystemObject
51
+ the_object.path.should == "hola"
52
+ end
53
+ end
54
+
55
+ context "the path is undefined" do
56
+ it "should return nil" do
57
+ the_object = stub "object"
58
+ the_object.extend Fast::FilesystemObject
59
+ the_object.path.should be_nil
60
+ end
61
+ end
62
+ end
63
+
64
+ shared_examples_for "any path absolutizer" do
65
+ context "using existing @path in object" do
66
+ context "path is a relative route" do
67
+ it "should expand the path with pwd" do
68
+ the_object = stub "object"
69
+ def the_object.set_path
70
+ @path = "demo.file"
71
+ end
72
+ the_object.set_path
73
+ the_object.extend Fast::FilesystemObject
74
+ the_object.send( @method ).should == "#{Dir.pwd}/demo.file"
75
+ end
76
+ end
77
+
78
+ context "path is an absolute route" do
79
+ it "should return the same as given path" do
80
+ unless OS.windows?
81
+ the_object = stub "object"
82
+ def the_object.set_path
83
+ @path = "/dev/null"
84
+ end
85
+ the_object.set_path
86
+ the_object.extend Fast::FilesystemObject
87
+ the_object.send( @method ).should == "/dev/null"
88
+ else
89
+ pending "POSIX only!"
90
+ end
91
+ end
92
+ end
93
+
94
+ context "no path is setted" do
95
+ it "should fail with custom error" do
96
+ the_object = stub "object"
97
+ the_object.extend Fast::FilesystemObject
98
+ expect { the_object.send @method
99
+ }.to raise_error Fast::PathNotSettedException, "The path was not setted in this instance"
100
+ end
101
+ end
102
+ end
103
+
104
+ context "giving path as argument" do
105
+ context "the path is a relative route" do
106
+ it "should expand the path with pwd" do
107
+ the_object = stub "object"
108
+ the_object.extend Fast::FilesystemObject
109
+ the_object.send( @method, "demo.file" ).should == "#{Dir.pwd}/demo.file"
110
+ end
111
+ end
112
+
113
+ context "path is an absolute route" do
114
+ it "should return the same as the given path" do
115
+ the_object = stub "object"
116
+ the_object.extend Fast::FilesystemObject
117
+ the_object.send( @method, "/dev/null" ).should == "/dev/null"
118
+ end
119
+ end
120
+ end
121
+ end
122
+
123
+ describe "#expand" do
124
+ before { @method = :expand }
125
+ it_behaves_like "any path absolutizer"
126
+ end
127
+
128
+ describe "#absolute" do
129
+ before { @method = :absolute }
130
+ it_behaves_like "any path absolutizer"
131
+ end
132
+
133
+ shared_examples_for "any item existencialism" do
134
+ it "should call the method #do_exist?" do
135
+ the_object = Object.new
136
+ the_object.extend Fast::FilesystemObject
137
+ def the_object.path
138
+ @path = "somepath"
139
+ end
140
+ the_object.path
141
+ the_object.should_receive(:do_exist?).with("somepath")
142
+ the_object.send @method
143
+ end
144
+
145
+ context "no argument and no @path was setted" do
146
+ it "should fail" do
147
+ an_obj = Object.new
148
+ an_obj.stub :do_exist?
149
+ an_obj.extend Fast::FilesystemObject
150
+ expect { an_obj.send @method
151
+ }.to raise_error ArgumentError, "An argument should be provided if this instance has no path setted"
152
+ end
153
+ end
154
+
155
+ context "@path was setted previously" do
156
+ context "should return the same as #do_exist?" do
157
+ it "when exists is true" do
158
+ o = Object.new
159
+ o.extend Fast::FilesystemObject
160
+ def o.set; @path = "p"; end
161
+ o.set
162
+
163
+ o.should_receive(:do_exist?).with("p").and_return(true)
164
+ o.send(@method).should === true
165
+ end
166
+
167
+ it "when does not exist is false" do
168
+ o = Object.new
169
+ o.extend Fast::FilesystemObject
170
+ def o.set; @path = "p"; end
171
+ o.set
172
+
173
+ o.should_receive(:do_exist?).with("p").and_return(false)
174
+ o.send(@method).should === false
175
+ end
176
+ end
177
+ end
178
+ end
179
+
180
+ shared_examples_for "any single argument existencialism" do
181
+ it_behaves_like "any item existencialism"
182
+
183
+ it "should not accept more than one argument" do
184
+ o = Object.new
185
+ o.extend Fast::FilesystemObject
186
+ expect { o.send @method, "one", "two"
187
+ }.to raise_error ArgumentError
188
+ end
189
+
190
+ context "when receiving an argument" do
191
+ it "should normalize it" do
192
+ o = Object.new
193
+ o.extend Fast::FilesystemObject
194
+ o.should_receive(:normalize).with("mypath")
195
+ o.stub :do_exist?
196
+ o.send @method, "mypath"
197
+ end
198
+
199
+ context "if path wasn't setted" do
200
+ it "should set @path" do
201
+ o = Object.new
202
+ o.extend Fast::FilesystemObject
203
+ o.stub :do_exist?
204
+ o.send @method, :mypath
205
+ o.path.should == "mypath"
206
+ end
207
+ end
208
+
209
+ context "if @path was set" do
210
+ it "should not change path" do
211
+ o = Object.new
212
+ o.extend Fast::FilesystemObject
213
+ o.stub :do_exist?
214
+ def o.set_path; @path = "other"; end
215
+ o.set_path
216
+ o.send @method, :mypath
217
+ o.path.should == "other"
218
+ end
219
+ end
220
+
221
+ it "should call do_exist? with the given path" do
222
+ o = Object.new
223
+ o.extend Fast::FilesystemObject
224
+ o.should_receive(:do_exist?).with("apath")
225
+ o.send @method, :apath
226
+ end
227
+
228
+ it "when exists is true" do
229
+ o = Object.new
230
+ o.extend Fast::FilesystemObject
231
+
232
+ o.should_receive(:do_exist?).with("p").and_return(true)
233
+ o.send(@method, "p").should === true
234
+ end
235
+
236
+ it "when does not exist is false" do
237
+ o = Object.new
238
+ o.extend Fast::FilesystemObject
239
+
240
+ o.should_receive(:do_exist?).with("p").and_return(false)
241
+ o.send(@method, "p").should === false
242
+ end
243
+ end
244
+ end
245
+
246
+ describe "#exist?" do
247
+ before { @method = :exist? }
248
+ it_behaves_like "any single argument existencialism"
249
+ end
250
+
251
+ describe "#exists?" do
252
+ before { @method = :exists? }
253
+ it_behaves_like "any single argument existencialism"
254
+ end
255
+
256
+ describe "#exist_all?" do
257
+ before { @method = :exist_all? }
258
+ it_behaves_like "any item existencialism"
259
+
260
+ it "should return true if all item exist"
261
+
262
+ it "should return false if any item does not exist"
263
+ end
264
+
265
+ describe "#exist_any?" do
266
+ before { @method = :exist_any? }
267
+ it_behaves_like "any item existencialism"
268
+
269
+ it "should return true if at least one item exists"
270
+
271
+ it "should return false if none exists"
272
+ end
273
+
274
+ # Private methods here
275
+ describe "#do_exist?" do
276
+ context "when called as public" do
277
+ it "should raise an exception related with private method" do
278
+ obj = Object.new
279
+ obj.extend Fast::FilesystemObject
280
+ expect { obj.do_exist?
281
+ }.to raise_error NoMethodError, /private method/
282
+ end
283
+ end
284
+
285
+ context "when called as private" do
286
+ it "should raise ArgumentError when called without arguments" do
287
+ obj = Object.new
288
+ obj.extend Fast::FilesystemObject
289
+ def obj.test
290
+ do_exist?
291
+ end
292
+
293
+ expect { obj.test
294
+ }.to raise_error ArgumentError
295
+ end
296
+
297
+ it "should raise a NotImplementedException when called with an argument" do
298
+ o = Object.new
299
+ o.extend Fast::FilesystemObject
300
+ def o.t
301
+ do_exist? "path"
302
+ end
303
+
304
+ expect { o.t
305
+ }.to raise_error NotImplementedError, "The implementation of #do_exist? in the module FilesystemObject is abstract, please reimplement in any class including it."
306
+ end
307
+ end
308
+ end
309
+ end
@@ -0,0 +1,16 @@
1
+ require "fast"
2
+
3
+ describe Patterns::Adapter::Fast::Dir do
4
+ describe "#symbols" do
5
+ context "when given a list of file names" do
6
+ it "should return a list of the same files as symbols without extensions" do
7
+ list = ["file.txt", "data.txt", "thumbs.db", "data.txt.jpg"]
8
+ final_list = Patterns::Adapter::Fast::Dir.new( list ).symbols
9
+ final_list.should include :file
10
+ final_list.should include :data
11
+ final_list.should include :thumbs
12
+ final_list.should include :"data.txt"
13
+ end
14
+ end
15
+ end
16
+ end
@@ -15,6 +15,26 @@ describe SubSetter::Fast::Dir do
15
15
  end
16
16
  end
17
17
  end
18
+
19
+ describe "#ending" do
20
+ context "when given a list of file names and a ending" do
21
+ it "should return a Dir of the files with the given ending" do
22
+ list = ["file.txt", "data.txt", "thumbs.db", "data.txt.jpg"]
23
+ final_list = SubSetter::Fast::Dir.new( list ).ending "txt"
24
+ final_list.should be_a Fast::Dir
25
+ final_list.should include "file.txt"
26
+ final_list.should include "data.txt"
27
+ final_list.should_not include "thumbs.db"
28
+ final_list.should_not include "data.txt.jpg"
29
+ end
30
+ end
31
+ end
32
+
33
+ describe "#existence" do
34
+ context "given a list of items some of which exist and some not" do
35
+ it "should return only the existing ones"
36
+ end
37
+ end
18
38
 
19
39
  describe "#strip_extension" do
20
40
  it "should return a Dir with the files names without extension" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fast
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-04-04 00:00:00.000000000 Z
12
+ date: 2012-07-26 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: metafun
16
- requirement: &83229840 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,31 @@ dependencies:
21
21
  version: 0.2.0
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *83229840
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: 0.2.0
30
+ - !ruby/object:Gem::Dependency
31
+ name: sub-setter
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: 0.0.2
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: 0.0.2
25
46
  - !ruby/object:Gem::Dependency
26
47
  name: rspec
27
- requirement: &83229540 !ruby/object:Gem::Requirement
48
+ requirement: !ruby/object:Gem::Requirement
28
49
  none: false
29
50
  requirements:
30
51
  - - ! '>='
@@ -32,10 +53,15 @@ dependencies:
32
53
  version: '0'
33
54
  type: :development
34
55
  prerelease: false
35
- version_requirements: *83229540
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
36
62
  - !ruby/object:Gem::Dependency
37
63
  name: zucker
38
- requirement: &83229210 !ruby/object:Gem::Requirement
64
+ requirement: !ruby/object:Gem::Requirement
39
65
  none: false
40
66
  requirements:
41
67
  - - ! '>='
@@ -43,7 +69,12 @@ dependencies:
43
69
  version: '0'
44
70
  type: :development
45
71
  prerelease: false
46
- version_requirements: *83229210
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
47
78
  description: DSL for file system interaction
48
79
  email:
49
80
  - xavierviacanel@gmail.com
@@ -53,21 +84,27 @@ extra_rdoc_files: []
53
84
  files:
54
85
  - .gitignore
55
86
  - .rvmrc
87
+ - .travis.yml
56
88
  - Gemfile
57
89
  - Gemfile.lock
58
- - README.rdoc
90
+ - README.md
59
91
  - Rakefile
60
92
  - fast.gemspec
61
93
  - lib/fast.rb
62
94
  - lib/fast/dir.rb
95
+ - lib/fast/exceptions.rb
63
96
  - lib/fast/fast.rb
64
97
  - lib/fast/file.rb
98
+ - lib/fast/filesystemobject.rb
65
99
  - lib/fast/version.rb
100
+ - lib/patterns/adapter/fast/dir.rb
66
101
  - lib/sub-setter/fast/dir.rb
67
102
  - lib/sub-setter/fast/file.rb
68
103
  - spec/fast/dir_spec.rb
69
104
  - spec/fast/fast_spec.rb
70
105
  - spec/fast/file_spec.rb
106
+ - spec/fast/filesystemobject_spec.rb
107
+ - spec/patterns/adapter/fast/dir_spec.rb
71
108
  - spec/sub-setter/fast/dir_spec.rb
72
109
  homepage: ''
73
110
  licenses: []
@@ -89,7 +126,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
89
126
  version: '0'
90
127
  requirements: []
91
128
  rubyforge_project: fast
92
- rubygems_version: 1.8.15
129
+ rubygems_version: 1.8.21
93
130
  signing_key:
94
131
  specification_version: 3
95
132
  summary: DSL for file system interaction