alloc8 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -60,9 +60,12 @@ module Alloc8
60
60
  # block to allocate a resource
61
61
  def self.with_resource(klass, host, port, db=nil)
62
62
  a = Alloc8::Tor.new host, port, db
63
- res = a.acquire(klass)
64
- yield res
65
- a.return(klass, res)
63
+ begin
64
+ res = a.acquire(klass)
65
+ yield res
66
+ ensure
67
+ a.return(klass, res)
68
+ end
66
69
  end
67
70
 
68
71
  private
@@ -1,3 +1,3 @@
1
1
  module Alloc8
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -52,10 +52,19 @@ describe Alloc8 do
52
52
  lambda { @allocator.return(KIND, "foo") }.should raise_error
53
53
  end
54
54
 
55
- it "can acquire with a block" do
55
+ it "can acquire with a block, and returns correctly" do
56
56
  Alloc8::Tor.with_resource(KIND, HOST, PORT) do |res|
57
57
  res.should == "a"
58
+ @allocator.available(KIND).should eq([])
58
59
  end
60
+ @allocator.list(KIND).should eq(["a"])
61
+ @allocator.available(KIND).should eq(["a"])
62
+ end
63
+
64
+ it "can acquire with a block, and handle an exception" do
65
+ lambda { Alloc8::Tor.with_resource(KIND, HOST, PORT) { raise Exception.new("test") } }.should raise_error
66
+ @allocator.list(KIND).should eq(["a"])
67
+ @allocator.available(KIND).should eq(["a"])
59
68
  end
60
69
 
61
70
  it "can't acquire a second resource" do
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: alloc8
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 25
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 2
10
- version: 0.0.2
9
+ - 3
10
+ version: 0.0.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Ariel Salomon
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-05-22 00:00:00 -07:00
18
+ date: 2011-05-23 00:00:00 -07:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency