fakefs 1.5.1 → 1.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +17 -0
- data/lib/fakefs/base.rb +10 -1
- data/lib/fakefs/file.rb +6 -10
- data/lib/fakefs/io.rb +20 -0
- data/lib/fakefs/safe.rb +1 -0
- data/lib/fakefs/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8e8927be6abec55f007c7e506a952e715415bacde44cf649e04c12d33b16ecab
|
4
|
+
data.tar.gz: a25489d361ce7ab7c5421c8685285507a19750ed87ef770432d5d10240cb5545
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 47fa5277d6012a8b89cda9f380949aac619286cd9b025f39b3b298aae3b5586474ae1858095886e9cdcdd93b1e9517bd63c51d0db50c6ffb8bae2a048b5f127d
|
7
|
+
data.tar.gz: 2f6871703b0c795b555b55e8792ecc926f866bfe95675518f01b0ff27e3cf1a17825f35b8547b9d2213b94a2d1270ed06a62727c7c8220669b9dbd20a927de5b
|
data/README.md
CHANGED
@@ -71,6 +71,23 @@ FakeFS do
|
|
71
71
|
end
|
72
72
|
```
|
73
73
|
|
74
|
+
Mocking IO methods
|
75
|
+
------------------
|
76
|
+
|
77
|
+
The IO class is the very basis for all Input and Output in Ruby, not only simple File reading/writting operations.
|
78
|
+
To avoid breaking critical components, the fakefs gem is not mocking IO methods by default.
|
79
|
+
|
80
|
+
However you can enable some very simple mocks using an explicit optin keyword:
|
81
|
+
|
82
|
+
``` ruby
|
83
|
+
|
84
|
+
require 'fakefs/safe'
|
85
|
+
|
86
|
+
FakeFS.activate!(io_mocks: true)
|
87
|
+
# your code
|
88
|
+
FakeFS.deactivate!
|
89
|
+
```
|
90
|
+
|
74
91
|
Rails
|
75
92
|
-----
|
76
93
|
|
data/lib/fakefs/base.rb
CHANGED
@@ -2,6 +2,7 @@ RealFile = File
|
|
2
2
|
RealFileTest = FileTest
|
3
3
|
RealFileUtils = FileUtils
|
4
4
|
RealDir = Dir
|
5
|
+
RealIO = IO
|
5
6
|
RealPathname = Pathname
|
6
7
|
|
7
8
|
def RealPathname(*args)
|
@@ -20,7 +21,7 @@ module FakeFS
|
|
20
21
|
end
|
21
22
|
|
22
23
|
# unconditionally activate
|
23
|
-
def activate!
|
24
|
+
def activate!(io_mocks: false)
|
24
25
|
Object.class_eval do
|
25
26
|
remove_const(:Dir)
|
26
27
|
remove_const(:File)
|
@@ -33,6 +34,12 @@ module FakeFS
|
|
33
34
|
const_set(:FileUtils, FakeFS::FileUtils)
|
34
35
|
const_set(:FileTest, FakeFS::FileTest)
|
35
36
|
const_set(:Pathname, FakeFS::Pathname)
|
37
|
+
|
38
|
+
if io_mocks
|
39
|
+
remove_const(:IO)
|
40
|
+
const_set(:IO, ::FakeFS::IO)
|
41
|
+
end
|
42
|
+
|
36
43
|
::FakeFS::Kernel.hijack!
|
37
44
|
end
|
38
45
|
|
@@ -48,12 +55,14 @@ module FakeFS
|
|
48
55
|
remove_const(:File)
|
49
56
|
remove_const(:FileTest)
|
50
57
|
remove_const(:FileUtils)
|
58
|
+
remove_const(:IO)
|
51
59
|
remove_const(:Pathname)
|
52
60
|
|
53
61
|
const_set(:Dir, RealDir)
|
54
62
|
const_set(:File, RealFile)
|
55
63
|
const_set(:FileTest, RealFileTest)
|
56
64
|
const_set(:FileUtils, RealFileUtils)
|
65
|
+
const_set(:IO, RealIO)
|
57
66
|
const_set(:Pathname, RealPathname)
|
58
67
|
::FakeFS::Kernel.unhijack!
|
59
68
|
end
|
data/lib/fakefs/file.rb
CHANGED
@@ -574,7 +574,7 @@ module FakeFS
|
|
574
574
|
end
|
575
575
|
|
576
576
|
def readpartial(*)
|
577
|
-
|
577
|
+
super
|
578
578
|
end
|
579
579
|
|
580
580
|
def atime
|
@@ -624,7 +624,10 @@ module FakeFS
|
|
624
624
|
end
|
625
625
|
|
626
626
|
def binmode?
|
627
|
-
|
627
|
+
@mode.is_a?(String) && (
|
628
|
+
@mode.include?('b') ||
|
629
|
+
@mode.include?('binary')
|
630
|
+
) && !@mode.include?('bom')
|
628
631
|
end
|
629
632
|
|
630
633
|
def close_on_exec=(_bool)
|
@@ -702,7 +705,7 @@ module FakeFS
|
|
702
705
|
|
703
706
|
def read(length = nil, buf = '')
|
704
707
|
read_buf = super(length, buf)
|
705
|
-
if
|
708
|
+
if binmode?
|
706
709
|
read_buf&.force_encoding('ASCII-8BIT')
|
707
710
|
else
|
708
711
|
read_buf&.force_encoding(Encoding.default_external)
|
@@ -869,13 +872,6 @@ module FakeFS
|
|
869
872
|
StringIO.new('', @mode)
|
870
873
|
end
|
871
874
|
|
872
|
-
def binary_mode?
|
873
|
-
@mode.is_a?(String) && (
|
874
|
-
@mode.include?('b') ||
|
875
|
-
@mode.include?('binary')
|
876
|
-
) && !@mode.include?('bom')
|
877
|
-
end
|
878
|
-
|
879
875
|
def check_file_existence!
|
880
876
|
raise Errno::ENOENT, @path.to_s unless @file
|
881
877
|
end
|
data/lib/fakefs/io.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
module FakeFS
|
2
|
+
# FakeFS IO class inherit root IO
|
3
|
+
# Only minimal mocks are provided as IO may be used by ruby's internals
|
4
|
+
class IO < ::IO
|
5
|
+
# Redirects ::IO.binread to ::FakeFS::File.binread
|
6
|
+
def self.binread(*args)
|
7
|
+
::FakeFS::File.binread(*args)
|
8
|
+
end
|
9
|
+
|
10
|
+
# Redirects ::IO.read to ::FakeFS::File.read
|
11
|
+
def self.read(*args)
|
12
|
+
::FakeFS::File.read(*args)
|
13
|
+
end
|
14
|
+
|
15
|
+
# Redirects ::IO.write to ::FakeFS::File.write
|
16
|
+
def self.write(*args)
|
17
|
+
::FakeFS::File.write(*args)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
data/lib/fakefs/safe.rb
CHANGED
data/lib/fakefs/version.rb
CHANGED
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.
|
4
|
+
version: 1.8.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: 2022-
|
15
|
+
date: 2022-06-25 00:00:00.000000000 Z
|
16
16
|
dependencies:
|
17
17
|
- !ruby/object:Gem::Dependency
|
18
18
|
name: bump
|
@@ -105,6 +105,7 @@ files:
|
|
105
105
|
- lib/fakefs/file_test.rb
|
106
106
|
- lib/fakefs/fileutils.rb
|
107
107
|
- lib/fakefs/globber.rb
|
108
|
+
- lib/fakefs/io.rb
|
108
109
|
- lib/fakefs/kernel.rb
|
109
110
|
- lib/fakefs/pathname.rb
|
110
111
|
- lib/fakefs/safe.rb
|