require "spec_helper" require "oria" describe Oria do describe "Moneta methods" do it "should include []" do Oria.should respond_to(:[]) end it "should include []=" do Oria.should respond_to(:[]=) end it "should include clear" do Oria.should respond_to(:clear) end it "should include delete" do Oria.should respond_to(:delete) end it "should include has_key?" do Oria.should respond_to(:has_key?) end it "should include key?" do Oria.should respond_to(:key?) end end it "should provide a connect method" do Oria.should respond_to(:connect) end it "should support per-app keys" do Oria.should respond_to(:app_key) Oria.should respond_to(:app_key=) end it "should support custom connections" do Oria.connect("127.0.0.1", 4567) Oria.server.should == "127.0.0.1" Oria.port.should == 4567 end it "should automatically boot a server" do # Oria.should_receive(:auto_start) # Oria["foo"] = "bar" # Oria.disconnect end describe "app_key" do # it "should default to nil" do # # This is bleeding over from the last example below. Frankly, # # I don't know how to fix it. # Oria.app_key.should be_nil # end it "should be configurable" do Oria.app_key = "test_app" Oria.app_key.should == "test_app" end end it "should be possible to disconnect" do Oria::Server.should_receive(:stop) Oria["foo"] = "bar" Oria.disconnect end describe "setting values" do describe "with a booted server" do before :all do @pid = fork do Oria::Server.start(Oria.server, Oria.port, nil, true) end Process.detach(@pid) sleep 0.5 end after :all do Oria.clear Oria::Server.stop Process.kill("HUP", @pid) end it "should set string values" do Oria["foo"] = "bar" Oria["foo"].should == "bar" end it "should set integer values" do Oria["foo"] = 12 Oria["foo"].should == 12 end it "should support Hashes" do Oria["foo"] = {"Flip" => "Sasser"} Oria["foo"].should == {"Flip" => "Sasser"} end it "should support Arrays" do Oria["foo"] = ["Foo", "Bar", "Baz"] Oria["foo"].should == ["Foo", "Bar", "Baz"] end it "should support Booleans" do Oria["true"] = false Oria["true"].should == false end it "should support deleting values" do Oria["memoria"] = "foobar" Oria["dont_delete"] = "please" Oria.delete("memoria").should == "foobar" Oria["memora"].should be_nil Oria["dont_delete"].should == "please" end it "should support complete clearing" do Oria["a"] = "c" Oria["b"] = "d" Oria["a"].should == "c" Oria["b"].should == "d" Oria.clear Oria["a"].should be_nil Oria["b"].should be_nil end it "should support key-checking" do Oria["key_check"] = "check-a-key" Oria.key?("key_check").should be_true Oria.key?("key_check_broken").should be_false Oria.has_key?("key_check").should be_true Oria.has_key?("key_check_broken").should be_false end it "should support stashing" do key = Oria.stash("foobar") key.should_not be_nil Oria[key].should == "foobar" end it "should support different app_keys" do Oria.app_key = "test_app_1" Oria["test_app_1"] = "bar" Oria["test_app_1"].should == "bar" Oria.app_key = "test_app_2" Oria["test_app_2"] = "baz" Oria["test_app_1"].should be_nil Oria["test_app_2"].should == "baz" end end end end