fakefs 1.6.0 → 1.7.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 +4 -4
- data/README.md +17 -0
- data/lib/fakefs/base.rb +10 -1
- data/lib/fakefs/io.rb +20 -0
- data/lib/fakefs/safe.rb +1 -0
- data/lib/fakefs/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ce09ec8d126543da5199d5a49c32ac6e7122895c2a07985a0216a9b45105f6bc
|
4
|
+
data.tar.gz: 0bbcbe864737bc302f7c8f079f448f8f3a89128fb5bcdcd35c42c062b8d7c2aa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 22575e664d52f74dc4c14d84d8981c751d33a43e94b52891e51e9b1cc5000838f25fd8f8709de48908f4d01ad489c51d4aa0865fc6b1c82b77c63e0814d93d01
|
7
|
+
data.tar.gz: e570516fa4e06a352b1b90bf643331b296f60684920a51a65a897913fa7c1a91a2a2ea092bcb363d8727442281851fa3f3fe497d09100bbf5e1b2f4bbe3e8274
|
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/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.read
|
6
|
+
def self.binread(*args, **keywords)
|
7
|
+
::FakeFS::File.read(*args, **keywords)
|
8
|
+
end
|
9
|
+
|
10
|
+
# Redirects ::IO.read to ::FakeFS::File.read
|
11
|
+
def self.read(*args, **keywords)
|
12
|
+
::FakeFS::File.read(*args, **keywords)
|
13
|
+
end
|
14
|
+
|
15
|
+
# Redirects ::IO.write to ::FakeFS::File.write
|
16
|
+
def self.write(*args, **keywords)
|
17
|
+
::FakeFS::File.write(*args, **keywords)
|
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.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Wanstrath
|
@@ -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
|