fakefs 2.5.0 → 2.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e4a0f94695c0070ec3847b3177acebdf1160f2064ba02d950d04a31385c43207
4
- data.tar.gz: bb0e627c6a32b31b8a1068cae3a5d4542b150d2ed06fecc0719a029889a0815c
3
+ metadata.gz: 765257209fdbaff32e467e7e5f0acbd9d324d6066fe569d5722a0568368a3288
4
+ data.tar.gz: fe4e318738464fd61e4b4d150a06285ea1a1923c92fc51bf244f27afa31b30a2
5
5
  SHA512:
6
- metadata.gz: 646053f9768a3a408c3d365ee2230f089131477decf9ccdb4e51bcd6c9080e1fb56bada71f2f661a685fa41866de408cab4b9de7c07cf50df3fe21b2dde09a85
7
- data.tar.gz: 87d29cda1d981939b941023104f5b7a1ee6f58ea9ca983ca16e379a4471c55ce1aea045a2a6c560b07bd760dc238d14f56b68dd7881a651991a587ca0294e0f8
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
@@ -1,7 +1,7 @@
1
1
  module FakeFS
2
2
  # Version module
3
3
  module Version
4
- VERSION = '2.5.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.5.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-05-23 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.