mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
f4b721904a
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@310 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
51 lines
1.3 KiB
Ruby
51 lines
1.3 KiB
Ruby
require 'test/unit'
|
|
require File.dirname(__FILE__) + '/../lib/misc'
|
|
|
|
class MiscTest < Test::Unit::TestCase
|
|
def test_silence_warnings
|
|
silence_warnings { assert_nil $VERBOSE }
|
|
assert_equal 1234, silence_warnings { 1234 }
|
|
end
|
|
|
|
def test_silence_warnings_verbose_invariant
|
|
old_verbose = $VERBOSE
|
|
begin
|
|
silence_warnings { raise }
|
|
flunk
|
|
rescue
|
|
assert_equal old_verbose, $VERBOSE
|
|
end
|
|
end
|
|
end
|
|
|
|
class HashOptionsTest < Test::Unit::TestCase
|
|
def setup
|
|
@strings = { 'a' => 1, 'b' => 2 }
|
|
@symbols = { :a => 1, :b => 2 }
|
|
@mixed = { :a => 1, 'b' => 2 }
|
|
end
|
|
|
|
def test_methods
|
|
h = {}
|
|
assert_respond_to h, :symbolize_keys
|
|
assert_respond_to h, :symbolize_keys!
|
|
assert_respond_to h, :to_options
|
|
assert_respond_to h, :to_options!
|
|
end
|
|
|
|
def test_symbolize_keys
|
|
assert_equal @symbols, @symbols.symbolize_keys
|
|
assert_equal @symbols, @strings.symbolize_keys
|
|
assert_equal @symbols, @mixed.symbolize_keys
|
|
|
|
assert_raises(NoMethodError) { { [] => 1 }.symbolize_keys }
|
|
end
|
|
|
|
def test_symbolize_keys!
|
|
assert_equal @symbols, @symbols.dup.symbolize_keys!
|
|
assert_equal @symbols, @strings.dup.symbolize_keys!
|
|
assert_equal @symbols, @mixed.dup.symbolize_keys!
|
|
|
|
assert_raises(NoMethodError) { { [] => 1 }.symbolize_keys! }
|
|
end
|
|
end
|