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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0f8537aa4162b3719ec77e1473ff51f15534088c
4
- data.tar.gz: e07735c800c2d357a4bccea0192f8f1f5d811de8
3
+ metadata.gz: ed6afbd6cc78d88527ac85b6bb0017a737a29b32
4
+ data.tar.gz: 79904ccdd7d7974cbda597ff28d986fda601ef83
5
5
  SHA512:
6
- metadata.gz: adbcc925b19c3ab19b319dab7e8d08d54d17c39524452b8824202e21000c66d75d9f9abe5b9f0a18fa2add08ea3ef547e0b6add273ae60154047f83117147503
7
- data.tar.gz: e81a430d7ecdd264a8e9b72f522786849622b5a4aedcacfa06a2f020fd91062ab3b2b6a63fdb19c67038a633374d6cc79b6656b88edf6650e369af607416a529
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
- Mocha is great. But when your library is all about manipulating the
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
- def test_creates_directory
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 we decide to use `mkdir_p` in our code. Refactoring
18
- code shouldn't necessitate refactoring tests.
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
- With FakeFS:
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
- def test_creates_directory
24
- Library.add "directory"
25
- assert File.directory?("directory")
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
- Woot.
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
- Don't Fake the FS Immediately
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
- If you are using fakefs in a rails project with bundler, you'll probably want
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", :require => "fakefs/safe"
80
+ gem "fakefs", require: "fakefs/safe"
67
81
  ```
68
82
 
69
-
70
83
  RSpec
71
84
  -----
72
85
 
73
- The above approach works with RSpec as well. In addition you may include
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
- module FakeFS
97
- class File
98
- def content_type
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
@@ -35,6 +35,10 @@ module FakeFS
35
35
  RealFile.join(parts)
36
36
  end
37
37
 
38
+ def self.path(file)
39
+ RealFile.path(file)
40
+ end
41
+
38
42
  def self.exist?(path)
39
43
  if File.symlink?(path)
40
44
  referent = File.expand_path(File.readlink(path), File.dirname(path))
@@ -1,7 +1,7 @@
1
1
  module FakeFS
2
2
  # Version module
3
3
  module Version
4
- VERSION = '0.8.0'
4
+ VERSION = '0.8.1'
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.8.0
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-02-03 00:00:00.000000000 Z
15
+ date: 2016-03-07 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: bundler