memfs 0.0.1
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 +7 -0
- data/.DS_Store +0 -0
- data/.gitignore +17 -0
- data/.rspec +2 -0
- data/.travis.yml +3 -0
- data/Gemfile +4 -0
- data/Guardfile +8 -0
- data/LICENSE.txt +22 -0
- data/README.md +128 -0
- data/Rakefile +6 -0
- data/lib/fileutils.rb +1738 -0
- data/lib/memfs/dir.rb +33 -0
- data/lib/memfs/fake/directory.rb +51 -0
- data/lib/memfs/fake/entry.rb +73 -0
- data/lib/memfs/fake/file/content.rb +47 -0
- data/lib/memfs/fake/file.rb +36 -0
- data/lib/memfs/fake/symlink.rb +32 -0
- data/lib/memfs/file/stat.rb +48 -0
- data/lib/memfs/file.rb +284 -0
- data/lib/memfs/file_system.rb +157 -0
- data/lib/memfs/filesystem_access.rb +7 -0
- data/lib/memfs/version.rb +3 -0
- data/lib/memfs.rb +100 -0
- data/memfs.gemspec +29 -0
- data/spec/fileutils_spec.rb +961 -0
- data/spec/memfs/dir_spec.rb +104 -0
- data/spec/memfs/fake/directory_spec.rb +115 -0
- data/spec/memfs/fake/entry_spec.rb +140 -0
- data/spec/memfs/fake/file/content_spec.rb +154 -0
- data/spec/memfs/fake/file_spec.rb +37 -0
- data/spec/memfs/fake/symlink_spec.rb +43 -0
- data/spec/memfs/file/stat_spec.rb +209 -0
- data/spec/memfs/file_spec.rb +928 -0
- data/spec/memfs/file_system_spec.rb +393 -0
- data/spec/memfs_spec.rb +54 -0
- data/spec/spec_helper.rb +20 -0
- metadata +203 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 07e362c240eee55e823d9e7b0ce0da5fe3d810c0
|
4
|
+
data.tar.gz: cb018e417f9972d2244cb9c2a89d0f8c570bb9b7
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 57a7489053cf43b9592c02128a01cbd484c2a57c025557f065b2170acc103330415161ca55e43b01cc430ac18adb152a911548ef8b0fad19dffa158e7d25f76b
|
7
|
+
data.tar.gz: 99a74244caf5093f89d19ebe975e5773b0cf342e3535da0d3652de482e2982342de495755ee0b40553759605074d35598c963b5b93c092e056fafcdee15ca1d0
|
data/.DS_Store
ADDED
Binary file
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Guardfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Simon COURTOIS
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,128 @@
|
|
1
|
+
# MemFs [](http://travis-ci.org/simonc/memfs) [](https://codeclimate.com/github/simonc/memfs) [](https://coveralls.io/r/simonc/memfs?branch=master)
|
2
|
+
|
3
|
+
MemFs is an in-memory filesystem that can be used for your tests.
|
4
|
+
|
5
|
+
When you're writing code that manipulates files, directories, symlinks, you need
|
6
|
+
to be able to test it without touching your hard drive. MemFs is made for it.
|
7
|
+
|
8
|
+
MemFs is intended for tests but you can use it for any other scenario needing in
|
9
|
+
memory file system.
|
10
|
+
|
11
|
+
MemFs is greatly inspired by the awesome
|
12
|
+
[FakeFs](https://github.com/defunkt/fakefs).
|
13
|
+
|
14
|
+
The main goal of MemFs is to be 100% compatible with the Ruby libraries like
|
15
|
+
FileUtils.
|
16
|
+
|
17
|
+
For french guys, the answer is yes, the joke in the name is intended ;)
|
18
|
+
|
19
|
+
## Take a look
|
20
|
+
|
21
|
+
Here is a simple example of MemFs usage:
|
22
|
+
|
23
|
+
``` ruby
|
24
|
+
MemFs.activate!
|
25
|
+
File.open('/test-file', 'w') { |f| f.puts "hello world" }
|
26
|
+
File.read('/test-file') #=> "hello world\n"
|
27
|
+
MemFs.deactivate!
|
28
|
+
|
29
|
+
File.exists?('/test-file') #=> false
|
30
|
+
|
31
|
+
# Or with the block syntax
|
32
|
+
|
33
|
+
MemFs.activate do
|
34
|
+
FileUtils.touch('/test-file', verbose: true, noop: true)
|
35
|
+
File.exists?('/test-file') #=> true
|
36
|
+
end
|
37
|
+
|
38
|
+
File.exists?('/test-file') #=> false
|
39
|
+
```
|
40
|
+
|
41
|
+
## Installation
|
42
|
+
|
43
|
+
Add this line to your application's Gemfile:
|
44
|
+
|
45
|
+
gem 'memfs'
|
46
|
+
|
47
|
+
And then execute:
|
48
|
+
|
49
|
+
$ bundle
|
50
|
+
|
51
|
+
Or install it yourself as:
|
52
|
+
|
53
|
+
$ gem install memfs
|
54
|
+
|
55
|
+
## Usage in tests
|
56
|
+
|
57
|
+
### Global activation
|
58
|
+
|
59
|
+
Add the following to your `spec_helper.rb`:
|
60
|
+
|
61
|
+
``` ruby
|
62
|
+
RSpec.configure do |config|
|
63
|
+
config.before do
|
64
|
+
MemFs.activate!
|
65
|
+
end
|
66
|
+
|
67
|
+
config.after do
|
68
|
+
MemFs.deactivate!
|
69
|
+
end
|
70
|
+
end
|
71
|
+
```
|
72
|
+
|
73
|
+
All the spec will be sandboxed in MemFs.
|
74
|
+
|
75
|
+
### Local activation
|
76
|
+
|
77
|
+
You can choose to activate MemFs only for a specific test:
|
78
|
+
|
79
|
+
``` ruby
|
80
|
+
describe FileCreator do
|
81
|
+
describe '.create_file' do
|
82
|
+
it "creates a file" do
|
83
|
+
MemFs.activate do
|
84
|
+
subject.create_file('test.rb')
|
85
|
+
expect(File.exists?('test.rb')).to be_true
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
```
|
91
|
+
|
92
|
+
No real file will be created during the test.
|
93
|
+
|
94
|
+
You can also use it for a specific `describe` block:
|
95
|
+
|
96
|
+
``` ruby
|
97
|
+
describe FileCreator do
|
98
|
+
before { MemFs.activate! }
|
99
|
+
after { MemFs.deactivate! }
|
100
|
+
|
101
|
+
describe '.create_file' do
|
102
|
+
it "creates a file" do
|
103
|
+
subject.create_file('test.rb')
|
104
|
+
expect(File.exists?('test.rb')).to be_true
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
```
|
109
|
+
|
110
|
+
## Requirements
|
111
|
+
|
112
|
+
* Ruby 2.0+
|
113
|
+
|
114
|
+
## Known issues
|
115
|
+
|
116
|
+
* MemFs doesn't implement IO so FileUtils.copy_stream is still the original one
|
117
|
+
|
118
|
+
## TODO
|
119
|
+
|
120
|
+
* Implement missing methods from `File`, `Dir` and `Stat`
|
121
|
+
|
122
|
+
## Contributing
|
123
|
+
|
124
|
+
1. Fork it
|
125
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
126
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
127
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
128
|
+
5. Create new Pull Request
|