mockfs 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/mockfs.rb +6 -2
- data/lib/mockfs.rb~ +59 -14
- metadata +2 -2
data/lib/mockfs.rb
CHANGED
@@ -94,7 +94,7 @@ require 'fileutils'
|
|
94
94
|
require 'singleton'
|
95
95
|
|
96
96
|
module MockFS
|
97
|
-
Version = '0.1.
|
97
|
+
Version = '0.1.4'
|
98
98
|
|
99
99
|
@@mock = false
|
100
100
|
|
@@ -252,6 +252,10 @@ module MockFS
|
|
252
252
|
end
|
253
253
|
end
|
254
254
|
|
255
|
+
def self.dirname( file_name )
|
256
|
+
File.dirname file_name
|
257
|
+
end
|
258
|
+
|
255
259
|
class << self
|
256
260
|
def exist?( filename )
|
257
261
|
begin
|
@@ -365,7 +369,7 @@ module MockFS
|
|
365
369
|
rescue Errno::ENOENT
|
366
370
|
path = Path.new( file ).absolute
|
367
371
|
parent_dir = node( path.parent )
|
368
|
-
file = MockFileSystem::MockFile.new( parent_dir, path.node,
|
372
|
+
file = MockFileSystem::MockFile.new( parent_dir, path.node, '' )
|
369
373
|
parent_dir[path.node] = file
|
370
374
|
end
|
371
375
|
end
|
data/lib/mockfs.rb~
CHANGED
@@ -94,7 +94,7 @@ require 'fileutils'
|
|
94
94
|
require 'singleton'
|
95
95
|
|
96
96
|
module MockFS
|
97
|
-
Version = '0.1.
|
97
|
+
Version = '0.1.3'
|
98
98
|
|
99
99
|
@@mock = false
|
100
100
|
|
@@ -118,6 +118,9 @@ module MockFS
|
|
118
118
|
# +is_mock+ should be a Boolean.
|
119
119
|
def self.mock= ( is_mock ); @@mock = is_mock; end
|
120
120
|
|
121
|
+
# Returns +true+ or +false+ depending on whether MockFS is using the mock file system.
|
122
|
+
def self.mock?; @@mock; end
|
123
|
+
|
121
124
|
# If we're in mock mode, this will return the MockFileSystem; otherwise it
|
122
125
|
# will raise a RuntimeError.
|
123
126
|
def self.mock_file_system
|
@@ -163,7 +166,9 @@ module MockFS
|
|
163
166
|
def self.[]( string ); glob( string, 0 ); end
|
164
167
|
|
165
168
|
def self.glob( string, flags = 0 )
|
166
|
-
|
169
|
+
DirAdapter.new( '.' ).send( :glob, string, flags ).map { |result|
|
170
|
+
Path.new( result )[1..-1]
|
171
|
+
}
|
167
172
|
end
|
168
173
|
|
169
174
|
def self.mkdir( dirname )
|
@@ -176,31 +181,59 @@ module MockFS
|
|
176
181
|
node( path ).delete
|
177
182
|
end
|
178
183
|
|
184
|
+
attr_reader :path
|
185
|
+
|
179
186
|
def initialize( dirname )
|
180
187
|
unless node( dirname ).class == MockFileSystem::MockDir
|
181
188
|
raise Errno::ENOTDIR
|
182
189
|
end
|
183
|
-
@
|
190
|
+
@path = dirname
|
184
191
|
end
|
185
192
|
|
186
|
-
def entries; self.class.entries( @
|
193
|
+
def entries; self.class.entries( @path ); end
|
187
194
|
|
188
|
-
|
195
|
+
protected
|
189
196
|
|
190
197
|
def glob( string, flags = 0 )
|
191
|
-
|
192
|
-
|
198
|
+
glob_path = Path.new string
|
199
|
+
if glob_path.size > 1
|
200
|
+
if glob_path.first != '**'
|
201
|
+
subdir = DirAdapter.new( File.join( self.path, glob_path.first ) )
|
202
|
+
subdir.send( :glob, glob_path[1..-1], flags )
|
203
|
+
else
|
204
|
+
if glob_path.size > 2 and glob_path[1] == Path.new( path ).last
|
205
|
+
glob( glob_path[2..-1], flags )
|
206
|
+
else
|
207
|
+
if glob_path.size == 2
|
208
|
+
matches = match_entries( glob_path[-1], flags )
|
209
|
+
else
|
210
|
+
matches = []
|
211
|
+
end
|
212
|
+
DirAdapter.entries( path ).each do |entry|
|
213
|
+
unless %w( . .. ).include? entry
|
214
|
+
if FileAdapter.directory? File.join( path, entry )
|
215
|
+
subdir = DirAdapter.new File.join( self.path, entry )
|
216
|
+
matches << subdir.send( :glob, glob_path, flags )
|
217
|
+
end
|
218
|
+
end
|
219
|
+
end
|
220
|
+
matches.flatten.uniq
|
221
|
+
end
|
222
|
+
end
|
223
|
+
else
|
224
|
+
match_entries( string, flags )
|
225
|
+
end
|
226
|
+
end
|
227
|
+
|
228
|
+
def match_entries( string, flags )
|
193
229
|
string = string.gsub( /\./, '\.' )
|
194
230
|
string = string.gsub( /\?/, '.' )
|
195
231
|
string = string.gsub( /\*/, ".*" )
|
196
232
|
string = string.gsub( /\{(.+),(.+)\}/, '(\1|\2)' )
|
197
|
-
puts " #{ string }"
|
198
233
|
re = Regexp.new string
|
199
|
-
entries( path
|
234
|
+
DirAdapter.entries( path ).select { |entry|
|
200
235
|
flags & File::FNM_DOTMATCH != 0 || !%w( . .. ).include?( entry )
|
201
|
-
}.select { |entry| entry =~ re }.map { |entry|
|
202
|
-
File.join( path.parent, entry )
|
203
|
-
}
|
236
|
+
}.select { |entry| entry =~ re }.map { |entry| File.join( path, entry ) }
|
204
237
|
end
|
205
238
|
end
|
206
239
|
|
@@ -219,6 +252,10 @@ module MockFS
|
|
219
252
|
end
|
220
253
|
end
|
221
254
|
|
255
|
+
def self.dirname( file_name )
|
256
|
+
File.dirname file_name
|
257
|
+
end
|
258
|
+
|
222
259
|
class << self
|
223
260
|
def exist?( filename )
|
224
261
|
begin
|
@@ -278,7 +315,7 @@ module MockFS
|
|
278
315
|
mfile.read
|
279
316
|
end
|
280
317
|
|
281
|
-
class Mode
|
318
|
+
class Mode #:nodoc:
|
282
319
|
def initialize( string_or_bitwise )
|
283
320
|
if string_or_bitwise.is_a?( String )
|
284
321
|
if string_or_bitwise == 'w'
|
@@ -480,7 +517,13 @@ module MockFS
|
|
480
517
|
@@getwd
|
481
518
|
end
|
482
519
|
|
483
|
-
def []( *args )
|
520
|
+
def []( *args )
|
521
|
+
if args.size == 1 and args.first.is_a? Fixnum
|
522
|
+
Path.new self.split( "/" )[*args]
|
523
|
+
else
|
524
|
+
Path.new self.split( "/" )[*args].join( "/" )
|
525
|
+
end
|
526
|
+
end
|
484
527
|
|
485
528
|
def absolute
|
486
529
|
if self =~ %r{^\w}
|
@@ -495,6 +538,8 @@ module MockFS
|
|
495
538
|
|
496
539
|
def first; self.split( "/" ).first; end
|
497
540
|
|
541
|
+
def last; self.split( "/" ).last; end
|
542
|
+
|
498
543
|
def node
|
499
544
|
self =~ %r{^(.*)/(.*?)$}
|
500
545
|
$2
|
metadata
CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.8.11
|
|
3
3
|
specification_version: 1
|
4
4
|
name: mockfs
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.1.
|
7
|
-
date: 2006-
|
6
|
+
version: 0.1.4
|
7
|
+
date: 2006-12-31 00:00:00 -05:00
|
8
8
|
summary: MockFS is a test-obsessed library for mocking out the entire file system.
|
9
9
|
require_paths:
|
10
10
|
- lib
|