spec/hashes_spec.rb in fakeredis-0.4.3 vs spec/hashes_spec.rb in fakeredis-0.5.0

- old
+ new

@@ -7,21 +7,21 @@ end it "should delete a hash field" do @client.hset("key1", "k1", "val1") @client.hset("key1", "k2", "val2") - @client.hdel("key1", "k1") + @client.hdel("key1", "k1").should be(1) @client.hget("key1", "k1").should be_nil @client.hget("key1", "k2").should be == "val2" end it "should remove a hash with no keys left" do @client.hset("key1", "k1", "val1") @client.hset("key1", "k2", "val2") - @client.hdel("key1", "k1") - @client.hdel("key1", "k2") + @client.hdel("key1", "k1").should be(1) + @client.hdel("key1", "k2").should be(1) @client.exists("key1").should be == false end it "should convert key to a string for hset" do @@ -41,12 +41,12 @@ end it "should determine if a hash field exists" do @client.hset("key1", "index", "value") - @client.hexists("key1", "index").should be_true - @client.hexists("key2", "i2").should be_false + @client.hexists("key1", "index").should be true + @client.hexists("key2", "i2").should be false end it "should get the value of a hash field" do @client.hset("key1", "index", "value") @@ -69,10 +69,21 @@ it "should increment non existing hash keys" do @client.hget("key1", "cont2").should be_nil @client.hincrby("key1", "cont2", "5").should be == 5 end + it "should increment the float value of a hash field by the given float" do + @client.hset("key1", "cont1", 5.0) + @client.hincrbyfloat("key1", "cont1", 4.1).should be == 9.1 + @client.hget("key1", "cont1").should be == "9.1" + end + + it "should increment non existing hash keys" do + @client.hget("key1", "cont2").should be_nil + @client.hincrbyfloat("key1", "cont2", 5.5).should be == 5.5 + end + it "should get all the fields in a hash" do @client.hset("key1", "i1", "val1") @client.hset("key1", "i2", "val2") @client.hkeys("key1").should =~ ["i1", "i2"] @@ -89,26 +100,28 @@ it "should get the values of all the given hash fields" do @client.hset("key1", "i1", "val1") @client.hset("key1", "i2", "val2") @client.hmget("key1", "i1", "i2", "i3").should =~ ["val1", "val2", nil] + @client.hmget("key1", ["i1", "i2", "i3"]).should =~ ["val1", "val2", nil] + @client.hmget("key2", "i1", "i2").should be == [nil, nil] end it "should throw an argument error when you don't ask for any keys" do lambda { @client.hmget("key1") }.should raise_error(Redis::CommandError) end it "should reject an empty list of values" do lambda { @client.hmset("key") }.should raise_error(Redis::CommandError) - @client.exists("key").should be_false + @client.exists("key").should be false end it "rejects an insert with a key but no value" do lambda { @client.hmset("key", 'foo') }.should raise_error(Redis::CommandError) lambda { @client.hmset("key", 'foo', 3, 'bar') }.should raise_error(Redis::CommandError) - @client.exists("key").should be_false + @client.exists("key").should be false end it "should reject the wrong number of arguments" do lambda { @client.hmset("hash", "foo1", "bar1", "foo2", "bar2", "foo3") }.should raise_error(Redis::CommandError, "ERR wrong number of arguments for HMSET") end @@ -169,10 +182,10 @@ @client.hdel("key1", 1).should be(1) end it "should convert a integer field name to string for hexists" do @client.hset("key1", "1", 1) - @client.hexists("key1", 1).should be_true + @client.hexists("key1", 1).should be true end it "should convert a integer field name to string for hincrby" do @client.hset("key1", 1, 0) @client.hincrby("key1", 1, 1).should be(1)