fakefs 0.8.0 → 0.8.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.markdown +41 -39
- data/lib/fakefs/file.rb +4 -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: ed6afbd6cc78d88527ac85b6bb0017a737a29b32
|
4
|
+
data.tar.gz: 79904ccdd7d7974cbda597ff28d986fda601ef83
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 72ba95d6739f30d35cb24735b20f94d919875bfe1576e43e51a868b7458e15e1978f52578f0ff4cb6b14c8da4b5a3d790577f8c6b70e0bb76998021156bb82ce
|
7
|
+
data.tar.gz: 7fd93d529856d687558b60dc12b0a03056691b88673ca373f688615c0eee27b6a9fc71e0b7231d71c8dceb57542f852803cc055e54f0cc9243aa2557202d8812
|
data/README.markdown
CHANGED
@@ -1,49 +1,64 @@
|
|
1
1
|
FakeFS [![build status](https://secure.travis-ci.org/defunkt/fakefs.svg?branch=master)](https://secure.travis-ci.org/defunkt/fakefs)
|
2
2
|
======
|
3
3
|
|
4
|
-
|
5
|
-
filesystem, you really want to test the behavior and not the implementation.
|
6
|
-
|
7
|
-
If you're mocking and stubbing every call to FileUtils or File, you're
|
8
|
-
tightly coupling your tests with the implementation.
|
4
|
+
Mocking calls to FileUtils or File means tightly coupling tests with the implementation.
|
9
5
|
|
10
6
|
``` ruby
|
11
|
-
|
7
|
+
it "creates a directory" do
|
12
8
|
FileUtils.expects(:mkdir).with("directory").once
|
13
9
|
Library.add "directory"
|
14
10
|
end
|
15
11
|
```
|
16
12
|
|
17
|
-
The above test will break if
|
18
|
-
code
|
13
|
+
The above test will break if `mkdir_p` is used instead.
|
14
|
+
Refactoring code should not necessitate refactoring tests.
|
15
|
+
|
16
|
+
A better approach is to use a temp directory if you are working with relative directories.
|
17
|
+
|
18
|
+
```Ruby
|
19
|
+
require 'tmpdir'
|
20
|
+
|
21
|
+
it "creates a directory" do
|
22
|
+
Dir.mktmpdir do |dir|
|
23
|
+
Dir.chdir dir do
|
24
|
+
Library.add "directory"
|
25
|
+
assert File.directory?("directory")
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
```
|
19
30
|
|
20
|
-
|
31
|
+
But if you are working with absolute directories or do not want to use temporary directories, use FakeFS instead:
|
21
32
|
|
22
33
|
``` ruby
|
23
|
-
|
24
|
-
|
25
|
-
|
34
|
+
it "creates a directory" do
|
35
|
+
FakeFS do
|
36
|
+
Library.add "directory"
|
37
|
+
assert File.directory?("directory")
|
38
|
+
end
|
26
39
|
end
|
27
40
|
```
|
28
41
|
|
29
|
-
|
42
|
+
Installation
|
43
|
+
------------
|
30
44
|
|
45
|
+
```Bash
|
46
|
+
gem install fakefs
|
47
|
+
```
|
31
48
|
|
32
49
|
Usage
|
33
50
|
-----
|
34
51
|
|
52
|
+
To fake out the FS:
|
53
|
+
|
35
54
|
``` ruby
|
36
55
|
require 'fakefs'
|
37
|
-
|
38
|
-
# That's it.
|
39
56
|
```
|
40
57
|
|
41
|
-
|
42
|
-
|
58
|
+
Temporarily faking the FS
|
59
|
+
-------------------------
|
43
60
|
|
44
61
|
``` ruby
|
45
|
-
gem "fakefs", :require => "fakefs/safe"
|
46
|
-
|
47
62
|
require 'fakefs/safe'
|
48
63
|
|
49
64
|
FakeFS.activate!
|
@@ -59,19 +74,16 @@ end
|
|
59
74
|
Rails
|
60
75
|
-----
|
61
76
|
|
62
|
-
|
63
|
-
to specify the following in your Gemfile:
|
77
|
+
In rails projects, add this to your Gemfile:
|
64
78
|
|
65
79
|
``` ruby
|
66
|
-
gem "fakefs", :
|
80
|
+
gem "fakefs", require: "fakefs/safe"
|
67
81
|
```
|
68
82
|
|
69
|
-
|
70
83
|
RSpec
|
71
84
|
-----
|
72
85
|
|
73
|
-
|
74
|
-
FakeFS::SpecHelpers to turn FakeFS on and off in a given example group:
|
86
|
+
Include FakeFS::SpecHelpers to turn FakeFS on and off in an example group:
|
75
87
|
|
76
88
|
``` ruby
|
77
89
|
require 'fakefs/spec_helpers'
|
@@ -93,16 +105,14 @@ yourself on the equivalent FakeFS classes. For example,
|
|
93
105
|
A fake version can be provided as follows:
|
94
106
|
|
95
107
|
``` ruby
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
'fake/file'
|
100
|
-
end
|
108
|
+
FakeFS::File.class_eval do
|
109
|
+
def content_type
|
110
|
+
'fake/file'
|
101
111
|
end
|
102
112
|
end
|
103
113
|
```
|
104
114
|
|
105
|
-
How is this different than MockFS?
|
115
|
+
How is this different than [MockFS](http://mockfs.rubyforge.org/) ?
|
106
116
|
----------------------------------
|
107
117
|
|
108
118
|
FakeFS provides a test suite and works with symlinks. It's also strictly a
|
@@ -133,14 +143,6 @@ Speed?
|
|
133
143
|
<http://gist.github.com/156091>
|
134
144
|
|
135
145
|
|
136
|
-
Installation
|
137
|
-
------------
|
138
|
-
|
139
|
-
### [RubyGems](https://rubygems.org/)
|
140
|
-
|
141
|
-
$ gem install fakefs
|
142
|
-
|
143
|
-
|
144
146
|
Contributing
|
145
147
|
------------
|
146
148
|
|
data/lib/fakefs/file.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: 0.8.
|
4
|
+
version: 0.8.1
|
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: 2016-
|
15
|
+
date: 2016-03-07 00:00:00.000000000 Z
|
16
16
|
dependencies:
|
17
17
|
- !ruby/object:Gem::Dependency
|
18
18
|
name: bundler
|