spec/hashes_spec.rb in fakeredis-0.8.0 vs spec/hashes_spec.rb in fakeredis-0.9.0

- old
+ new

@@ -30,11 +30,11 @@ @client.hset("key1", "k1", "val1") @client.hset("key1", "k2", "val2") expect(@client.hdel("key1", "k1")).to be(1) expect(@client.hdel("key1", "k2")).to be(1) - expect(@client.exists("key1")).to eq(false) + expect(@client.exists("key1")).to eq(0) end it "should convert key to a string for hset" do m = double("key") allow(m).to receive(:to_s).and_return("foo") @@ -133,17 +133,17 @@ expect { @client.hmget("key1", []) }.to raise_error(Redis::CommandError) end it "should reject an empty list of values" do expect { @client.hmset("key") }.to raise_error(Redis::CommandError) - expect(@client.exists("key")).to be false + expect(@client.exists?("key")).to be false end it "rejects an insert with a key but no value" do expect { @client.hmset("key", 'foo') }.to raise_error(Redis::CommandError) expect { @client.hmset("key", 'foo', 3, 'bar') }.to raise_error(Redis::CommandError) - expect(@client.exists("key")).to be false + expect(@client.exists?("key")).to be false end it "should reject the wrong number of arguments" do expect { @client.hmset("hash", "foo1", "bar1", "foo2", "bar2", "foo3") }.to raise_error(Redis::CommandError, "ERR wrong number of arguments for HMSET") end @@ -165,13 +165,43 @@ expect(@client.hget("foo", "k1")).to eq("value1") expect(@client.hget("foo", "k2")).to eq("value2") end it "should set the string value of a hash field" do - expect(@client.hset("key1", "k1", "val1")).to eq(true) - expect(@client.hset("key1", "k1", "val1")).to eq(false) + expect(@client.hset("key1", "k1", "val1")).to eq(1) + expect(@client.hset("key1", "k1", "val1")).to eq(0) expect(@client.hget("key1", "k1")).to eq("val1") + end + + it "should accept a list of key-value pair" do + @client.hset("key1", "k1", "val1", "k2", "val2") + + expect(@client.hget("key1", "k1")).to eq("val1") + expect(@client.hget("key1", "k2")).to eq("val2") + end + + it "should accept a hash of attributes to insert" do + @client.hset("key1", {"k1" => "val1", "k2" => "val2"}) + + expect(@client.hget("key1", "k1")).to eq("val1") + expect(@client.hget("key1", "k2")).to eq("val2") + end + + it "should return correct value when inserting a list of key-value pair" do + @client.hset("key1", "k1", "val1", "k2", "val2") + + expect(@client.hset("key1", "k1", "val1", "k2", "val2")).to eq(0) + expect(@client.hset("key1", "k2", "val2", "k3", "val3")).to eq(1) + expect(@client.hset("key1", "k4", "val4", "k5", "val5")).to eq(2) + end + + it "should return correct value when inserting a hash of attributes" do + @client.hset("key1", { "k1" => "val1", "k2" => "val2" }) + + expect(@client.hset("key1", { "k1" => "val1", "k2" => "val2" })).to eq(0) + expect(@client.hset("key1", { "k2" => "val2", "k3" => "val3" })).to eq(1) + expect(@client.hset("key1", { "k4" => "val4", "k5" => "val5" })).to eq(2) end it "should set the value of a hash field, only if the field does not exist" do @client.hset("key1", "k1", "val1") expect(@client.hsetnx("key1", "k1", "value")).to eq(false)