Skip to content
This repository has been archived by the owner on May 18, 2018. It is now read-only.

Commit

Permalink
More Lua tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dim committed Jun 12, 2013
1 parent 01e3b55 commit 36a76f5
Showing 1 changed file with 21 additions and 11 deletions.
32 changes: 21 additions & 11 deletions spec/ssdb_spec.rb
Expand Up @@ -48,16 +48,26 @@
res["leveldb.stats"].should have(6).keys
end

it 'should eval scripts' do
subject.eval("return 'hello'").should == "hello"
subject.eval("return table.concat(args)", 1, "a", 2, "b").should == "1a2b"
subject.eval("local x = 10 * math.pi; return x").should == "31.415927"
subject.eval("return 2 ^ 3 == 8").should == "1"
subject.eval("local no_return").should be_nil
# TODO
# subject.eval("return {1, 'a', 2, 'b', ['c'] = 3}").should == ["1", "a", "2", "b", "c", "3"]

-> { subject.eval "wrong syntax" }.should raise_error(SSDB::CommandError, /failed compiling/)
end
describe "scripting" do

it 'should eval' do
subject.eval("return 'hello'").should == "hello"
subject.eval("return table.concat(args)", 1, "a", 2, "b").should == "1a2b"
subject.eval("local x = 10 * math.pi; return x").should == "31.415927"
subject.eval("return 2 ^ 3 == 8").should == "1"
subject.eval("local no_return").should be_nil
subject.eval("return {1, 'a', 2, 'b', ['c'] = 3, 'd'}").should == ["1", "a", "2", "b", "d"]
end

it 'should raise on eval failures' do
-> { subject.eval "wrong syntax" }.should raise_error(SSDB::CommandError, /failed compiling/)
end

it 'should have an ssdb accessor' do
subject.eval("return type(ssdb)").should == "userdata"
subject.eval("return ssdb:call('get', 'key')").should be_nil
-> { subject.eval "return ssdb:no_method()" }.should raise_error(SSDB::CommandError, /failed running/)
end

end
end

0 comments on commit 36a76f5

Please sign in to comment.