lib/adapter/spec/an_adapter.rb in adapter-0.6.1 vs lib/adapter/spec/an_adapter.rb in adapter-0.6.2
- old
+ new
@@ -23,84 +23,115 @@
describe "#read" do
it "returns nil if key not available" do
adapter.read(key).should be_nil
end
- it "returns value if key available" do
+ it "returns attributes if key available" 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 "#get" do
it "returns nil if key not available" do
adapter.get(key).should be_nil
end
- it "returns value if key available" do
+ it "returns attributes if key available" do
adapter.write(key, attributes)
- adapter.get(key).should eq(attributes)
+ result = adapter.get(key)
+ attributes.each do |column, value|
+ result[column].should eq(value)
+ end
end
end
describe "#[]" do
it "returns nil if key not available" do
adapter[key].should be_nil
end
- it "returns value if key available" do
+ it "returns attributes if key available" do
adapter.write(key, attributes)
- adapter[key].should eq(attributes)
+ result = adapter[key]
+ attributes.each do |column, value|
+ result[column].should eq(value)
+ end
end
end
describe "#read_multiple" do
before do
adapter.write(key, attributes)
adapter.write(key2, attributes2)
end
- it "returns Hash of keys and values" do
- adapter.read_multiple(key, key2).should eq({
- key => attributes,
- key2 => attributes2,
- })
+ it "returns Hash of keys and attributes" do
+ 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,
- })
+ it "returns Hash of keys and attributes where unavailable keys are nil" do
+ 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
describe "#get_multiple" do
before do
adapter.write(key, attributes)
adapter.write(key2, attributes2)
end
- it "returns Hash of keys and values" do
- adapter.get_multiple(key, key2).should eq({
- key => attributes,
- key2 => attributes2,
- })
+ it "returns Hash of keys and attributes" do
+ 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,
- })
+ it "returns Hash of keys and attributes where unavailable keys are nil" do
+ 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
describe "#key?" do
@@ -113,13 +144,13 @@
adapter.key?(key).should be_false
end
end
describe "#fetch" do
- context "with key not stored" do
- context "with default value" do
- it "returns default value" do
+ context "with key not available" do
+ context "with default attributes" do
+ it "returns default" do
adapter.fetch(key, {}).should eq({})
end
end
context "with default block" do
@@ -127,15 +158,18 @@
adapter.fetch(key) { |k| {} }.should eq({})
end
end
end
- context "with key that is stored" do
- context "with default value" do
- it "returns key value instead of default" do
+ context "with key that is available" do
+ context "with default attributes" do
+ it "returns result of read 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
context "with default block" do
it "does not run the block" do
@@ -147,56 +181,64 @@
end
end
end
describe "#write" do
- it "sets key to value" do
+ it "sets key to attributes" 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
+ it "sets key to attributes" 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
+ it "sets key to attributes" 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
+ it "removes all available keys" do
+ adapter.write(key, attributes)
+ adapter.write(key2, attributes2)
+ adapter.key?(key).should be_true
+ adapter.key?(key2).should be_true
adapter.clear
- end
-
- it "removes all stored keys" do
adapter.key?(key).should be_false
adapter.key?(key2).should be_false
end
end
end