fakefs 0.10.2 → 0.11.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 +30 -2
- data/lib/fakefs/base.rb +15 -0
- data/lib/fakefs/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 775bb49c6d9342054b77a97f0896dc5cbb1a185d
|
4
|
+
data.tar.gz: ecaf59b2d26c5d719a9a5ed7647eb41ddd3ebdcc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9b76df497c9c26676a079649ec241815fb972579acb5d28f884d73dfab6c9708d94807f96d252a98134a602c58b719e511b738fc0efec9eef3cfa8e9e65513c2
|
7
|
+
data.tar.gz: dfa04c77cbf2c5c349f9b9a90c021ea4fb5c1fffd74354c68a27e3faddff373a641117e66824806ba8cab18e3d660c2f51e16edfd4ce68fbfea8e727b9bed27b
|
data/README.md
CHANGED
@@ -96,10 +96,35 @@ end
|
|
96
96
|
|
97
97
|
See `lib/fakefs/spec_helpers.rb` for more info.
|
98
98
|
|
99
|
-
|
99
|
+
To use FakeFS within a single test and be guaranteed a fresh fake filesystem:
|
100
|
+
``` ruby
|
101
|
+
require 'fakefs/safe'
|
102
|
+
|
103
|
+
describe "my spec" do
|
104
|
+
context "my context" do
|
105
|
+
it "does something to the filesystem"
|
106
|
+
FakeFS.with_fresh do
|
107
|
+
# whatever it does
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
```
|
113
|
+
|
114
|
+
|
115
|
+
FakeFs --- `TypeError: superclass mismatch for class File`
|
100
116
|
--------------
|
101
117
|
|
102
|
-
`pp` and `fakefs` collide, `require 'pp'`
|
118
|
+
`pp` and `fakefs` may collide, even if you're not actually explicitly using `pp`. Adding `require 'pp'` before `require 'fakefs'` should fix the problem locally. For a module-level fix, try adding it to the `Gemfile`:
|
119
|
+
|
120
|
+
```ruby
|
121
|
+
source "https://rubygems.org"
|
122
|
+
|
123
|
+
require 'pp'
|
124
|
+
# list of gems
|
125
|
+
```
|
126
|
+
|
127
|
+
The problem may not be limited to `pp`; any gems that add to `File` may be affected.
|
103
128
|
|
104
129
|
Working with existing files
|
105
130
|
---------------------------
|
@@ -158,6 +183,9 @@ is the only thing that is guaranteed to exist, namely the root (i.e. `/`). This
|
|
158
183
|
may be important when upgrading from v0.4.x to v0.5.x, especially if you depend
|
159
184
|
on the real working directory while using FakeFS.
|
160
185
|
|
186
|
+
FakeFS replaces File and FileUtils, but is not a filesystem replacement, so gems
|
187
|
+
that use strange commands or C might circumvent it. For example, the `sqlite3`
|
188
|
+
gem will completely ignore any faked filesystem.
|
161
189
|
|
162
190
|
Speed?
|
163
191
|
------
|
data/lib/fakefs/base.rb
CHANGED
@@ -21,6 +21,7 @@ module FakeFS
|
|
21
21
|
@activated ? true : false
|
22
22
|
end
|
23
23
|
|
24
|
+
# unconditionally activate
|
24
25
|
def activate!
|
25
26
|
Object.class_eval do
|
26
27
|
remove_const(:Dir)
|
@@ -42,6 +43,7 @@ module FakeFS
|
|
42
43
|
true
|
43
44
|
end
|
44
45
|
|
46
|
+
# unconditionally deactivate
|
45
47
|
def deactivate!
|
46
48
|
Object.class_eval do
|
47
49
|
remove_const(:Dir)
|
@@ -63,6 +65,18 @@ module FakeFS
|
|
63
65
|
true
|
64
66
|
end
|
65
67
|
|
68
|
+
# unconditionally clear the fake filesystem
|
69
|
+
def clear!
|
70
|
+
::FakeFS::FileSystem.clear
|
71
|
+
end
|
72
|
+
|
73
|
+
# present a fresh new fake filesystem to the block
|
74
|
+
def with_fresh(&block)
|
75
|
+
clear!
|
76
|
+
with(&block)
|
77
|
+
end
|
78
|
+
|
79
|
+
# present the fake filesystem to the block
|
66
80
|
def with
|
67
81
|
if activated?
|
68
82
|
yield
|
@@ -76,6 +90,7 @@ module FakeFS
|
|
76
90
|
end
|
77
91
|
end
|
78
92
|
|
93
|
+
# present a non-fake filesystem to the block
|
79
94
|
def without
|
80
95
|
if !activated?
|
81
96
|
yield
|
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: 0.
|
4
|
+
version: 0.11.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: 2017-
|
15
|
+
date: 2017-04-08 00:00:00.000000000 Z
|
16
16
|
dependencies:
|
17
17
|
- !ruby/object:Gem::Dependency
|
18
18
|
name: bundler
|