fake_zip 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/fake_zip/version.rb +1 -1
- data/lib/fake_zip.rb +4 -0
- data/spec/examples_spec.rb +9 -3
- metadata +3 -3
data/lib/fake_zip/version.rb
CHANGED
data/lib/fake_zip.rb
CHANGED
@@ -4,6 +4,9 @@ require 'yaml'
|
|
4
4
|
require 'forwardable'
|
5
5
|
require 'zip/zipfilesystem'
|
6
6
|
|
7
|
+
def FakeZip file, structure
|
8
|
+
FakeZip.new file, structure
|
9
|
+
end
|
7
10
|
|
8
11
|
module FakeZip
|
9
12
|
|
@@ -46,6 +49,7 @@ module FakeZip
|
|
46
49
|
|
47
50
|
class FakeZip < Struct.new :file_structure
|
48
51
|
def save file
|
52
|
+
File.delete file if File.exist? file
|
49
53
|
Zip::ZipFile.open file, Zip::ZipFile::CREATE do |z|
|
50
54
|
dirs(struct).each do |dir|
|
51
55
|
z.dir.mkdir(dir) unless z.file.exist? dir
|
data/spec/examples_spec.rb
CHANGED
@@ -3,11 +3,17 @@ describe FakeZip do
|
|
3
3
|
|
4
4
|
describe '.new' do
|
5
5
|
it 'takes file name and yaml string' do
|
6
|
-
expect { FakeZip
|
6
|
+
expect { FakeZip temp, '{}' }.to change { File.exist? temp }.from(false).to(true)
|
7
7
|
end
|
8
8
|
|
9
9
|
it 'takes file name and hash' do
|
10
|
-
expect { FakeZip
|
10
|
+
expect { FakeZip temp, {} }.to change { File.exist? temp }.from(false).to(true)
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'recreates file if exist' do
|
14
|
+
FakeZip temp, {dir:[:file]}
|
15
|
+
FakeZip temp, {other:[:any]}
|
16
|
+
zip_entries(temp).should == %w[ other/ other/any ]
|
11
17
|
end
|
12
18
|
end
|
13
19
|
|
@@ -22,7 +28,7 @@ describe FakeZip do
|
|
22
28
|
|
23
29
|
examples.each do |input,output|
|
24
30
|
specify "#{input.inspect} --- #{output.inspect}" do
|
25
|
-
FakeZip
|
31
|
+
FakeZip temp, input
|
26
32
|
zip_entries(temp).should == output
|
27
33
|
end
|
28
34
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fake_zip
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -112,7 +112,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
112
112
|
version: '0'
|
113
113
|
segments:
|
114
114
|
- 0
|
115
|
-
hash:
|
115
|
+
hash: 129868252758744392
|
116
116
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
117
117
|
none: false
|
118
118
|
requirements:
|
@@ -121,7 +121,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
121
121
|
version: '0'
|
122
122
|
segments:
|
123
123
|
- 0
|
124
|
-
hash:
|
124
|
+
hash: 129868252758744392
|
125
125
|
requirements: []
|
126
126
|
rubyforge_project:
|
127
127
|
rubygems_version: 1.8.25
|