fakefs 2.8.0 → 3.0.1

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: 7293346fcf1164e9e312a2e9dcfc9b5795fc4ba0df452f26fc2c43942f0855a7
4
- data.tar.gz: cefca13b077629a3ada2ee8b29a047dcd7661f1b3a2d2922d2af6649fc9ef69f
3
+ metadata.gz: 1e08faef6f68079adb9d714e2f5b28ab19f6502f636b7cced858fc2dd8f9feca
4
+ data.tar.gz: 975d872ac50fc21b632b14c34f9b9a5bb20e2efe3ba5f5f05b98e166cd183569
5
5
  SHA512:
6
- metadata.gz: 258159efa60c4968941ed425eb78175e3c9bd412b235fea93361b0f442c9569de3b51d6d5f00adf5c880854d40ae8553095206666ce2324913624927c3a1f069
7
- data.tar.gz: 6bf302764a2e765051cdd0709fa722cf6acd30df831d8211c4fdcd83e8a1ad4ad7d0cdb5286b22a8b4dfbc6de8686ca2bb24b5a30ffbf986764e239c2802b220
6
+ metadata.gz: b44203007feb73426b81d63f96824c0712fadc5bc08f5622d159450cdaecd6afd7b7a31c5c69ba561f221160190ae00de4c67c39b93470a27be58e522aee8001
7
+ data.tar.gz: 30c2f8c8c74e68640ba042271c40b1e4da750c71ff44432417f208378645ef5620193e44aa75225260f6fbbf7fe010d1083e578ee857baba07eb610a43a7a867
data/lib/fakefs/base.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  RealFile = File
2
4
  RealFileTest = FileTest
3
5
  RealFileUtils = FileUtils
data/lib/fakefs/dir.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'English'
2
4
 
3
5
  module FakeFS
@@ -38,7 +40,7 @@ module FakeFS
38
40
  end
39
41
 
40
42
  def children
41
- each.to_a
43
+ each.to_a - ['.', '..']
42
44
  end
43
45
 
44
46
  def pos
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module FakeFS
2
4
  # Fake Dir class
3
5
  class FakeDir
@@ -1,8 +1,9 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module FakeFS
2
4
  # Fake file class
3
5
  class FakeFile
4
- attr_accessor :name, :parent, :mtime, :atime, :mode, :uid, :gid
5
- attr_reader :ctime, :birthtime
6
+ attr_accessor :name, :parent, :mtime, :atime, :mode, :uid, :gid, :ctime, :birthtime, :inode
6
7
 
7
8
  def initialize(name = nil, parent = nil)
8
9
  @name = name
@@ -17,8 +18,6 @@ module FakeFS
17
18
  @gid = Process.gid
18
19
  end
19
20
 
20
- attr_accessor :inode
21
-
22
21
  def content
23
22
  @inode.content
24
23
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module FakeFS
2
4
  # Inode class
3
5
  class FakeInode
@@ -10,14 +12,11 @@ module FakeFS
10
12
  assign_inode_num
11
13
  end
12
14
 
13
- attr_accessor :content
14
- attr_accessor :links
15
- attr_accessor :inode_num
15
+ attr_accessor :content, :links, :inode_num
16
16
 
17
17
  # please see: http://iacobson.net/beware-of-ruby-class-variables/
18
18
  class << self
19
- attr_accessor :freed_inodes
20
- attr_accessor :next_inode_num
19
+ attr_accessor :freed_inodes, :next_inode_num
21
20
 
22
21
  # This method should only be used for tests
23
22
  # When called, it will reset the current inode information of the FakeFS
@@ -28,8 +27,7 @@ module FakeFS
28
27
  end
29
28
 
30
29
  def assign_inode_num
31
- if (@inode_num = self.class.freed_inodes.shift)
32
- else
30
+ unless (@inode_num = self.class.freed_inodes.shift)
33
31
  @inode_num = self.class.next_inode_num
34
32
  self.class.next_inode_num += 1
35
33
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module FakeFS
2
4
  # Fake symlink class
3
5
  class FakeSymlink
@@ -29,7 +31,7 @@ module FakeFS
29
31
 
30
32
  private
31
33
 
32
- def method_missing(*args, &block) # rubocop:disable Style/MethodMissingSuper
34
+ def method_missing(*args, &block)
33
35
  entry.send(*args, &block)
34
36
  end
35
37
  end
data/lib/fakefs/file.rb CHANGED
@@ -1,15 +1,17 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'stringio'
2
4
 
3
5
  module FakeFS
4
6
  # FakeFS File class inherit StringIO
5
7
  class File < StringIO
6
8
  MODES = [
7
- READ_ONLY = 'r'.freeze,
8
- READ_WRITE = 'r+'.freeze,
9
- WRITE_ONLY = 'w'.freeze,
10
- READ_WRITE_TRUNCATE = 'w+'.freeze,
11
- APPEND_WRITE_ONLY = 'a'.freeze,
12
- APPEND_READ_WRITE = 'a+'.freeze
9
+ READ_ONLY = 'r',
10
+ READ_WRITE = 'r+',
11
+ WRITE_ONLY = 'w',
12
+ READ_WRITE_TRUNCATE = 'w+',
13
+ APPEND_WRITE_ONLY = 'a',
14
+ APPEND_READ_WRITE = 'a+'
13
15
  ].freeze
14
16
 
15
17
  FMODE_READABLE = 0x00000001
@@ -46,6 +48,9 @@ module FakeFS
46
48
  (RealFile.const_defined?(:SYNC) ? RealFile::SYNC : 0)
47
49
  )
48
50
 
51
+ DEFAULT_DIR_SIZE = 64
52
+ DIR_ENTRY_SIZE = 32
53
+
49
54
  def self.extname(path)
50
55
  RealFile.extname(path)
51
56
  end
@@ -88,37 +93,24 @@ module FakeFS
88
93
  File.lstat(path).writable?
89
94
  end
90
95
 
91
- def self.mtime(path)
92
- if exist?(path)
93
- FileSystem.find(path).mtime
94
- else
95
- raise Errno::ENOENT
96
- end
97
- end
98
-
99
- def self.ctime(path)
100
- if exist?(path)
101
- FileSystem.find(path).ctime
102
- else
103
- raise Errno::ENOENT
104
- end
105
- end
106
-
107
- def self.atime(path)
108
- if exist?(path)
109
- FileSystem.find(path).atime
110
- else
111
- 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
112
103
  end
113
104
  end
114
105
 
115
106
  def self.utime(atime, mtime, *paths)
116
107
  paths.each do |path|
117
- if exist?(path)
118
- FileSystem.find(path).atime = atime
119
- 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
120
112
  else
121
- raise Errno::ENOENT
113
+ raise Errno::ENOENT, "No such file or directory - #{path}"
122
114
  end
123
115
  end
124
116
 
@@ -127,7 +119,7 @@ module FakeFS
127
119
 
128
120
  def self.size(path)
129
121
  if directory?(path)
130
- 64 + (32 * FileSystem.find(path).entries.size)
122
+ DEFAULT_DIR_SIZE + (DIR_ENTRY_SIZE * FileSystem.find(path).entries.size)
131
123
  else
132
124
  read(path).bytesize
133
125
  end
@@ -277,7 +269,7 @@ module FakeFS
277
269
 
278
270
  def self.delete(*files)
279
271
  files.each do |file|
280
- file_name = (file.class == FakeFS::File ? file.path : file.to_s)
272
+ file_name = (file.instance_of?(FakeFS::File) ? file.path : file.to_s)
281
273
  raise Errno::ENOENT, file_name unless exist?(file_name)
282
274
 
283
275
  FileUtils.rm(file_name)
@@ -362,8 +354,7 @@ module FakeFS
362
354
 
363
355
  # FakeFS Stat class
364
356
  class Stat
365
- attr_reader :ctime, :mtime, :atime, :mode, :uid, :gid
366
- attr_reader :birthtime
357
+ attr_reader :ctime, :mtime, :atime, :mode, :uid, :gid, :birthtime
367
358
 
368
359
  def initialize(file, lstat = false)
369
360
  raise(Errno::ENOENT, file.to_s) unless File.exist?(file)
@@ -574,7 +565,9 @@ module FakeFS
574
565
  # and force set it back.
575
566
 
576
567
  # truncate doesn't work
577
- @file.content.force_encoding(Encoding.default_external)
568
+ unless @file.is_a?(FakeFS::FakeDir)
569
+ @file.content = @file.content.dup.force_encoding(Encoding.default_external)
570
+ end
578
571
  # StringIO.new 'content', nil, **{} # works in MRI, but fails in JRuby
579
572
  # but File.open 'filename', nil, **{} is ok both in MRI and JRuby
580
573
 
@@ -906,9 +899,9 @@ module FakeFS
906
899
  # note we multiply by 7 since the group num is 1, and octal represents digits 1-7 and we want all 3 bits
907
900
  current_group_mode = current_file_mode & (group_num * 7)
908
901
  if group_num == 0o100
909
- current_group_mode = current_group_mode >> 6
902
+ current_group_mode >>= 6
910
903
  elsif group_num == 0o10
911
- current_group_mode = current_group_mode >> 3
904
+ current_group_mode >>= 3
912
905
  end
913
906
 
914
907
  current_group_mode
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module FakeFS
2
4
  # FileSystem module
3
5
  module FileSystem
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module FakeFS
2
4
  # FileTest
3
5
  module FileTest
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module FakeFS
2
4
  # FileUtils module
3
5
  module FileUtils
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative 'file'
2
4
 
3
5
  module FakeFS
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module FakeFS
2
4
  # Handles globbing for FakeFS.
3
5
  module Globber
@@ -8,14 +10,14 @@ module FakeFS
8
10
 
9
11
  return [pattern] if pattern[0] != '{' || pattern[-1] != '}'
10
12
 
11
- part = ''
13
+ part = +''
12
14
  result = []
13
15
 
14
16
  each_char_with_levels pattern, '{', '}' do |chr, level|
15
17
  case level
16
18
  when 0
17
19
  case chr
18
- when '{' # rubocop:disable Lint/EmptyWhen
20
+ when '{'
19
21
  # noop
20
22
  else
21
23
  part << chr
@@ -24,8 +26,8 @@ module FakeFS
24
26
  case chr
25
27
  when ','
26
28
  result << part
27
- part = ''
28
- when '}' # rubocop:disable Lint/EmptyWhen
29
+ part = +''
30
+ when '}'
29
31
  # noop
30
32
  else
31
33
  part << chr
@@ -43,13 +45,13 @@ module FakeFS
43
45
  def path_components(pattern)
44
46
  pattern = pattern.to_s
45
47
 
46
- part = ''
48
+ part = +''
47
49
  result = []
48
50
 
49
51
  each_char_with_levels pattern, '{', '}' do |chr, level|
50
52
  if level == 0 && chr == File::SEPARATOR
51
53
  result << part
52
- part = ''
54
+ part = +''
53
55
  else
54
56
  part << chr
55
57
  end
data/lib/fakefs/io.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module FakeFS
2
4
  # FakeFS IO class inherit root IO
3
5
  # Only minimal mocks are provided as IO may be used by ruby's internals
data/lib/fakefs/irb.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'irb'
2
4
 
3
5
  # Make the original file system classes available in IRB.
data/lib/fakefs/kernel.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module FakeFS
2
4
  # Kernel Module
3
5
  module Kernel
@@ -16,7 +18,7 @@ module FakeFS
16
18
  end
17
19
 
18
20
  def self.unhijack!
19
- captives[:original].each do |name, _prc|
21
+ captives[:original].each_key do |name|
20
22
  ::Kernel.send(:remove_method, name.to_sym)
21
23
  ::Kernel.send(:define_method, name.to_sym, proc do |*args, **kwargs, &block|
22
24
  ::FakeFS::Kernel.captives[:original][name].call(*args, **kwargs, &block)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # FakeFS module
2
4
  module FakeFS
3
5
  #
@@ -109,10 +111,10 @@ module FakeFS
109
111
  if File::ALT_SEPARATOR
110
112
  SEPARATOR_LIST = "#{Regexp.quote File::ALT_SEPARATOR}" \
111
113
  "#{Regexp.quote File::SEPARATOR}".freeze
112
- SEPARATOR_PAT = /[#{SEPARATOR_LIST}]/.freeze
114
+ SEPARATOR_PAT = /[#{SEPARATOR_LIST}]/
113
115
  else
114
116
  SEPARATOR_LIST = (Regexp.quote File::SEPARATOR).to_s.freeze
115
- SEPARATOR_PAT = /#{Regexp.quote File::SEPARATOR}/.freeze
117
+ SEPARATOR_PAT = /#{Regexp.quote File::SEPARATOR}/
116
118
  end
117
119
 
118
120
  # Return a pathname which the extension of the basename is substituted by
@@ -483,7 +485,8 @@ module FakeFS
483
485
  while (r = chop_basename(pre))
484
486
  pre, base = r
485
487
  case base
486
- when '.' # rubocop:disable Lint/EmptyWhen
488
+ when '.'
489
+ # ignored
487
490
  when '..'
488
491
  names.unshift base
489
492
  else
data/lib/fakefs/pry.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Define Pry class if it's not defined. Useful if pry
2
4
  # is required after loading FakeFS
3
5
  ::Pry = Class.new unless defined?(::Pry)
data/lib/fakefs/safe.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'fileutils'
2
4
  require 'pathname'
3
5
  require 'fakefs/pry'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # FakeFS::SpecHelpers provides a simple macro for RSpec example
2
4
  # groups to turn FakeFS on and off.
3
5
  # To use it simply require 'fakefs/spec_helpers', then include
@@ -1,7 +1,9 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module FakeFS
2
4
  # Version module
3
5
  module Version
4
- VERSION = '2.8.0'.freeze
6
+ VERSION = '3.0.1'
5
7
 
6
8
  def self.to_s
7
9
  VERSION
data/lib/fakefs.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'fakefs/safe'
2
4
 
3
5
  FakeFS.activate!
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: 2.8.0
4
+ version: 3.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Wanstrath
@@ -12,36 +12,64 @@ authors:
12
12
  autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
- date: 2024-12-10 00:00:00.000000000 Z
15
+ date: 2025-08-03 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: bump
19
19
  requirement: !ruby/object:Gem::Requirement
20
20
  requirements:
21
- - - "~>"
21
+ - - ">="
22
22
  - !ruby/object:Gem::Version
23
- version: 0.5.3
23
+ version: '0'
24
24
  type: :development
25
25
  prerelease: false
26
26
  version_requirements: !ruby/object:Gem::Requirement
27
27
  requirements:
28
- - - "~>"
28
+ - - ">="
29
29
  - !ruby/object:Gem::Version
30
- version: 0.5.3
30
+ version: '0'
31
+ - !ruby/object:Gem::Dependency
32
+ name: csv
33
+ requirement: !ruby/object:Gem::Requirement
34
+ requirements:
35
+ - - ">="
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ requirements:
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ version: '0'
31
45
  - !ruby/object:Gem::Dependency
32
46
  name: maxitest
33
47
  requirement: !ruby/object:Gem::Requirement
34
48
  requirements:
35
- - - "~>"
49
+ - - ">="
36
50
  - !ruby/object:Gem::Version
37
- version: '3.6'
51
+ version: '0'
38
52
  type: :development
39
53
  prerelease: false
40
54
  version_requirements: !ruby/object:Gem::Requirement
41
55
  requirements:
42
- - - "~>"
56
+ - - ">="
43
57
  - !ruby/object:Gem::Version
44
- version: '3.6'
58
+ version: '0'
59
+ - !ruby/object:Gem::Dependency
60
+ name: mutex_m
61
+ requirement: !ruby/object:Gem::Requirement
62
+ requirements:
63
+ - - ">="
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ type: :development
67
+ prerelease: false
68
+ version_requirements: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: '0'
45
73
  - !ruby/object:Gem::Dependency
46
74
  name: pry
47
75
  requirement: !ruby/object:Gem::Requirement
@@ -62,42 +90,42 @@ dependencies:
62
90
  requirements:
63
91
  - - ">="
64
92
  - !ruby/object:Gem::Version
65
- version: '10.3'
93
+ version: '0'
66
94
  type: :development
67
95
  prerelease: false
68
96
  version_requirements: !ruby/object:Gem::Requirement
69
97
  requirements:
70
98
  - - ">="
71
99
  - !ruby/object:Gem::Version
72
- version: '10.3'
100
+ version: '0'
73
101
  - !ruby/object:Gem::Dependency
74
102
  name: rspec
75
103
  requirement: !ruby/object:Gem::Requirement
76
104
  requirements:
77
- - - "~>"
105
+ - - ">="
78
106
  - !ruby/object:Gem::Version
79
- version: '3.1'
107
+ version: '0'
80
108
  type: :development
81
109
  prerelease: false
82
110
  version_requirements: !ruby/object:Gem::Requirement
83
111
  requirements:
84
- - - "~>"
112
+ - - ">="
85
113
  - !ruby/object:Gem::Version
86
- version: '3.1'
114
+ version: '0'
87
115
  - !ruby/object:Gem::Dependency
88
116
  name: rubocop
89
117
  requirement: !ruby/object:Gem::Requirement
90
118
  requirements:
91
119
  - - "~>"
92
120
  - !ruby/object:Gem::Version
93
- version: 0.82.0
121
+ version: 1.70.0
94
122
  type: :development
95
123
  prerelease: false
96
124
  version_requirements: !ruby/object:Gem::Requirement
97
125
  requirements:
98
126
  - - "~>"
99
127
  - !ruby/object:Gem::Version
100
- version: 0.82.0
128
+ version: 1.70.0
101
129
  description: A fake filesystem. Use it in your tests.
102
130
  email:
103
131
  - chris@ozmm.org
@@ -140,14 +168,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
140
168
  requirements:
141
169
  - - ">="
142
170
  - !ruby/object:Gem::Version
143
- version: 2.7.0
171
+ version: 3.0.0
144
172
  required_rubygems_version: !ruby/object:Gem::Requirement
145
173
  requirements:
146
174
  - - ">="
147
175
  - !ruby/object:Gem::Version
148
176
  version: '0'
149
177
  requirements: []
150
- rubygems_version: 3.5.11
178
+ rubygems_version: 3.4.10
151
179
  signing_key:
152
180
  specification_version: 4
153
181
  summary: A fake filesystem. Use it in your tests.