memfs 0.4.0 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +2 -0
- data/CHANGELOG.md +4 -0
- data/README.md +1 -1
- data/lib/memfs/dir.rb +5 -1
- data/lib/memfs/file.rb +14 -4
- data/lib/memfs/version.rb +1 -1
- data/spec/memfs/dir_spec.rb +6 -3
- data/spec/memfs/file_spec.rb +58 -0
- metadata +51 -27
- checksums.yaml +0 -7
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -19,7 +19,7 @@ MemFs is greatly inspired by the awesome
|
|
19
19
|
The main goal of MemFs is to be 100% compatible with the Ruby libraries like
|
20
20
|
FileUtils.
|
21
21
|
|
22
|
-
For
|
22
|
+
For French people, the answer is yes, the joke in the name is intended ;)
|
23
23
|
|
24
24
|
## Take a look
|
25
25
|
|
data/lib/memfs/dir.rb
CHANGED
@@ -147,7 +147,11 @@ module MemFs
|
|
147
147
|
|
148
148
|
private
|
149
149
|
|
150
|
-
|
150
|
+
if defined?(File::FNM_EXTGLOB)
|
151
|
+
GLOB_FLAGS = File::FNM_EXTGLOB | File::FNM_PATHNAME
|
152
|
+
else
|
153
|
+
GLOB_FLAGS = File::FNM_PATHNAME
|
154
|
+
end
|
151
155
|
|
152
156
|
attr_accessor :entry, :max_seek, :state
|
153
157
|
|
data/lib/memfs/file.rb
CHANGED
@@ -5,11 +5,9 @@ module MemFs
|
|
5
5
|
class File
|
6
6
|
extend FilesystemAccess
|
7
7
|
extend SingleForwardable
|
8
|
+
include Enumerable
|
8
9
|
include FilesystemAccess
|
9
|
-
|
10
|
-
OriginalFile.constants.grep(/^[A-Z_]+$/).each do |const|
|
11
|
-
const_set const, OriginalFile.const_get(const)
|
12
|
-
end
|
10
|
+
include OriginalFile::Constants
|
13
11
|
|
14
12
|
MODE_MAP = {
|
15
13
|
'r' => RDONLY,
|
@@ -262,6 +260,13 @@ module MemFs
|
|
262
260
|
closed
|
263
261
|
end
|
264
262
|
|
263
|
+
def each(sep = $/, &block)
|
264
|
+
return to_enum(__callee__) unless block_given?
|
265
|
+
fail IOError, 'not opened for reading' unless readable?
|
266
|
+
content.each_line(sep) { |line| block.call(line) }
|
267
|
+
self
|
268
|
+
end
|
269
|
+
|
265
270
|
def lstat
|
266
271
|
File.lstat(path)
|
267
272
|
end
|
@@ -373,6 +378,11 @@ module MemFs
|
|
373
378
|
(opening_mode & File::CREAT).nonzero?
|
374
379
|
end
|
375
380
|
|
381
|
+
def readable?
|
382
|
+
(opening_mode & File::RDWR).nonzero? ||
|
383
|
+
(opening_mode | File::RDONLY).zero?
|
384
|
+
end
|
385
|
+
|
376
386
|
def truncate_file?
|
377
387
|
(opening_mode & File::TRUNC).nonzero?
|
378
388
|
end
|
data/lib/memfs/version.rb
CHANGED
data/spec/memfs/dir_spec.rb
CHANGED
@@ -215,7 +215,10 @@ module MemFs
|
|
215
215
|
it_behaves_like 'returning matching filenames', '/test?', %w[/test0 /test1 /test2]
|
216
216
|
it_behaves_like 'returning matching filenames', '/test[01]', %w[/test0 /test1]
|
217
217
|
it_behaves_like 'returning matching filenames', '/test[^2]', %w[/test0 /test1]
|
218
|
-
|
218
|
+
|
219
|
+
if defined?(File::FNM_EXTGLOB)
|
220
|
+
it_behaves_like 'returning matching filenames', '/test{1,2}', %w[/test1 /test2]
|
221
|
+
end
|
219
222
|
|
220
223
|
context 'when a flag is given' do
|
221
224
|
it 'uses it to compare filenames' do
|
@@ -381,7 +384,7 @@ module MemFs
|
|
381
384
|
end
|
382
385
|
|
383
386
|
describe '#path' do
|
384
|
-
it "returns the path parameter passed to dir
|
387
|
+
it "returns the path parameter passed to dir's constructor" do
|
385
388
|
expect(instance.path).to eq '/test'
|
386
389
|
end
|
387
390
|
end
|
@@ -492,7 +495,7 @@ module MemFs
|
|
492
495
|
end
|
493
496
|
|
494
497
|
describe '#to_path' do
|
495
|
-
it "returns the path parameter passed to dir
|
498
|
+
it "returns the path parameter passed to dir's constructor" do
|
496
499
|
expect(instance.to_path).to eq '/test'
|
497
500
|
end
|
498
501
|
end
|
data/spec/memfs/file_spec.rb
CHANGED
@@ -14,6 +14,10 @@ module MemFs
|
|
14
14
|
subject.symlink '/no-file', '/no-link'
|
15
15
|
end
|
16
16
|
|
17
|
+
it 'implements Enumerable' do
|
18
|
+
expect(subject.ancestors).to include(Enumerable)
|
19
|
+
end
|
20
|
+
|
17
21
|
describe '.absolute_path' do
|
18
22
|
before :each do
|
19
23
|
MemFs::Dir.chdir('/test-dir')
|
@@ -1724,6 +1728,60 @@ module MemFs
|
|
1724
1728
|
end
|
1725
1729
|
end
|
1726
1730
|
|
1731
|
+
describe '#each' do
|
1732
|
+
let(:file) { subject.open('/test-file') }
|
1733
|
+
let(:lines) do
|
1734
|
+
["Hello this is a file\n", "with some lines\n", "for test purpose\n"]
|
1735
|
+
end
|
1736
|
+
|
1737
|
+
before do
|
1738
|
+
subject.open('/test-file', 'w') do |f|
|
1739
|
+
lines.each { |line| f.puts line }
|
1740
|
+
end
|
1741
|
+
end
|
1742
|
+
|
1743
|
+
it 'executes the block for every line in the file' do
|
1744
|
+
expect{ |blk| file.each(&blk) }.to \
|
1745
|
+
yield_successive_args(*lines)
|
1746
|
+
end
|
1747
|
+
|
1748
|
+
it 'returns the file itself' do
|
1749
|
+
expect(file.each {}).to be file
|
1750
|
+
end
|
1751
|
+
|
1752
|
+
context 'when a separator is given' do
|
1753
|
+
it 'uses this separator to split lines' do
|
1754
|
+
expected_lines = [
|
1755
|
+
"Hello this is a f",
|
1756
|
+
"ile\nwith some lines\nf",
|
1757
|
+
"or test purpose\n"
|
1758
|
+
]
|
1759
|
+
expect{ |blk| file.each('f', &blk) }.to \
|
1760
|
+
yield_successive_args(*expected_lines)
|
1761
|
+
end
|
1762
|
+
end
|
1763
|
+
|
1764
|
+
context 'when the file is not open for reading' do
|
1765
|
+
let(:file) { subject.open('/test-file', 'w') }
|
1766
|
+
|
1767
|
+
it 'raises an exception' do
|
1768
|
+
expect{ file.each { |l| puts l } }.to raise_error(IOError)
|
1769
|
+
end
|
1770
|
+
|
1771
|
+
context 'when no block is given' do
|
1772
|
+
it 'does not raise an exception' do
|
1773
|
+
expect{ file.each }.not_to raise_error
|
1774
|
+
end
|
1775
|
+
end
|
1776
|
+
end
|
1777
|
+
|
1778
|
+
context 'when no block is given' do
|
1779
|
+
it 'returns an enumerator' do
|
1780
|
+
expect(file.each.next).to eq "Hello this is a file\n"
|
1781
|
+
end
|
1782
|
+
end
|
1783
|
+
end
|
1784
|
+
|
1727
1785
|
describe '#lstat' do
|
1728
1786
|
it "returns the File::Stat object of the file" do
|
1729
1787
|
expect(file.lstat).to be_a(File::Stat)
|
metadata
CHANGED
@@ -1,125 +1,142 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: memfs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.1
|
5
|
+
prerelease:
|
5
6
|
platform: ruby
|
6
7
|
authors:
|
7
8
|
- Simon COURTOIS
|
8
9
|
autorequire:
|
9
10
|
bindir: bin
|
10
11
|
cert_chain: []
|
11
|
-
date: 2014-07-
|
12
|
+
date: 2014-07-24 00:00:00.000000000 Z
|
12
13
|
dependencies:
|
13
14
|
- !ruby/object:Gem::Dependency
|
14
15
|
name: coveralls
|
15
16
|
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
16
18
|
requirements:
|
17
|
-
- -
|
19
|
+
- - ~>
|
18
20
|
- !ruby/object:Gem::Version
|
19
21
|
version: '0.6'
|
20
22
|
type: :development
|
21
23
|
prerelease: false
|
22
24
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
23
26
|
requirements:
|
24
|
-
- -
|
27
|
+
- - ~>
|
25
28
|
- !ruby/object:Gem::Version
|
26
29
|
version: '0.6'
|
27
30
|
- !ruby/object:Gem::Dependency
|
28
31
|
name: rake
|
29
32
|
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
30
34
|
requirements:
|
31
|
-
- -
|
35
|
+
- - ~>
|
32
36
|
- !ruby/object:Gem::Version
|
33
37
|
version: '10.0'
|
34
38
|
type: :development
|
35
39
|
prerelease: false
|
36
40
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
37
42
|
requirements:
|
38
|
-
- -
|
43
|
+
- - ~>
|
39
44
|
- !ruby/object:Gem::Version
|
40
45
|
version: '10.0'
|
41
46
|
- !ruby/object:Gem::Dependency
|
42
47
|
name: rspec
|
43
48
|
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
44
50
|
requirements:
|
45
|
-
- -
|
51
|
+
- - ~>
|
46
52
|
- !ruby/object:Gem::Version
|
47
53
|
version: '2.14'
|
48
54
|
type: :development
|
49
55
|
prerelease: false
|
50
56
|
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
51
58
|
requirements:
|
52
|
-
- -
|
59
|
+
- - ~>
|
53
60
|
- !ruby/object:Gem::Version
|
54
61
|
version: '2.14'
|
55
62
|
- !ruby/object:Gem::Dependency
|
56
63
|
name: guard
|
57
64
|
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
58
66
|
requirements:
|
59
|
-
- -
|
67
|
+
- - ~>
|
60
68
|
- !ruby/object:Gem::Version
|
61
69
|
version: '1.5'
|
62
70
|
type: :development
|
63
71
|
prerelease: false
|
64
72
|
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
65
74
|
requirements:
|
66
|
-
- -
|
75
|
+
- - ~>
|
67
76
|
- !ruby/object:Gem::Version
|
68
77
|
version: '1.5'
|
69
78
|
- !ruby/object:Gem::Dependency
|
70
79
|
name: guard-rspec
|
71
80
|
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
72
82
|
requirements:
|
73
|
-
- -
|
83
|
+
- - ~>
|
74
84
|
- !ruby/object:Gem::Version
|
75
85
|
version: '2.1'
|
76
86
|
type: :development
|
77
87
|
prerelease: false
|
78
88
|
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
79
90
|
requirements:
|
80
|
-
- -
|
91
|
+
- - ~>
|
81
92
|
- !ruby/object:Gem::Version
|
82
93
|
version: '2.1'
|
83
94
|
- !ruby/object:Gem::Dependency
|
84
95
|
name: rb-inotify
|
85
96
|
requirement: !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
86
98
|
requirements:
|
87
|
-
- -
|
99
|
+
- - ~>
|
88
100
|
- !ruby/object:Gem::Version
|
89
101
|
version: '0.8'
|
90
102
|
type: :development
|
91
103
|
prerelease: false
|
92
104
|
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
93
106
|
requirements:
|
94
|
-
- -
|
107
|
+
- - ~>
|
95
108
|
- !ruby/object:Gem::Version
|
96
109
|
version: '0.8'
|
97
110
|
- !ruby/object:Gem::Dependency
|
98
111
|
name: rb-fsevent
|
99
112
|
requirement: !ruby/object:Gem::Requirement
|
113
|
+
none: false
|
100
114
|
requirements:
|
101
|
-
- -
|
115
|
+
- - ~>
|
102
116
|
- !ruby/object:Gem::Version
|
103
117
|
version: '0.9'
|
104
118
|
type: :development
|
105
119
|
prerelease: false
|
106
120
|
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
none: false
|
107
122
|
requirements:
|
108
|
-
- -
|
123
|
+
- - ~>
|
109
124
|
- !ruby/object:Gem::Version
|
110
125
|
version: '0.9'
|
111
126
|
- !ruby/object:Gem::Dependency
|
112
127
|
name: rb-fchange
|
113
128
|
requirement: !ruby/object:Gem::Requirement
|
129
|
+
none: false
|
114
130
|
requirements:
|
115
|
-
- -
|
131
|
+
- - ~>
|
116
132
|
- !ruby/object:Gem::Version
|
117
133
|
version: '0.0'
|
118
134
|
type: :development
|
119
135
|
prerelease: false
|
120
136
|
version_requirements: !ruby/object:Gem::Requirement
|
137
|
+
none: false
|
121
138
|
requirements:
|
122
|
-
- -
|
139
|
+
- - ~>
|
123
140
|
- !ruby/object:Gem::Version
|
124
141
|
version: '0.0'
|
125
142
|
description: MemFs provides a fake file system that can be used for tests. Strongly
|
@@ -130,9 +147,9 @@ executables: []
|
|
130
147
|
extensions: []
|
131
148
|
extra_rdoc_files: []
|
132
149
|
files:
|
133
|
-
-
|
134
|
-
-
|
135
|
-
-
|
150
|
+
- .gitignore
|
151
|
+
- .rspec
|
152
|
+
- .travis.yml
|
136
153
|
- CHANGELOG.md
|
137
154
|
- Gemfile
|
138
155
|
- Guardfile
|
@@ -167,27 +184,34 @@ files:
|
|
167
184
|
homepage: http://github.com/simonc/memfs
|
168
185
|
licenses:
|
169
186
|
- MIT
|
170
|
-
metadata: {}
|
171
187
|
post_install_message:
|
172
188
|
rdoc_options: []
|
173
189
|
require_paths:
|
174
190
|
- lib
|
175
191
|
required_ruby_version: !ruby/object:Gem::Requirement
|
192
|
+
none: false
|
176
193
|
requirements:
|
177
|
-
- -
|
194
|
+
- - ! '>='
|
178
195
|
- !ruby/object:Gem::Version
|
179
196
|
version: '0'
|
197
|
+
segments:
|
198
|
+
- 0
|
199
|
+
hash: 1081085221049252726
|
180
200
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
201
|
+
none: false
|
181
202
|
requirements:
|
182
|
-
- -
|
203
|
+
- - ! '>='
|
183
204
|
- !ruby/object:Gem::Version
|
184
205
|
version: '0'
|
206
|
+
segments:
|
207
|
+
- 0
|
208
|
+
hash: 1081085221049252726
|
185
209
|
requirements: []
|
186
210
|
rubyforge_project:
|
187
|
-
rubygems_version:
|
211
|
+
rubygems_version: 1.8.23.2
|
188
212
|
signing_key:
|
189
|
-
specification_version:
|
190
|
-
summary: memfs-0.4.
|
213
|
+
specification_version: 3
|
214
|
+
summary: memfs-0.4.1
|
191
215
|
test_files:
|
192
216
|
- spec/fileutils_spec.rb
|
193
217
|
- spec/memfs/dir_spec.rb
|
checksums.yaml
DELETED
@@ -1,7 +0,0 @@
|
|
1
|
-
---
|
2
|
-
SHA1:
|
3
|
-
metadata.gz: a6b1cfcdf00318e924ed6247443dffdee28f85e4
|
4
|
-
data.tar.gz: e902f9ddd053b6aa53388f5151d38e650b459874
|
5
|
-
SHA512:
|
6
|
-
metadata.gz: 4478660656ed0a1fc638a01f5010fc27f3673064f36f4cda41523029266b220907ffe28cb0337763e2b266e8afb0a29ba18289293a316c56dcfac00fed763814
|
7
|
-
data.tar.gz: 6417b9df0a65364af0c7a4e6f04389b68388b456e8d6b641634b2794687f743f6e971655959d29322efac885918a297b472aa2a5fa6a5003784dd4a2652a110c
|