fakefs 2.4.0 → 2.6.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: 1233eb5f53d2726d129d63b73b637d324eccd588bf2b91a03ea9c66ce4eaf315
4
- data.tar.gz: 86ee22f93f37f84744da31813a43377a95b398337c45d08d2bddbfdab3794df9
3
+ metadata.gz: 765257209fdbaff32e467e7e5f0acbd9d324d6066fe569d5722a0568368a3288
4
+ data.tar.gz: fe4e318738464fd61e4b4d150a06285ea1a1923c92fc51bf244f27afa31b30a2
5
5
  SHA512:
6
- metadata.gz: e1df486ce2856004f54e6ef9216754e008843282d5ad14f95700ce66d3f49185359217855be28cd5a4603e7b3168f2c5aec4bc5618c0f356abb6759193e0a2bf
7
- data.tar.gz: 6cda052f83b1e7d3ec3e5ffcba0d29851eced5f450c4e60c24f459e8859b109b2ec22f94144e8cc2d24526eb254259c9ba08cf93b54e4d383e087d3275b73ca8
6
+ metadata.gz: 0b2d56c157243b4a95961f35c946697b229358af469692e91e72ac82eec1c0bdb6b97da19215335f26dd0837b731701bf9d072cb41fbb069f14868f7768d66fc
7
+ data.tar.gz: 46b48334206cd89958b8f3177f0e4050580a7c84891f8027e0e768cdfcc8685c22b5cadf03e0bdccb4ae4b9f7bbf788623be644377c53e6ab9277955b8472d9f
data/README.md CHANGED
@@ -128,7 +128,6 @@ describe "my spec" do
128
128
  end
129
129
  ```
130
130
 
131
-
132
131
  FakeFs --- `TypeError: superclass mismatch for class File`
133
132
  --------------
134
133
 
@@ -168,7 +167,7 @@ yourself on the equivalent FakeFS classes. For example,
168
167
  [FileMagic](https://rubygems.org/gems/ruby-filemagic) adds `File#content_type`.
169
168
  A fake version can be provided as follows:
170
169
 
171
- ``` ruby
170
+ ```ruby
172
171
  FakeFS::File.class_eval do
173
172
  def content_type
174
173
  'fake/file'
@@ -176,6 +175,15 @@ FakeFS::File.class_eval do
176
175
  end
177
176
  ```
178
177
 
178
+ File.lock
179
+ ---------
180
+
181
+ Warning: experimental and might break if you obtain more that one flock per file using different descriptors
182
+
183
+ ```ruby
184
+ require 'fakefs/flockable_file'
185
+ ```
186
+
179
187
  Caveats
180
188
  -------
181
189
 
@@ -56,7 +56,11 @@ module FakeFS
56
56
  assert_dir d
57
57
  object.name = parts.last
58
58
  object.parent = d
59
- d[parts.last] ||= object
59
+ if object.is_a? FakeDir
60
+ d[parts.last] ||= object
61
+ else
62
+ d[parts.last] = object
63
+ end
60
64
  end
61
65
 
62
66
  # copies directories and files from the real filesystem
@@ -0,0 +1,46 @@
1
+ require_relative 'file'
2
+
3
+ module FakeFS
4
+ # Be careful using this, as it may break things if
5
+ # you obtain more that one flock per file using
6
+ # different descriptors.
7
+ # Real flock call blocks/returns false in that case -
8
+ # see https://man7.org/linux/man-pages/man2/flock.2.html,
9
+ # it says it "may be denied", but it does, it fact, deny.
10
+ # This implementation simply returns 0.
11
+ # This may also be a problem if you, it fact, are accessing a
12
+ # real file, which is locked by another process.
13
+ class File < StringIO
14
+ # yep, File::LOCK_UN | File::LOCK_NB is allowed
15
+ FAKE_FS_ALLOWED_FLOCK_MODES = [RealFile::LOCK_EX, RealFile::LOCK_SH, RealFile::LOCK_UN].flat_map do |mode|
16
+ [mode, mode | RealFile::LOCK_NB]
17
+ end.freeze
18
+
19
+ remove_method :flock
20
+
21
+ def flock(mode)
22
+ # all successful calls - even UN - seem to return 0
23
+ unless mode.is_a?(Integer)
24
+ unless mode.respond_to?(:to_int)
25
+ raise TypeError, "no implicit conversion of #{mode.class} into Integer"
26
+ end
27
+ int_mode = mode.to_int
28
+
29
+ unless int_mode.is_a?(Integer)
30
+ raise TypeError, "can't convert Object to Integer (#{mode.class}#to_int gives #{int_mode.class})"
31
+ end
32
+ mode = int_mode
33
+ end
34
+
35
+ # real implementation may not fail on `flock 11111` - but fails with `f1.flock 11111111` - or may fail
36
+ # with another error - `f1.flock 1111111111111` gives `integer 1111111111111 too big to convert to `int'
37
+ # but I think it's safer to allow only documented modes.
38
+ unless FAKE_FS_ALLOWED_FLOCK_MODES.include?(mode)
39
+ # real exception
40
+ # Invalid argument @ rb_file_flock - filepath (Errno::EINVAL)
41
+ raise Errno::EINVAL.new(@path, 'rb_file_flock')
42
+ end
43
+ 0
44
+ end
45
+ end
46
+ end
data/lib/fakefs/kernel.rb CHANGED
@@ -18,8 +18,8 @@ module FakeFS
18
18
  def self.unhijack!
19
19
  captives[:original].each do |name, _prc|
20
20
  ::Kernel.send(:remove_method, name.to_sym)
21
- ::Kernel.send(:define_method, name.to_sym, proc do |*args, &block|
22
- ::FakeFS::Kernel.captives[:original][name].call(*args, &block)
21
+ ::Kernel.send(:define_method, name.to_sym, proc do |*args, **kwargs, &block|
22
+ ::FakeFS::Kernel.captives[:original][name].call(*args, **kwargs, &block)
23
23
  end)
24
24
  ::Kernel.send(:private, name.to_sym)
25
25
  end
@@ -1,7 +1,7 @@
1
1
  module FakeFS
2
2
  # Version module
3
3
  module Version
4
- VERSION = '2.4.0'.freeze
4
+ VERSION = '2.6.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.4.0
4
+ version: 2.6.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-13 00:00:00.000000000 Z
15
+ date: 2024-12-08 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: bump
@@ -118,6 +118,7 @@ files:
118
118
  - lib/fakefs/file_system.rb
119
119
  - lib/fakefs/file_test.rb
120
120
  - lib/fakefs/fileutils.rb
121
+ - lib/fakefs/flockable_file.rb
121
122
  - lib/fakefs/globber.rb
122
123
  - lib/fakefs/io.rb
123
124
  - lib/fakefs/irb.rb
@@ -146,7 +147,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
146
147
  - !ruby/object:Gem::Version
147
148
  version: '0'
148
149
  requirements: []
149
- rubygems_version: 3.4.0.dev
150
+ rubygems_version: 3.5.11
150
151
  signing_key:
151
152
  specification_version: 4
152
153
  summary: A fake filesystem. Use it in your tests.