fakefs 1.3.2 → 1.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 05aa1f68c0f9298802a4171ba6b109e53cb2e020b9b6f2973872ce4cc4de6ce1
4
- data.tar.gz: 566bdaeab08f35a081857a4a76170c6b94f29bf928735f81470a19e4280297e4
3
+ metadata.gz: 825da63678bcf85ba7a0e7fdcdf067da5477187ffb2e5d982bcdae72084b8ea6
4
+ data.tar.gz: 7d860f9926de5b203041b652ff4692731dfd5c34846908c48bc02e6b853e0dd1
5
5
  SHA512:
6
- metadata.gz: 25dd82ac5d99560aee6642ee5faea80ee35cf0b70610d6b1f7b3e4cd7369c78f9acf9fce6567ad4ae0409c82e388917a220f4acc2637875768df486127491cf9
7
- data.tar.gz: 8d087e11e9c7ba065bf07b4cff4ff51011ecf903fd830aa5ec51d8dcb2c18ded53c3cfbf38cc8226f7d4f46590bc3868fa902bfcc2011c1e19c1586868a920eb
6
+ metadata.gz: 649a2c7d8c39458f3c81cdaf7eade2a5203fa5b1c33ac7e243e94afbb4da4dad6029772ee708d7034b6ad70ca15549e6bbb028967a92183b4bb26780c5374b6f
7
+ data.tar.gz: cded1748b5a782e70923bf9cf3111f91cd2f06cb749db05768b2a619c884041a508e49221b2ddf775ac340bc76dd47bb26da1c397a6cd7f9b9dc99eedd22005b
data/lib/fakefs/dir.rb CHANGED
@@ -117,10 +117,10 @@ module FakeFS
117
117
  Dir.open(dirname) { |file| yield file }
118
118
  end
119
119
 
120
- def self.glob(pattern, flags = 0, &block)
120
+ def self.glob(pattern, _flags = 0, flags: _flags, base: nil, &block) # rubocop:disable Lint/UnderscorePrefixedVariableName
121
+ pwd = FileSystem.normalize_path(base || Dir.pwd)
121
122
  matches_for_pattern = lambda do |matcher|
122
- [FileSystem.find(matcher, flags, true) || []].flatten.map do |e|
123
- pwd = Dir.pwd
123
+ [FileSystem.find(matcher, flags, true, dir: pwd) || []].flatten.map do |e|
124
124
  pwd_regex = %r{\A#{pwd.gsub('+') { '\+' }}/?}
125
125
  if pwd.match(%r{\A/?\z}) ||
126
126
  !e.to_s.match(pwd_regex)
data/lib/fakefs/file.rb CHANGED
@@ -331,6 +331,11 @@ module FakeFS
331
331
  File.read(file, length, offset, mode: 'rb:ASCII-8BIT')
332
332
  end
333
333
 
334
+ def self.binwrite(file, content, offset = nil)
335
+ mode = offset ? 'r+b:ASCII-8BIT' : 'wb:ASCII-8BIT'
336
+ File.write(file, content, offset, mode: mode)
337
+ end
338
+
334
339
  def self.fnmatch?(pattern, path, flags = 0)
335
340
  RealFile.fnmatch?(pattern, path, flags)
336
341
  end
@@ -658,7 +663,7 @@ module FakeFS
658
663
 
659
664
  def self.write(filename, contents, offset = nil, open_args = {})
660
665
  offset, open_args = nil, offset if offset.is_a?(Hash)
661
- mode = offset ? 'a' : 'w'
666
+ mode = offset ? 'r+' : 'w'
662
667
  if open_args.any?
663
668
  if open_args[:open_args]
664
669
  args = [filename, *open_args[:open_args]]
@@ -20,12 +20,12 @@ module FakeFS
20
20
  fs.entries
21
21
  end
22
22
 
23
- def find(path, find_flags = 0, gave_char_class = false)
24
- parts = path_parts(normalize_path(path))
23
+ def find(path, find_flags = 0, gave_char_class = false, dir: nil)
24
+ parts = path_parts(normalize_path(path, dir: dir))
25
25
  return fs if parts.empty? # '/'
26
26
 
27
27
  entries = Globber.expand(path).flat_map do |pattern|
28
- parts = path_parts(normalize_path(pattern))
28
+ parts = path_parts(normalize_path(pattern, dir: dir))
29
29
  find_recurser(fs, parts, find_flags, gave_char_class).flatten
30
30
  end
31
31
 
@@ -100,11 +100,13 @@ module FakeFS
100
100
  Globber.path_components(path)
101
101
  end
102
102
 
103
- def normalize_path(path)
103
+ def normalize_path(path, dir: nil)
104
104
  if Pathname.new(path).absolute?
105
105
  RealFile.expand_path(path)
106
106
  else
107
- parts = dir_levels + [path]
107
+ dir ||= dir_levels
108
+ dir = Array(dir)
109
+ parts = dir + [path]
108
110
  RealFile.expand_path(parts.reduce do |base, part|
109
111
  Pathname(base) + part
110
112
  end.to_s)
@@ -909,11 +909,11 @@ module FakeFS
909
909
  # Pathname class
910
910
  class Pathname # * Dir *
911
911
  # See <tt>Dir.glob</tt>. Returns or yields Pathname objects.
912
- def self.glob(*args) # :yield: pathname
912
+ def self.glob(*args, **opts) # :yield: pathname
913
913
  if block_given?
914
- Dir.glob(*args) { |f| yield new(f) }
914
+ Dir.glob(*args, **opts) { |f| yield new(f) }
915
915
  else
916
- Dir.glob(*args).map { |f| new(f) }
916
+ Dir.glob(*args, **opts).map { |f| new(f) }
917
917
  end
918
918
  end
919
919
 
@@ -953,6 +953,14 @@ module FakeFS
953
953
  def opendir(&block) # :yield: dir
954
954
  Dir.open(@path, &block)
955
955
  end
956
+
957
+ def glob(pattern, flags = 0)
958
+ if block_given?
959
+ Dir.glob(pattern, flags: flags, base: self) { |f| yield join(f) }
960
+ else
961
+ Dir.glob(pattern, flags: flags, base: self).map { |f| join(f) }
962
+ end
963
+ end
956
964
  end
957
965
 
958
966
  # Pathname class
@@ -1027,6 +1035,6 @@ module FakeFS
1027
1035
 
1028
1036
  # Pathname class
1029
1037
  class Pathname
1030
- undef =~
1038
+ undef =~ if respond_to?(:=~)
1031
1039
  end
1032
1040
  end
@@ -1,7 +1,7 @@
1
1
  module FakeFS
2
2
  # Version module
3
3
  module Version
4
- VERSION = '1.3.2'.freeze
4
+ VERSION = '1.5.0'.freeze
5
5
 
6
6
  def self.to_s
7
7
  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: 1.3.2
4
+ version: 1.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Wanstrath
@@ -12,7 +12,7 @@ authors:
12
12
  autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
- date: 2021-01-04 00:00:00.000000000 Z
15
+ date: 2022-05-23 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: bump
@@ -129,7 +129,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
129
129
  - !ruby/object:Gem::Version
130
130
  version: '0'
131
131
  requirements: []
132
- rubygems_version: 3.1.3
132
+ rubygems_version: 3.1.6
133
133
  signing_key:
134
134
  specification_version: 4
135
135
  summary: A fake filesystem. Use it in your tests.