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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9d7b3b25ef85a316cd2eb054da61b981921c50062f28ee9f5527c0a80993a609
4
- data.tar.gz: b89a13206e9056790d8b9a2d36b37b3d0fc0591b2b94cfc453ebae211a0e421f
3
+ metadata.gz: ce09ec8d126543da5199d5a49c32ac6e7122895c2a07985a0216a9b45105f6bc
4
+ data.tar.gz: 0bbcbe864737bc302f7c8f079f448f8f3a89128fb5bcdcd35c42c062b8d7c2aa
5
5
  SHA512:
6
- metadata.gz: 868d13ee9a97b8d0f74da133ba129de776d5a5fb3b03c24f586330852e8c264eb42d9807a314ec68af4a34c556319b40f289ea94618d653b4ba44f083eb1f93e
7
- data.tar.gz: 2ff056cc43d651381c3ad9112ae9df44b8893746a17969528633a358305100d2cc2f24b956a746f5837cf3c79550ca918446638ae1a6eef2dd05ff68d7e6cecb
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
@@ -11,5 +11,6 @@ require 'fakefs/file'
11
11
  require 'fakefs/file_test'
12
12
  require 'fakefs/dir'
13
13
  require 'fakefs/globber'
14
+ require 'fakefs/io'
14
15
  require 'fakefs/pathname'
15
16
  require 'fakefs/kernel'
@@ -1,7 +1,7 @@
1
1
  module FakeFS
2
2
  # Version module
3
3
  module Version
4
- VERSION = '1.6.0'.freeze
4
+ VERSION = '1.7.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.6.0
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