PageRenderTime 60ms CodeModel.GetById 35ms app.highlight 21ms RepoModel.GetById 2ms app.codeStats 0ms

/spec/oria_spec.rb

http://github.com/intridea/oria
Ruby | 152 lines | 113 code | 24 blank | 15 comment | 15 complexity | b2194c3cf40f7a6a66bb3a65c148313d MD5 | raw file
  1require "spec_helper"
  2require "oria"
  3
  4describe Oria do
  5  describe "Moneta methods" do
  6    it "should include []" do
  7      Oria.should respond_to(:[])
  8    end
  9
 10    it "should include []=" do
 11      Oria.should respond_to(:[]=)
 12    end
 13
 14    it "should include clear" do
 15      Oria.should respond_to(:clear)
 16    end
 17
 18    it "should include delete" do
 19      Oria.should respond_to(:delete)
 20    end
 21
 22    it "should include has_key?" do
 23      Oria.should respond_to(:has_key?)
 24    end
 25
 26    it "should include key?" do
 27      Oria.should respond_to(:key?)
 28    end
 29  end
 30
 31  describe "class methods" do
 32    it "should provide a connect method" do
 33      Oria.should respond_to(:connect)
 34    end
 35
 36    it "should support per-app keys" do
 37      Oria.should respond_to(:app_key)
 38      Oria.should respond_to(:app_key=)
 39    end
 40
 41    it "should support custom connections" do
 42      Oria.connect("127.0.0.1", 4567)
 43      Oria.server.should == "127.0.0.1"
 44      Oria.port.should == 4567
 45      Oria::Server.stop
 46      sleep 1
 47    end
 48  end
 49
 50  describe "app_key" do
 51    # it "should default to nil" do
 52    #   # This is bleeding over from the last example below. Frankly,
 53    #   # I don't know how to fix it. I'm unclear on separating
 54    #   # Rspec examples from each other at the class level like
 55    #   # this.
 56    #   Oria.app_key.should be_nil
 57    # end
 58  
 59    it "should be configurable" do
 60      Oria.app_key = "test_app"
 61      Oria.app_key.should == "test_app"
 62    end
 63  end
 64  
 65  describe "setting values" do
 66    before :all do
 67      Oria.connect
 68      sleep 1
 69    end
 70
 71    after :all do
 72      # TODO: In general, I find "sleep" to be a terrible method of doing anything.
 73      # Still, it gets the job done, albeit by delaying our specs.
 74      Oria::Server.stop
 75      sleep 0.5
 76    end
 77    
 78    it "should set string values" do
 79      Oria["foo"] = "bar"
 80      Oria["foo"].should == "bar"
 81    end
 82
 83    it "should set integer values" do
 84      Oria["foo"] = 12
 85      Oria["foo"].should == 12
 86    end
 87
 88    it "should support Hashes" do
 89      Oria["foo"] = {"Flip" => "Sasser"}
 90      Oria["foo"].should == {"Flip" => "Sasser"}
 91    end
 92
 93    it "should support Arrays" do
 94      Oria["foo"] = ["Foo", "Bar", "Baz"]
 95      Oria["foo"].should == ["Foo", "Bar", "Baz"]
 96    end
 97
 98    it "should support Booleans" do
 99      Oria["true"] = false
100      Oria["true"].should == false
101    end
102
103    it "should support deleting values" do
104      Oria["memoria"] = "foobar"
105      Oria["dont_delete"] = "please"
106      Oria.delete("memoria").should == "foobar"
107      Oria["memora"].should be_nil
108      Oria["dont_delete"].should == "please"
109    end
110
111    it "should support complete clearing" do
112      Oria["a"] = "c"
113      Oria["b"] = "d"
114      Oria["a"].should == "c"
115      Oria["b"].should == "d"
116      Oria.clear
117      Oria["a"].should be_nil
118      Oria["b"].should be_nil
119    end
120
121    it "should support key-checking" do
122      Oria["key_check"] = "check-a-key"
123      Oria.key?("key_check").should be_true
124      Oria.key?("key_check_broken").should be_false
125      Oria.has_key?("key_check").should be_true
126      Oria.has_key?("key_check_broken").should be_false
127    end
128
129    it "should support stashing" do
130      key = Oria.stash("foobar")
131      key.should_not be_nil
132      Oria[key].should == "foobar"
133    end
134
135    it "should support different app_keys" do
136      Oria.app_key = "test_app_1"
137      Oria["test_app_1"] = "bar"
138      Oria["test_app_1"].should == "bar"
139      Oria.app_key = "test_app_2"
140      Oria["test_app_2"] = "baz"
141      Oria["test_app_1"].should be_nil
142      Oria["test_app_2"].should == "baz"
143    end
144  end
145
146  # it "should automatically boot a server" do
147  #   Oria.should_receive(:connect)
148  #   Oria["foo"] = "bar"
149  #   Oria["foo"].should == "bar"
150  #   Oria::Server.stop
151  # end
152end