fakefs 0.10.2 → 0.11.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2ad6c6a8b8e37f4902227e29ec8440158b83a888
4
- data.tar.gz: 69369bfb16c12cc091e9da9d701e48aa6dd0bbb1
3
+ metadata.gz: 775bb49c6d9342054b77a97f0896dc5cbb1a185d
4
+ data.tar.gz: ecaf59b2d26c5d719a9a5ed7647eb41ddd3ebdcc
5
5
  SHA512:
6
- metadata.gz: 37734960786a62c9fce7e425c5869f1f8084fd82427d0b901f7f8c2dc6c787645ba06fbb50a0c5532fcd4dd9949208c6f0c02c1c82396801d90dcbd860c7fdab
7
- data.tar.gz: 53654f93f29e9b7dc76bcf7e11f4086bca6a3e997c689ef58ca5fae6771295d1514acde28073b9da3a29e2090cd096c65d9c6d83f9e45666acb73cf5ce835dd9
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
- FakeFs vs `pp` --- `TypeError: superclass mismatch for class File`
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'` then `require 'fakefs'`.
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
@@ -1,7 +1,7 @@
1
1
  module FakeFS
2
2
  # Version module
3
3
  module Version
4
- VERSION = '0.10.2'.freeze
4
+ VERSION = '0.11.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: 0.10.2
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-01-12 00:00:00.000000000 Z
15
+ date: 2017-04-08 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: bundler