spec/hamster/hash/get_spec.rb in hamster-0.1.8 vs spec/hamster/hash/get_spec.rb in hamster-0.1.11

- old
+ new

@@ -1,22 +1,34 @@ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') describe Hamster::Hash do - describe "#get" do + [:get, :[]].each do |method| - before do - @hash = Hamster::Hash.new - @hash = @hash.put("A", "aye") - end + describe "##{method}" do - it "returns the value for an existing key" do - @hash.get("A").should == "aye" - end + before do + @hash = Hamster.hash("A" => "aye", "B" => "bee", "C" => "see", nil => "NIL") + end - it "returns nil for a non-existing key" do - @hash.get("B").should be_nil + [ + ["A", "aye"], + ["B", "bee"], + ["C", "see"], + [nil, "NIL"] + ].each do |key, value| + + it "returns the value (#{value.inspect}) for an existing key (#{key.inspect})" do + @hash.send(method, key).should == value + end + + end + + it "returns nil for a non-existing key" do + @hash.send(method, "D").should be_nil + end + + end + end end - -end