Skip to content

Instantly share code, notes, and snippets.

@guilleiguaran
Created July 22, 2011 08:38
Show Gist options
  • Save guilleiguaran/1099094 to your computer and use it in GitHub Desktop.
Save guilleiguaran/1099094 to your computer and use it in GitHub Desktop.
require "test/unit"
require "rubygems"
begin ; require "turn" ; rescue LoadError ; end
require "active_support/core_ext/hash/indifferent_access"
class TestHashes < Test::Unit::TestCase
def setup
@hash1 = key_value('a', 1)
@hash2 = key_value('a', 1).with_indifferent_access
end
def test_regular_hash
assert @hash1[:a]
assert_nil @hash1['a']
end
def test_hash_with_indifferent_access
assert @hash2[:a]
assert @hash2['a']
assert_equal @hash2['a'], @hash2[:a]
end
def key_value(key, value)
if RUBY_VERSION < "1.9"
eval "{:#{key} => #{value}}"
else
eval "{#{key}: #{value}}"
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment