spec/helper.rb in kyototycoon-0.1.1 vs spec/helper.rb in kyototycoon-0.1.2

- old
+ new

@@ -1,16 +1,26 @@ # -- coding: utf-8 +=begin + +!!!!!!!!!!!!! +!! CAUTION !! +!!!!!!!!!!!!! + +This script access http://0.0.0.0:19999/ and destroy all records. +Be carefully for run, and run `ktserver -port 19999 '*'` before testing. + +=end + $LOAD_PATH.unshift(File.dirname(__FILE__) + "/../lib") require "rubygems" require "kyototycoon.rb" describe do before(:all) do - @kt = KyotoTycoon.new + @kt = KyotoTycoon.new('0.0.0.0', 19999) @kt.serializer=:default # or :msgpack - @kt.db='*' # in memory @kt.logger=nil end before(:each) do @kt.clear @@ -18,11 +28,11 @@ it 'should handle multi servers' do kt = KyotoTycoon.new('www.example.com', 11111) kt.connect_timeout = 0.1 kt.servers << ['example.net', 1978] - kt.servers << ['0.0.0.0', 1978] + kt.servers << ['0.0.0.0', 19999] kt['foo'] = 'bar' kt[:foo].should == 'bar' end it 'should provide simple kvs feature' do @@ -96,10 +106,13 @@ @kt.increment('foo').should == 1 @kt.increment('foo').should == 2 @kt.increment('foo').should == 3 @kt.increment('foo', 10).should == 13 @kt.increment('foo', -10).should == 3 + @kt.decrement('foo', 5).should == -2 + @kt.incr('foo', 5).should == 3 + @kt.decr('foo', 5).should == -2 end it 'should provide status/report' do @kt[:a] = 1 @kt[:b] = 2 @@ -116,7 +129,27 @@ @kt.match_prefix("12").sort.should == %w!123 124 125!.sort @kt.match_prefix("9").sort.should == %w!999 9999!.sort @kt.match_prefix("9999").sort.should == %w!9999! @kt.match_regex(/^12/).sort.should == %w!123 124 125!.sort @kt.match_regex(/^9+$/).sort.should == %w!999 9999!.sort + end + + it 'should configure/create method works' do + logger = Logger.new(STDOUT) + KyotoTycoon.configure(:test) do |kt| + kt.logger = logger + kt.serializer = :msgpack + kt.db = 'foobar' + end + KyotoTycoon.configure(:test2, 'host', 1999) do |kt| + kt.logger = logger + kt.serializer = :msgpack + kt.db = 'foobar' + end + %w!test test2!.each{|name| + kt = KyotoTycoon.create(name.to_sym) + kt.logger.should == logger + kt.serializer.should == KyotoTycoon::Serializer::Msgpack + kt.db.should == 'foobar' + } end end