Skip to content

Commit

Permalink
No need to handle failed connections anymore.
Browse files Browse the repository at this point in the history
  • Loading branch information
jnunemaker committed Jan 26, 2011
1 parent ccd263e commit 148ae78
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 105 deletions.
142 changes: 50 additions & 92 deletions lib/adapter/spec/an_adapter.rb
Expand Up @@ -5,158 +5,116 @@

Adapter::Spec::Types.each do |type, (key, key2)|
it "reads from keys that are #{type}s like a Hash" do
handle_failed_connections do
adapter[key].should == nil
end
adapter[key].should == nil
end

it "writes String values to keys that are #{type}s like a Hash" do
handle_failed_connections do
adapter[key] = "value"
adapter[key].should == "value"
end
adapter[key] = "value"
adapter[key].should == "value"
end

it "guarantees that a different String value is retrieved from the #{type} key" do
handle_failed_connections do
value = "value"
adapter[key] = value
adapter[key].should_not be_equal(value)
end
value = "value"
adapter[key] = value
adapter[key].should_not be_equal(value)
end

it "guarantees that a different Object value is retrieved from the #{type} key" do
handle_failed_connections do
value = {:foo => :bar}
adapter[key] = value
adapter[key].should_not be_equal(:foo => :bar)
end
value = {:foo => :bar}
adapter[key] = value
adapter[key].should_not be_equal(:foo => :bar)
end

it "returns false from key? if a #{type} key is not available" do
handle_failed_connections do
adapter.key?(key).should be_false
end
adapter.key?(key).should be_false
end

it "returns true from key? if a #{type} key is available" do
handle_failed_connections do
adapter[key] = "value"
adapter.key?(key).should be_true
end
adapter[key] = "value"
adapter.key?(key).should be_true
end

it "removes and return an element with a #{type} key from the backing store via delete if it exists" do
handle_failed_connections do
adapter[key] = "value"
adapter.delete(key).should == "value"
adapter.key?(key).should be_false
end
adapter[key] = "value"
adapter.delete(key).should == "value"
adapter.key?(key).should be_false
end

it "returns nil from delete if an element for a #{type} key does not exist" do
handle_failed_connections do
adapter.delete(key).should be_nil
end
adapter.delete(key).should be_nil
end

it "removes all #{type} keys from the store with clear" do
handle_failed_connections do
adapter[key] = "value"
adapter[key2] = "value2"
adapter.clear
adapter.key?(key).should_not be_true
adapter.key?(key2).should_not be_true
end
adapter[key] = "value"
adapter[key2] = "value2"
adapter.clear
adapter.key?(key).should_not be_true
adapter.key?(key2).should_not be_true
end

it "fetches a #{type} key with a default value with fetch, if the key is not available" do
handle_failed_connections do
adapter.fetch(key, "value").should == "value"
end
adapter.fetch(key, "value").should == "value"
end

it "fetches a #{type} key with a block with fetch, if the key is not available" do
handle_failed_connections do
adapter.fetch(key) { |k| "value" }.should == "value"
end
adapter.fetch(key) { |k| "value" }.should == "value"
end

it "does not run the block if the #{type} key is available" do
handle_failed_connections do
adapter[key] = "value"
unaltered = "unaltered"
adapter.fetch(key) { unaltered = "altered" }
unaltered.should == "unaltered"
end
adapter[key] = "value"
unaltered = "unaltered"
adapter.fetch(key) { unaltered = "altered" }
unaltered.should == "unaltered"
end

it "fetches a #{type} key with a default value with fetch, if the key is available" do
handle_failed_connections do
adapter[key] = "value2"
adapter.fetch(key, "value").should == "value2"
end
adapter[key] = "value2"
adapter.fetch(key, "value").should == "value2"
end

it "writes #{key} values with #write" do
handle_failed_connections do
adapter.write(key, "value")
adapter[key].should == "value"
end
adapter.write(key, "value")
adapter[key].should == "value"
end
end

it "refuses to #[] from keys that cannot be marshalled" do
handle_failed_connections do
lambda do
adapter[Struct.new(:foo).new(:bar)]
end.should raise_error(TypeError)
end
lambda do
adapter[Struct.new(:foo).new(:bar)]
end.should raise_error(TypeError)
end

it "refuses to fetch from keys that cannot be marshalled" do
handle_failed_connections do
lambda do
adapter.fetch(Struct.new(:foo).new(:bar), true)
end.should raise_error(TypeError)
end
lambda do
adapter.fetch(Struct.new(:foo).new(:bar), true)
end.should raise_error(TypeError)
end

it "refuses to #[]= to keys that cannot be marshalled" do
handle_failed_connections do
lambda do
adapter[Struct.new(:foo).new(:bar)] = "value"
end.should raise_error(TypeError)
end
lambda do
adapter[Struct.new(:foo).new(:bar)] = "value"
end.should raise_error(TypeError)
end

it "refuses to store to keys that cannot be marshalled" do
handle_failed_connections do
lambda do
adapter.write Struct.new(:foo).new(:bar), "value"
end.should raise_error(TypeError)
end
lambda do
adapter.write Struct.new(:foo).new(:bar), "value"
end.should raise_error(TypeError)
end

it "refuses to check for key? if the key cannot be marshalled" do
handle_failed_connections do
lambda do
adapter.key? Struct.new(:foo).new(:bar)
end.should raise_error(TypeError)
end
lambda do
adapter.key? Struct.new(:foo).new(:bar)
end.should raise_error(TypeError)
end

it "refuses to delete a key if the key cannot be marshalled" do
handle_failed_connections do
lambda do
adapter.delete Struct.new(:foo).new(:bar)
end.should raise_error(TypeError)
end
lambda do
adapter.delete Struct.new(:foo).new(:bar)
end.should raise_error(TypeError)
end

it "specifies that it is writable via frozen?" do
handle_failed_connections do
adapter.should_not be_frozen
end
adapter.should_not be_frozen
end
end
6 changes: 2 additions & 4 deletions lib/adapter/spec/marshal_adapter.rb
Expand Up @@ -3,10 +3,8 @@

Adapter::Spec::Types.each do |type, (key, key2)|
it "writes Object values to keys that are #{type}s like a Hash" do
handle_failed_connections do
adapter[key] = {:foo => :bar}
adapter[key].should == {:foo => :bar}
end
adapter[key] = {:foo => :bar}
adapter[key].should == {:foo => :bar}
end
end
end
2 changes: 1 addition & 1 deletion lib/adapter/version.rb
@@ -1,3 +1,3 @@
module Adapter
VERSION = '0.5'
VERSION = '0.5.1'
end
8 changes: 0 additions & 8 deletions spec/support/module_helpers.rb
Expand Up @@ -18,12 +18,4 @@ def clear
end
end
end

def handle_failed_connections
yield
rescue => e
puts e.inspect
puts e.message unless e.message.nil?
pending
end
end

0 comments on commit 148ae78

Please sign in to comment.