spec/transactions_spec.rb in fakeredis-0.5.0 vs spec/transactions_spec.rb in fakeredis-0.6.0
- old
+ new
@@ -10,44 +10,44 @@
@client.discard rescue nil
end
context '#multi' do
it "should respond with 'OK'" do
- @client.multi.should == 'OK'
+ expect(@client.multi).to eq('OK')
end
it "should forbid nesting" do
@client.multi
- lambda{@client.multi}.should raise_error(Redis::CommandError)
+ expect{@client.multi}.to raise_error(Redis::CommandError)
end
it "should mark the start of a transaction block" do
transaction = @client.multi do |multi|
multi.set("key1", "1")
multi.set("key2", "2")
multi.expire("key1", 123)
multi.mget("key1", "key2")
end
- transaction.should be == ["OK", "OK", true, ["1", "2"]]
+ expect(transaction).to eq(["OK", "OK", true, ["1", "2"]])
end
end
context '#discard' do
it "should responde with 'OK' after #multi" do
@client.multi
- @client.discard.should == 'OK'
+ expect(@client.discard).to eq('OK')
end
it "can't be run outside of #multi/#exec" do
- lambda{@client.discard}.should raise_error(Redis::CommandError)
+ expect{@client.discard}.to raise_error(Redis::CommandError)
end
end
context '#exec' do
it "can't be run outside of #multi" do
- lambda{@client.exec}.should raise_error(Redis::CommandError)
+ expect{@client.exec}.to raise_error(Redis::CommandError)
end
end
context 'saving up commands for later' do
before(:each) do
@@ -55,30 +55,38 @@
@string = 'fake-redis-test:string'
@list = 'fake-redis-test:list'
end
it "makes commands respond with 'QUEUED'" do
- @client.set(@string, 'string').should == 'QUEUED'
- @client.lpush(@list, 'list').should == 'QUEUED'
+ expect(@client.set(@string, 'string')).to eq('QUEUED')
+ expect(@client.lpush(@list, 'list')).to eq('QUEUED')
end
it "gives you the commands' responses when you call #exec" do
@client.set(@string, 'string')
@client.lpush(@list, 'list')
@client.lpush(@list, 'list')
- @client.exec.should == ['OK', 1, 2]
+ expect(@client.exec).to eq(['OK', 1, 2])
end
it "does not raise exceptions, but rather puts them in #exec's response" do
@client.set(@string, 'string')
@client.lpush(@string, 'oops!')
@client.lpush(@list, 'list')
responses = @client.exec
- responses[0].should == 'OK'
- responses[1].should be_a(RuntimeError)
- responses[2].should == 1
+ expect(responses[0]).to eq('OK')
+ expect(responses[1]).to be_a(RuntimeError)
+ expect(responses[2]).to eq(1)
+ end
+ end
+
+ context 'executing hash commands in a block' do
+ it "returns true if the nested hash command succeeds" do
+ responses = @client.multi { |multi| multi.hset('hash', 'key', 'value') }
+
+ expect(responses[0]).to eq(true)
end
end
end
end