fakefs 1.3.0 → 1.4.1

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: b8bd326fd88f546556eaca2194662454a12234d2da597e8002a663e5dba757cb
4
- data.tar.gz: c70378d690483115a4419f80d11a5775b0848c7fd2a2ceaec098f07b4196d6c5
3
+ metadata.gz: b92c729c5ace776ebe3f2b5f396532b900f15997884de6239d67d9d41e21d16e
4
+ data.tar.gz: b331cf5fcafafd27e677c96386670099998acb126fbe84beb81774ff32e04a85
5
5
  SHA512:
6
- metadata.gz: cf22c7d97a54dbc02f382ba3ee7feb75673e792340336446816411bbae4b04886d9b1b7587a4230aee0c0f12ff64ad42102d4e3369dad223c3d27444b63f34b6
7
- data.tar.gz: 96077a4735d8a880bb8073e5abc2c8869a99b688b18082253f0eb026800c11df7dcdb139a0e22be2e6993b1caadf86b12adb76eadd2dfd20c4ea2877b1cc39db
6
+ metadata.gz: 9325e6abc81df8f759d9898e0946432f7ef6f1f554d26d0d231663340f6dba9363ae1dc065a8bb91645c2d266a528002ca3be8eebece8579a0e02cba3b9b716e
7
+ data.tar.gz: 94457dccf10cff791ff60061b72994143fd3bd7771d71f48a90591709a0825439c852ad166f4212616f0476bca7bbc632f00e1bc77ed64700796a0f46b90c772
data/lib/fakefs/dir.rb CHANGED
@@ -117,14 +117,16 @@ 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
- if Dir.pwd.match(%r{\A/?\z}) ||
124
- !e.to_s.match(%r{\A#{Dir.pwd}/?})
123
+ [FileSystem.find(matcher, flags, true, dir: pwd) || []].flatten.map do |e|
124
+ pwd_regex = %r{\A#{pwd.gsub('+') { '\+' }}/?}
125
+ if pwd.match(%r{\A/?\z}) ||
126
+ !e.to_s.match(pwd_regex)
125
127
  e.to_s
126
128
  else
127
- e.to_s.match(%r{\A#{Dir.pwd}/?}).post_match
129
+ e.to_s.match(pwd_regex).post_match
128
130
  end
129
131
  end.sort
130
132
  end
@@ -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)
@@ -63,20 +63,21 @@ module FakeFS
63
63
  def regexp(pattern, find_flags = 0, gave_char_class = false)
64
64
  pattern = pattern.to_s
65
65
 
66
+ # Escape .+?*()$ characters unless already escaped.
66
67
  regex_body =
67
68
  pattern
68
- .gsub('.', '\.')
69
- .gsub('+') { '\+' }
70
- .gsub('?', '.')
71
- .gsub('*', '.*')
72
- .gsub('(', '\(')
73
- .gsub(')', '\)')
74
- .gsub('$', '\$')
75
-
76
- # unless we're expecting character class contructs in regexes, escape all brackets
77
- # since if we're expecting them, the string should already be properly escaped
69
+ .gsub(/(?<!\\)\./, '\.')
70
+ .gsub(/(?<!\\)\+/) { '\+' }
71
+ .gsub(/(?<!\\)\?/, '.')
72
+ .gsub(/(?<!\\)\*/, '.*')
73
+ .gsub(/(?<!\\)\(/, '\(')
74
+ .gsub(/(?<!\\)\)/, '\)')
75
+ .gsub(/(?<!\\)\$/, '\$')
76
+
77
+ # Unless we're expecting character class contructs in regexes, escape all brackets
78
+ # since if we're expecting them, the string should already be properly escaped.
78
79
  unless gave_char_class
79
- regex_body = regex_body.gsub('[', '\[').gsub(']', '\]')
80
+ regex_body = regex_body.gsub(/(?<!\\)([\[\]])/, '\\\\\1')
80
81
  end
81
82
 
82
83
  # This matches nested braces and attempts to do something correct most of the time
@@ -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.0'.freeze
4
+ VERSION = '1.4.1'.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.0
4
+ version: 1.4.1
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: 2020-12-10 00:00:00.000000000 Z
15
+ date: 2022-01-18 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.