Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

More flexible shared spec for adapter.

This makes it so extra keys do not matter. If a store returns more keys, adapter will not complain.
  • Loading branch information...
commit 13a5de9866c1d21c0808e6f4e80638466234f15c 1 parent 587ea6d
@jnunemaker authored
Showing with 79 additions and 37 deletions.
  1. +79 −37 lib/adapter/spec/an_adapter.rb
View
116 lib/adapter/spec/an_adapter.rb
@@ -27,7 +27,10 @@
it "returns value if key available" do
adapter.write(key, attributes)
- adapter.read(key).should eq(attributes)
+ result = adapter.read(key)
+ attributes.each do |key, value|
+ result[key].should eq(value)
+ end
end
end
@@ -38,7 +41,10 @@
it "returns value if key available" do
adapter.write(key, attributes)
- adapter.get(key).should eq(attributes)
+ result = adapter.get(key)
+ attributes.each do |key, value|
+ result[key].should eq(value)
+ end
end
end
@@ -49,7 +55,10 @@
it "returns value if key available" do
adapter.write(key, attributes)
- adapter[key].should eq(attributes)
+ result = adapter[key]
+ attributes.each do |key, value|
+ result[key].should eq(value)
+ end
end
end
@@ -60,20 +69,31 @@
end
it "returns Hash of keys and values" do
- adapter.read_multiple(key, key2).should eq({
- key => attributes,
- key2 => attributes2,
- })
+ result = adapter.read_multiple(key, key2)
+
+ attributes.each do |column, value|
+ result[key][column].should eq(value)
+ end
+
+ attributes2.each do |column, value|
+ result[key2][column].should eq(value)
+ end
end
context "with mix of keys that are and are not available" do
it "returns Hash of keys and values where unavailable keys are nil" do
- adapter.read_multiple(key, key2, 'foo', 'bar').should eq({
- key => attributes,
- key2 => attributes2,
- 'foo' => nil,
- 'bar' => nil,
- })
+ result = adapter.read_multiple(key, key2, 'foo', 'bar')
+
+ attributes.each do |column, value|
+ result[key][column].should eq(value)
+ end
+
+ attributes2.each do |column, value|
+ result[key2][column].should eq(value)
+ end
+
+ result['foo'].should be_nil
+ result['bar'].should be_nil
end
end
end
@@ -85,20 +105,31 @@
end
it "returns Hash of keys and values" do
- adapter.get_multiple(key, key2).should eq({
- key => attributes,
- key2 => attributes2,
- })
+ result = adapter.get_multiple(key, key2)
+
+ attributes.each do |column, value|
+ result[key][column].should eq(value)
+ end
+
+ attributes2.each do |column, value|
+ result[key2][column].should eq(value)
+ end
end
context "with mix of keys that are and are not available" do
it "returns Hash of keys and values where unavailable keys are nil" do
- adapter.get_multiple(key, key2, 'foo', 'bar').should eq({
- key => attributes,
- key2 => attributes2,
- 'foo' => nil,
- 'bar' => nil,
- })
+ result = adapter.get_multiple(key, key2, 'foo', 'bar')
+
+ attributes.each do |column, value|
+ result[key][column].should eq(value)
+ end
+
+ attributes2.each do |column, value|
+ result[key2][column].should eq(value)
+ end
+
+ result['foo'].should be_nil
+ result['bar'].should be_nil
end
end
end
@@ -133,7 +164,10 @@
context "with default value" do
it "returns key value instead of default" do
adapter.write(key, attributes2)
- adapter.fetch(key, attributes).should eq(attributes2)
+ result = adapter.fetch(key, attributes)
+ attributes2.each do |column, value|
+ result[column].should eq(value)
+ end
end
end
@@ -151,51 +185,59 @@
describe "#write" do
it "sets key to value" do
adapter.write(key, attributes)
- adapter.read(key).should eq(attributes)
+ result = adapter.read(key)
+ attributes.each do |column, value|
+ result[column].should eq(value)
+ end
end
end
describe "#set" do
it "sets key to value" do
adapter.set(key, attributes)
- adapter.read(key).should eq(attributes)
+ result = adapter.read(key)
+ attributes.each do |column, value|
+ result[column].should eq(value)
+ end
end
end
describe "#[]=" do
it "sets key to value" do
adapter[key] = attributes
- adapter.read(key).should eq(attributes)
+ result = adapter.read(key)
+ attributes.each do |column, value|
+ result[column].should eq(value)
+ end
end
end
describe "#delete" do
context "when key available" do
- before do
+ it "removes key" do
adapter.write(key, attributes)
+ adapter.key?(key).should be_true
adapter.delete(key)
- end
-
- it "removes key" do
adapter.key?(key).should be_false
end
end
context "when key not available" do
it "does not complain" do
+ adapter.key?(key).should be_false
adapter.delete(key)
+ adapter.key?(key).should be_false
end
end
end
describe "#clear" do
- before do
- adapter[key] = attributes
- adapter[key2] = attributes2
- adapter.clear
- end
-
it "removes all stored keys" do
+ adapter.write(key, attributes)
+ adapter.write(key2, attributes2)
+ adapter.key?(key).should be_true
+ adapter.key?(key2).should be_true
+ adapter.clear
adapter.key?(key).should be_false
adapter.key?(key2).should be_false
end
Please sign in to comment.
Something went wrong with that request. Please try again.