Sha256: 8e5d1ebc93ba2a1b01984dc2494af968f4b8619c173965d966d142df7c9cf94e
Contents?: true
Size: 1.77 KB
Versions: 1
Compression:
Stored size: 1.77 KB
Contents
require File.expand_path('../test_helper', __FILE__) module Loquor class ObjectHashTest < Minitest::Test def test_is_accessible_as_a_hash representation = ObjectHash.new({foo: "bar"}) assert_equal "bar", representation[:foo] end def test_hash_symbol_keys_are_accessible_as_strings representation = ObjectHash.new({foo: "bar"}) assert_equal "bar", representation["foo"] end def test_hash_string_keys_are_accessible_as_symbols representation = ObjectHash.new({"foo" => "bar"}) assert_equal "bar", representation[:foo] end def test_hash_keys_are_accessible_as_orignals representation = ObjectHash.new({1 => "bar"}) assert_equal "bar", representation[1] end def test_respond_to_still_proxies_to_super representation = ObjectHash.new({}) assert_equal true, representation.respond_to?(:to_s) end def test_respond_to_still_returns_false_for_non_existant_keys representation = ObjectHash.new({}) assert_equal false, representation.respond_to?(:dog) end def test_respond_to_knows_about_hash_keys representation = ObjectHash.new({foo: "bar"}) assert_equal true, representation.respond_to?(:foo) end def test_hash_keys_are_accessible_via_methods representation = ObjectHash.new({foo: "bar"}) assert_equal "bar", representation.foo end def test_non_strict_returns_nil_on_missing_attribute representation = ObjectHash.new({foo: "bar"}) assert_equal nil, representation.cat end def test_strict_raises_on_missing_attribute representation = ObjectHash.new({foo: "bar"}, strict: true) ex = assert_raises(ObjectHashKeyMissingError) do representation.cat end assert_equal "cat", ex.message end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
loquor-1.1.0 | test/object_hash_test.rb |