1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
|
require File.dirname(__FILE__) + '/../spec_helper'
module IceCube
describe FlexibleHash do
subject(:hash) { described_class.new(:sym => true, "str" => true, 1 => true) }
describe "#[]" do
specify ":sym => :sym is found" do
expect(hash[:sym]).to be true
end
specify "'sym' => :sym is found" do
expect(hash["sym"]).to be true
end
specify "'str' => 'str' is found" do
expect(hash["str"]).to be true
end
specify ":str => 'str' is found" do
expect(hash[:str]).to be true
end
specify "other types are found" do
expect(hash[1]).to be true
end
specify "missing keys are nil" do
expect(hash[-1]).to be nil
end
end
describe "#fetch" do
it "yields missing keys" do
expect(hash.fetch(-1) { |k| k == -1 }).to be true
end
end
describe "#delete" do
specify ":sym => :sym is found and removed" do
expect(hash.delete(:sym)).to be true
expect(hash[:sym]).to be nil
end
specify "'sym' => :sym is found and removed" do
expect(hash.delete("sym")).to be true
expect(hash["sym"]).to be nil
end
specify "'str' => 'str' is found and removed" do
expect(hash.delete("str")).to be true
expect(hash["str"]).to be nil
end
specify ":str => 'str' is found and removed" do
expect(hash.delete(:str)).to be true
expect(hash[:str]).to be nil
end
specify "other types are found and removed" do
expect(hash.delete(1)).to be true
expect(hash[1]).to be nil
end
specify "missing keys are nil" do
expect(hash.delete(-1)).to be nil
end
end
end
end
|