fakefs 2.2.0 → 2.4.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: ac7a61d1e3f94ffbd8bf9e02b2bc067756d9a2ec5b6dedd9dd4591c014e86ddc
4
- data.tar.gz: 849724752e1833ab9876f538910789178d78e20880be8803eb0bac0fd8f1f873
3
+ metadata.gz: 1233eb5f53d2726d129d63b73b637d324eccd588bf2b91a03ea9c66ce4eaf315
4
+ data.tar.gz: 86ee22f93f37f84744da31813a43377a95b398337c45d08d2bddbfdab3794df9
5
5
  SHA512:
6
- metadata.gz: 97c55be8f221b42ab6c3cb9e80ba1531f984b8c28d565f96ab6deef78dccfe2f822cfc163ffe3108d0e915903290e793b5fe58513e7ef7ffa7af732407242eb1
7
- data.tar.gz: 749aa9b67e909e40a6eec857c0be44faa915fbb09d30066a0387be9692860053d393922582f601de9cde3955e999b329d1febec4fadba7fc9ef0eb0c700bf8d8
6
+ metadata.gz: e1df486ce2856004f54e6ef9216754e008843282d5ad14f95700ce66d3f49185359217855be28cd5a4603e7b3168f2c5aec4bc5618c0f356abb6759193e0a2bf
7
+ data.tar.gz: 6cda052f83b1e7d3ec3e5ffcba0d29851eced5f450c4e60c24f459e8859b109b2ec22f94144e8cc2d24526eb254259c9ba08cf93b54e4d383e087d3275b73ca8
data/lib/fakefs/dir.rb CHANGED
@@ -130,7 +130,7 @@ module FakeFS
130
130
  def self.glob(pattern, _flags = 0, flags: _flags, base: nil, &block) # rubocop:disable Lint/UnderscorePrefixedVariableName
131
131
  pwd = FileSystem.normalize_path(base || Dir.pwd)
132
132
  matches_for_pattern = lambda do |matcher|
133
- [FileSystem.find(matcher, flags, true, dir: pwd) || []].flatten.map do |e|
133
+ [FileSystem.find_with_glob(matcher, flags, true, dir: pwd) || []].flatten.map do |e|
134
134
  pwd_regex = %r{\A#{pwd.gsub('+') { '\+' }}/?}
135
135
  if pwd.match(%r{\A/?\z}) ||
136
136
  !e.to_s.match(pwd_regex)
@@ -20,13 +20,22 @@ module FakeFS
20
20
  fs.entries
21
21
  end
22
22
 
23
- def find(path, find_flags = 0, gave_char_class = false, dir: nil)
23
+ # Finds files/directories using the exact path, without expanding globs.
24
+ def find(path, dir: nil)
25
+ parts = path_parts(normalize_path(path, dir: dir))
26
+ return fs if parts.empty? # '/'
27
+
28
+ find_recurser(fs, parts)
29
+ end
30
+
31
+ # Finds files/directories expanding globs.
32
+ def find_with_glob(path, find_flags = 0, gave_char_class = false, dir: nil)
24
33
  parts = path_parts(normalize_path(path, dir: dir))
25
34
  return fs if parts.empty? # '/'
26
35
 
27
36
  entries = Globber.expand(path).flat_map do |pattern|
28
37
  parts = path_parts(normalize_path(pattern, dir: dir))
29
- find_recurser(fs, parts, find_flags, gave_char_class).flatten
38
+ find_with_glob_recurser(fs, parts, find_flags, gave_char_class).flatten
30
39
  end
31
40
 
32
41
  case entries.length
@@ -120,6 +129,18 @@ module FakeFS
120
129
  private
121
130
 
122
131
  def find_recurser(dir, parts, find_flags = 0, gave_char_class = false)
132
+ return nil unless dir.respond_to? :[]
133
+ head, *parts = parts
134
+ match = dir.entries.find { |e| e.name == head }
135
+
136
+ if parts.empty? # we're done recursing
137
+ match
138
+ else
139
+ find_recurser(match, parts, find_flags, gave_char_class)
140
+ end
141
+ end
142
+
143
+ def find_with_glob_recurser(dir, parts, find_flags = 0, gave_char_class = false)
123
144
  return [] unless dir.respond_to? :[]
124
145
  pattern, *parts = parts
125
146
  matches =
@@ -149,7 +170,7 @@ module FakeFS
149
170
  if parts.empty? # we're done recursing
150
171
  matches
151
172
  else
152
- matches.map { |entry| find_recurser(entry, parts, find_flags, gave_char_class) }
173
+ matches.map { |entry| find_with_glob_recurser(entry, parts, find_flags, gave_char_class) }
153
174
  end
154
175
  end
155
176
 
@@ -232,7 +232,7 @@ module FakeFS
232
232
  list = Array(list)
233
233
  list.each do |file|
234
234
  chown(user, group, file)
235
- [FileSystem.find("#{file}/**/**")].flatten.each do |f|
235
+ [FileSystem.find_with_glob("#{file}/**/**")].flatten.each do |f|
236
236
  chown(user, group, f.to_s)
237
237
  end
238
238
  end
@@ -255,7 +255,7 @@ module FakeFS
255
255
  list = Array(list)
256
256
  list.each do |file|
257
257
  chmod(mode, file)
258
- [FileSystem.find("#{file}/**/**")].flatten.each do |f|
258
+ [FileSystem.find_with_glob("#{file}/**/**")].flatten.each do |f|
259
259
  chmod(mode, f.to_s)
260
260
  end
261
261
  end
data/lib/fakefs/irb.rb ADDED
@@ -0,0 +1,14 @@
1
+ require 'irb'
2
+
3
+ # Make the original file system classes available in IRB.
4
+ ::IRB::File = ::File
5
+ ::IRB::FileUtils = ::FileUtils
6
+ ::IRB::Dir = ::Dir
7
+ ::IRB::Pathname = ::Pathname
8
+
9
+ # We need to setup IRB early, because the setup process itself requires locale files.
10
+ # Otherwise we'll get an error from Budler
11
+ # Bundler::GemspecError: The gemspec for GEM_NAME was missing or broken.
12
+ # Try running `gem pristine GEM_NAME -v GEM_VERSION` to fix the cached spec.
13
+ # because file sytem in bundler is stubbed.
14
+ IRB.setup(binding.source_location[0], argv: [])
data/lib/fakefs/kernel.rb CHANGED
@@ -32,8 +32,8 @@ module FakeFS
32
32
  end
33
33
 
34
34
  hijack :open do |*args, &block|
35
- if args.first.start_with? '|'
36
- # This is a system command
35
+ # This is a system command or we're inside IRB internals
36
+ if args.first.start_with?('|') || self.class.to_s.start_with?("IRB::")
37
37
  ::FakeFS::Kernel.captives[:original][:open].call(*args, &block)
38
38
  else
39
39
  name = args.shift
data/lib/fakefs/safe.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require 'fileutils'
2
2
  require 'pathname'
3
3
  require 'fakefs/pry'
4
+ require 'fakefs/irb'
4
5
  require 'fakefs/base'
5
6
  require 'fakefs/fake/file'
6
7
  require 'fakefs/fake/dir'
@@ -1,7 +1,7 @@
1
1
  module FakeFS
2
2
  # Version module
3
3
  module Version
4
- VERSION = '2.2.0'.freeze
4
+ VERSION = '2.4.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: 2.2.0
4
+ version: 2.4.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: 2023-02-09 00:00:00.000000000 Z
15
+ date: 2023-02-13 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: bump
@@ -120,6 +120,7 @@ files:
120
120
  - lib/fakefs/fileutils.rb
121
121
  - lib/fakefs/globber.rb
122
122
  - lib/fakefs/io.rb
123
+ - lib/fakefs/irb.rb
123
124
  - lib/fakefs/kernel.rb
124
125
  - lib/fakefs/pathname.rb
125
126
  - lib/fakefs/pry.rb