From f4b721904a26f631fbc6d7241b7f9480cc87ea47 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Sun, 2 Jan 2005 15:16:59 +0000 Subject: Added test cases and rakefile to Active Support git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@310 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- activesupport/test/dependencies_test.rb | 8 ++++-- activesupport/test/inflector_test.rb | 3 +- activesupport/test/misc_test.rb | 51 +++++++++++++++++++++++++++++++++ 3 files changed, 58 insertions(+), 4 deletions(-) create mode 100644 activesupport/test/misc_test.rb (limited to 'activesupport/test') diff --git a/activesupport/test/dependencies_test.rb b/activesupport/test/dependencies_test.rb index cf704992a1..eb57413777 100644 --- a/activesupport/test/dependencies_test.rb +++ b/activesupport/test/dependencies_test.rb @@ -1,7 +1,9 @@ -require File.dirname(__FILE__) + '/../abstract_unit' -require 'action_controller/support/dependencies' +require 'test/unit' +$LOAD_PATH.unshift File.dirname(__FILE__) + '/../lib' +require 'misc' +require 'dependencies' -$LOAD_PATH << File.dirname(__FILE__) + '/../fixtures/dependencies' +$LOAD_PATH.unshift File.dirname(__FILE__) + '/dependencies' class DependenciesTest < Test::Unit::TestCase def teardown diff --git a/activesupport/test/inflector_test.rb b/activesupport/test/inflector_test.rb index 7bcff70bdd..41b5f909bb 100644 --- a/activesupport/test/inflector_test.rb +++ b/activesupport/test/inflector_test.rb @@ -1,4 +1,5 @@ -require 'abstract_unit' +require 'test/unit' +require File.dirname(__FILE__) + '/../lib/inflector' class InflectorTest < Test::Unit::TestCase SingularToPlural = { diff --git a/activesupport/test/misc_test.rb b/activesupport/test/misc_test.rb new file mode 100644 index 0000000000..2a6c40709a --- /dev/null +++ b/activesupport/test/misc_test.rb @@ -0,0 +1,51 @@ +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 -- cgit v1.2.3