Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 5th, 2012  |  syntax: None  |  size: 0.64 KB  |  hits: 9  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. require "test/unit"
  2. require "rubygems"
  3. begin ; require "turn" ; rescue LoadError ; end
  4. require "active_support/core_ext/hash/indifferent_access"
  5.  
  6. class TestHashes < Test::Unit::TestCase
  7.   def setup
  8.     @hash1 = key_value('a', 1)
  9.     @hash2 = key_value('a', 1).with_indifferent_access
  10.   end
  11.  
  12.   def test_regular_hash
  13.     assert @hash1[:a]
  14.     assert_nil @hash1['a']
  15.   end
  16.  
  17.   def test_hash_with_indifferent_access
  18.     assert @hash2[:a]
  19.     assert @hash2['a']
  20.     assert_equal @hash2['a'], @hash2[:a]
  21.   end
  22.  
  23.   def key_value(key, value)
  24.     if RUBY_VERSION < "1.9"
  25.       eval "{:#{key} => #{value}}"
  26.     else
  27.       eval "{#{key}: #{value}}"
  28.     end
  29.   end
  30. end