fakefs 3.0.0 → 3.0.2

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5e3224ff5a1d920e4564617bcb22fa5a7ece1e956cd8d4ea5602f3486780ac2f
4
- data.tar.gz: 66ee5d6658990778978ed1531c115ae28ad08414cf9aa1bc90f6fd7e6400b22f
3
+ metadata.gz: f14140aa5850811100ff24413b0a292776d556fd3db295751d9c2cd09ec6ea7e
4
+ data.tar.gz: 7fd749e6975091c8c76334f0231ad4f7934c258bf110dc48b9fdda997b6038e9
5
5
  SHA512:
6
- metadata.gz: 42daab712ce7b73ca3ffef7b383834eac7e624bdbf43e4098000fdca7d16cc92d505a5631e256248734962d8db7cb148842d4efc1853686f9cbe5d8b288c6c89
7
- data.tar.gz: 5514fc676ba615bd6387ad44cc3fa447fc566e265178729d8bb30a4098834e11a9f562f6cc8f25cc88b2c9d386827cc67506b46226008241510c67edbbeb6f81
6
+ metadata.gz: 71a73c4fdff9e06aed5eb192c659cff61c0eb61807ecf5d32a314e5e3a44eb47cf9c0c81322d2e49e5a1ea068518070197c605d1c2d8504e1f77dbe15ac6080b
7
+ data.tar.gz: c4fd74ecdf5cd6ef114948086ae27ac43b74063e51e7e5c430a9f1e0c3dd5ef5064b384c6c3ac6472c933363b80394c23c4699debb33fce5090ba8d4f329f478
data/lib/fakefs/dir.rb CHANGED
@@ -40,7 +40,7 @@ module FakeFS
40
40
  end
41
41
 
42
42
  def children
43
- each.to_a
43
+ each.to_a - ['.', '..']
44
44
  end
45
45
 
46
46
  def pos
data/lib/fakefs/file.rb CHANGED
@@ -48,6 +48,9 @@ module FakeFS
48
48
  (RealFile.const_defined?(:SYNC) ? RealFile::SYNC : 0)
49
49
  )
50
50
 
51
+ DEFAULT_DIR_SIZE = 64
52
+ DIR_ENTRY_SIZE = 32
53
+
51
54
  def self.extname(path)
52
55
  RealFile.extname(path)
53
56
  end
@@ -90,37 +93,24 @@ module FakeFS
90
93
  File.lstat(path).writable?
91
94
  end
92
95
 
93
- def self.mtime(path)
94
- if exist?(path)
95
- FileSystem.find(path).mtime
96
- else
97
- raise Errno::ENOENT
98
- end
99
- end
100
-
101
- def self.ctime(path)
102
- if exist?(path)
103
- FileSystem.find(path).ctime
104
- else
105
- raise Errno::ENOENT
106
- end
107
- end
108
-
109
- def self.atime(path)
110
- if exist?(path)
111
- FileSystem.find(path).atime
112
- else
113
- raise Errno::ENOENT
96
+ [:mtime, :ctime, :atime].each do |time_method|
97
+ define_singleton_method(time_method) do |path|
98
+ if (file_node = FileSystem.find(path))
99
+ file_node.send(time_method)
100
+ else
101
+ raise Errno::ENOENT, "No such file or directory - #{path}"
102
+ end
114
103
  end
115
104
  end
116
105
 
117
106
  def self.utime(atime, mtime, *paths)
118
107
  paths.each do |path|
119
- if exist?(path)
120
- FileSystem.find(path).atime = atime
121
- FileSystem.find(path).mtime = mtime
108
+ file_node = FileSystem.find(path)
109
+ if file_node
110
+ file_node.atime = atime
111
+ file_node.mtime = mtime
122
112
  else
123
- raise Errno::ENOENT
113
+ raise Errno::ENOENT, "No such file or directory - #{path}"
124
114
  end
125
115
  end
126
116
 
@@ -129,7 +119,7 @@ module FakeFS
129
119
 
130
120
  def self.size(path)
131
121
  if directory?(path)
132
- 64 + (32 * FileSystem.find(path).entries.size)
122
+ DEFAULT_DIR_SIZE + (DIR_ENTRY_SIZE * FileSystem.find(path).entries.size)
133
123
  else
134
124
  read(path).bytesize
135
125
  end
@@ -160,16 +160,25 @@ module FakeFS
160
160
  raise Errno::EEXIST, dest.to_s if new_dir && !File.directory?(dest)
161
161
  raise Errno::ENOENT, dest.to_s if !new_dir && !FileSystem.find(dest.to_s + '/../')
162
162
 
163
+ update_times = proc { |f| f.atime = f.mtime = Time.now }
163
164
  # This last bit is a total abuse and should be thought hard
164
165
  # about and cleaned up.
165
166
  if new_dir
166
- if src.to_s[-2..-1] == '/.'
167
- dir.entries.each { |f| new_dir[f.name] = f.clone(new_dir) }
167
+ if src.to_s.end_with?('/.')
168
+ dir.entries.each do |f|
169
+ copy = f.clone(new_dir)
170
+ walk_hierarchy(copy, &update_times) unless options[:preserve]
171
+ new_dir[f.name] = copy
172
+ end
168
173
  else
169
- new_dir[dir.name] = dir.entry.clone(new_dir)
174
+ copy = dir.entry.clone(new_dir)
175
+ walk_hierarchy(copy, &update_times) unless options[:preserve]
176
+ new_dir[dir.name] = copy
170
177
  end
171
178
  else
172
- FileSystem.add(dest, dir.entry.clone)
179
+ copy = dir.entry.clone
180
+ walk_hierarchy(copy, &update_times) unless options[:preserve]
181
+ FileSystem.add(dest, copy)
173
182
  end
174
183
  end
175
184
 
@@ -305,5 +314,16 @@ module FakeFS
305
314
  end
306
315
  true
307
316
  end
317
+
318
+ private
319
+
320
+ # Walks through the file system hierarchy recursively, starting from the given entry,
321
+ # and calls the given block with it.
322
+ def walk_hierarchy(entry, &block)
323
+ yield entry
324
+ if entry.is_a? FakeDir
325
+ entry.entries.each { |child| walk_hierarchy(child, &block) }
326
+ end
327
+ end
308
328
  end
309
329
  end
@@ -3,7 +3,7 @@
3
3
  module FakeFS
4
4
  # Version module
5
5
  module Version
6
- VERSION = '3.0.0'
6
+ VERSION = '3.0.2'
7
7
 
8
8
  def self.to_s
9
9
  VERSION
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fakefs
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.0
4
+ version: 3.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Wanstrath
@@ -9,9 +9,10 @@ authors:
9
9
  - Jeff Hodges
10
10
  - Pat Nakajima
11
11
  - Brian Donovan
12
+ autorequire:
12
13
  bindir: bin
13
14
  cert_chain: []
14
- date: 2025-01-20 00:00:00.000000000 Z
15
+ date: 2025-08-25 00:00:00.000000000 Z
15
16
  dependencies:
16
17
  - !ruby/object:Gem::Dependency
17
18
  name: bump
@@ -41,6 +42,20 @@ dependencies:
41
42
  - - ">="
42
43
  - !ruby/object:Gem::Version
43
44
  version: '0'
45
+ - !ruby/object:Gem::Dependency
46
+ name: irb
47
+ requirement: !ruby/object:Gem::Requirement
48
+ requirements:
49
+ - - ">="
50
+ - !ruby/object:Gem::Version
51
+ version: '0'
52
+ type: :development
53
+ prerelease: false
54
+ version_requirements: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ version: '0'
44
59
  - !ruby/object:Gem::Dependency
45
60
  name: maxitest
46
61
  requirement: !ruby/object:Gem::Requirement
@@ -159,6 +174,7 @@ homepage: https://github.com/fakefs/fakefs
159
174
  licenses:
160
175
  - MIT
161
176
  metadata: {}
177
+ post_install_message:
162
178
  rdoc_options: []
163
179
  require_paths:
164
180
  - lib
@@ -166,14 +182,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
166
182
  requirements:
167
183
  - - ">="
168
184
  - !ruby/object:Gem::Version
169
- version: 3.0.0
185
+ version: 3.2.0
170
186
  required_rubygems_version: !ruby/object:Gem::Requirement
171
187
  requirements:
172
188
  - - ">="
173
189
  - !ruby/object:Gem::Version
174
190
  version: '0'
175
191
  requirements: []
176
- rubygems_version: 3.6.2
192
+ rubygems_version: 3.4.10
193
+ signing_key:
177
194
  specification_version: 4
178
195
  summary: A fake filesystem. Use it in your tests.
179
196
  test_files: []