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
|
# test/stat_struct_test.rb
require File.expand_path('../test_helper', __FILE__)
describe Beaneater::StatStruct do
before do
@hash = { :foo => "bar", :bar => "baz", :baz => "foo", :"under-score" => "demo" }
@struct = Beaneater::StatStruct.from_hash(@hash)
end
describe "for #from_hash" do
it "should have 4 keys" do
assert_equal 'bar', @struct.foo
assert_equal 'baz', @struct.bar
assert_equal 'foo', @struct.baz
assert_equal 'demo', @struct.under_score
end
end # from_hash
describe "for [] access" do
it "should have hash lookup" do
assert_equal 'bar', @struct['foo']
assert_equal 'baz', @struct['bar']
end
it "should convert keys to string" do
assert_equal 'foo', @struct[:baz]
assert_equal 'demo', @struct[:"under_score"]
end
end # []
describe "for #keys" do
it "should return 4 keys" do
assert_equal 4, @struct.keys.size
end
it "should return expected keys" do
assert_equal ['foo', 'bar', 'baz', 'under_score'].sort, @struct.keys.sort
end
end # keys
describe "for #to_h" do
it "should return 4 keys / values" do
assert_equal 4, @struct.to_h.size
end
it "should return expect hash" do
assert_equal [['foo', 'bar'], ['bar', 'baz'], ['baz', 'foo'], ['under_score', 'demo']].sort, @struct.to_h.sort
end
end # to_h
end # Beaneater::StatStruct
|