fakefs 1.2.3 → 1.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: '05218e3b531393a48c565fe787759d6e4e89c64cc89047c3685d199ef0775921'
4
- data.tar.gz: 59a65166fe4d0bc0dbc4d3fa002e0180d98a548548542447568d9e9ea45b0977
3
+ metadata.gz: e62fc76c0ca1c48b09e7b4051d5888a3f361b7f6e72434275bf3820d972c05d0
4
+ data.tar.gz: fc2e3377b5948b04302f06893fd4b961311699c597dfe431a9ab04046b488d67
5
5
  SHA512:
6
- metadata.gz: a599803b52fd91196e05878a5570218de25884e2e0e47becebb49f0006b2d909b1de86f0699e983f7f315aedb2b789abe568765b42eefa2f8dce1080e6a2dc86
7
- data.tar.gz: e6a99b4c246abbc1f2de43420b82dbc48700cdb50851c8b76906a14ed6147a4892511b7c70cbbf4a67c6d66ee9b8824db3dbc331da22f47614a6de83bf789b3b
6
+ metadata.gz: 3c43a34b04c1d010a783da8646dfff11d50892a15faa5660730e9d284b046dfdf921adbcaff550ca0b2a25bbc5537060b457f37e11c7d64aa6bb7271cd8975ae
7
+ data.tar.gz: e0523fab127204c4400921d2e1bc6bdbf8ed6c61b8c731707d92b8fa916e1c7320290c18546168bee757888dfd2ae3ad5953cb1b55557e9e5f40997428cb66d4
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- FakeFS [![build status](https://travis-ci.org/fakefs/fakefs.svg?branch=master)](https://travis-ci.org/fakefs/fakefs)
1
+ FakeFS [![build status](https://github.com/fakefs/fakefs/workflows/CI/badge.svg)](https://github.com/fakefs/fakefs/actions?query=branch%3Amaster)
2
2
  ======
3
3
 
4
4
  Mocking calls to FileUtils or File means tightly coupling tests with the implementation.
@@ -202,7 +202,7 @@ Meta
202
202
  * Code: `git clone git://github.com/fakefs/fakefs.git`
203
203
  * Home: <https://github.com/fakefs/fakefs>
204
204
  * Bugs: <https://github.com/fakefs/fakefs/issues>
205
- * Test: <https://travis-ci.org/fakefs/fakefs>
205
+ * Test: <https://github.com/fakefs/fakefs/actions?query=branch%3Amaster>
206
206
  * Gems: <https://rubygems.org/gems/fakefs>
207
207
 
208
208
  [0]: https://help.github.com/forking/
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
data/lib/fakefs/file.rb CHANGED
@@ -197,11 +197,11 @@ module FakeFS
197
197
  file.read(length)
198
198
  end
199
199
 
200
- def self.readlines(path)
200
+ def self.readlines(path, chomp: false)
201
201
  file = new(path)
202
202
  if file.exists?
203
203
  FileSystem.find(path).atime = Time.now
204
- file.readlines
204
+ chomp ? file.readlines.map(&:chomp) : file.readlines
205
205
  else
206
206
  raise Errno::ENOENT
207
207
  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
@@ -1,7 +1,7 @@
1
1
  module FakeFS
2
2
  # Version module
3
3
  module Version
4
- VERSION = '1.2.3'.freeze
4
+ VERSION = '1.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: 1.2.3
4
+ version: 1.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: 2020-12-06 00:00:00.000000000 Z
15
+ date: 2021-10-21 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.2.16
133
133
  signing_key:
134
134
  specification_version: 4
135
135
  summary: A fake filesystem. Use it in your tests.