doo_dah 0.2.0 → 0.2.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.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.0
1
+ 0.2.1
data/doo_dah.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{doo_dah}
8
- s.version = "0.2.0"
8
+ s.version = "0.2.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Michael Collas"]
@@ -12,6 +12,12 @@ module DooDah
12
12
  @output_stream = output_stream
13
13
  @total_bytes_written = 0
14
14
  @entries = []
15
+ return unless block_given?
16
+ begin
17
+ yield self
18
+ ensure
19
+ close
20
+ end
15
21
  end
16
22
 
17
23
  def create_entry(name, size=0, crc=0)
@@ -10,6 +10,32 @@ module DooDah
10
10
  @entry = stub(:close => nil, :closed? => false)
11
11
  ZipEntry.stub(:new => @entry)
12
12
  end
13
+
14
+ describe 'when constructing with a block' do
15
+
16
+ it 'should yield itself to the block' do
17
+ block_parameter = nil
18
+ zip_output_stream = ZipOutputStream.new(@output_stream) {|output_stream| block_parameter = output_stream }
19
+ block_parameter.should == zip_output_stream
20
+ end
21
+
22
+ it 'should close itself upon return from the block' do
23
+ zip_output_stream = ZipOutputStream.allocate
24
+ zip_output_stream.should_receive(:close)
25
+ zip_output_stream.send(:initialize, @output_stream) {|output_stream| }
26
+ end
27
+
28
+ it 'should close itself even if an exception is thrown in the block' do
29
+ zip_output_stream = ZipOutputStream.allocate
30
+ zip_output_stream.should_receive(:close)
31
+ BadStuff = Class.new(Exception)
32
+ begin
33
+ zip_output_stream.send(:initialize, @output_stream) { |output_stream| raise BadStuff }
34
+ rescue BadStuff
35
+ end
36
+ end
37
+
38
+ end
13
39
 
14
40
  describe '#start_entry' do
15
41
 
@@ -158,6 +184,12 @@ module DooDah
158
184
  @zip.write('7 bytes')
159
185
  @zip.current_offset.should == 14
160
186
  end
187
+
188
+ it 'should not close itself when constructed without a block' do
189
+ zip_output_stream = ZipOutputStream.allocate
190
+ zip_output_stream.should_not_receive(:close)
191
+ zip_output_stream.send(:initialize, @output_stream)
192
+ end
161
193
 
162
194
  end
163
195
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: doo_dah
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
4
+ hash: 21
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 2
9
- - 0
10
- version: 0.2.0
9
+ - 1
10
+ version: 0.2.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Michael Collas