Skip to content
Browse files

Fixed tests for indifferent access

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@873 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
1 parent 7174211 commit 5bca6290003650563bea83f3373b4774b93200f5 @dhh dhh committed Mar 7, 2005
Showing with 16 additions and 47 deletions.
  1. +16 −47 activesupport/test/core_ext/hash_ext_test.rb
View
63 activesupport/test/core_ext/hash_ext_test.rb
@@ -47,29 +47,31 @@ def test_stringify_keys!
assert_equal @strings, @mixed.dup.stringify_keys!
end
- def test_indifferent_access
+ def test_indifferent_assorted
@strings = @strings.with_indifferent_access
@symbols = @symbols.with_indifferent_access
@mixed = @mixed.with_indifferent_access
+
+ assert_equal 'a', @strings.send(:convert_key, :a)
+
+ assert_equal 1, @strings.fetch('a')
+ assert_equal 1, @strings.fetch(:a.to_s)
+ assert_equal 1, @strings.fetch(:a)
- assert_equal @strings[:a], @strings['a']
- assert_equal @symbols[:a], @symbols['a']
- assert_equal @strings['b'], @mixed['b']
- assert_equal @strings[:b], @mixed['b']
-
hashes = { :@strings => @strings, :@symbols => @symbols, :@mixed => @mixed }
-
- method_map = { :'[]' => 1, :fetch => 1, :index => 1, :values_at => 1,
- :has_key? => true, :include? => true, :key => true,
- :member? => true }
-
+ method_map = { :'[]' => 1, :fetch => 1, :values_at => [1],
+ :has_key? => true, :include? => true, :key? => true,
+ :member? => true }
+
hashes.each do |name, hash|
method_map.sort_by { |m| m.to_s }.each do |meth, expected|
- assert_equal(expected, hash.send(meth, 'a'), "Calling #{name}.#{meth} 'a'")
- assert_equal(expected, hash.send(meth, :a), "Calling #{name}.#{meth} :a")
+ assert_equal(expected, hash.send(meth, 'a'),
+ "Calling #{name}.#{meth} 'a'")
+ assert_equal(expected, hash.send(meth, :a),
+ "Calling #{name}.#{meth} :a")
end
end
-
+
assert_equal [1, 2], @strings.values_at('a', 'b')
assert_equal [1, 2], @strings.values_at(:a, :b)
assert_equal [1, 2], @symbols.values_at('a', 'b')
@@ -91,39 +93,6 @@ def test_indifferent_writing
assert_equal hash[3], 3
end
- def test_indifferent_assorted
- @strings = @strings.with_indifferent_access
- @symbols = @symbols.with_indifferent_access
- @mixed = @mixed.with_indifferent_access
-
- assert_equal 'a', @strings.send(:convert_key, :a)
-
- assert_equal 1, @strings.fetch('a')
- assert_equal 1, @strings.fetch(:a.to_s)
- assert_equal 1, @strings.fetch(:a)
-
- hashes = { :@strings => @strings, :@symbols => @symbols, :@mixed => @mixed }
- method_map = { :'[]' => 1, :fetch => 1, :values_at => [1],
- :has_key? => true, :include? => true, :key? => true,
- :member? => true }
-
- hashes.each do |name, hash|
- method_map.sort_by { |m| m.to_s }.each do |meth, expected|
- assert_equal(expected, hash.send(meth, 'a'),
- "Calling #{name}.#{meth} 'a'")
- assert_equal(expected, hash.send(meth, :a),
- "Calling #{name}.#{meth} :a")
- end
- end
-
- assert_equal [1, 2], @strings.values_at('a', 'b')
- assert_equal [1, 2], @strings.values_at(:a, :b)
- assert_equal [1, 2], @symbols.values_at('a', 'b')
- assert_equal [1, 2], @symbols.values_at(:a, :b)
- assert_equal [1, 2], @mixed.values_at('a', 'b')
- assert_equal [1, 2], @mixed.values_at(:a, :b)
- end
-
def test_assert_valid_keys
assert_nothing_raised do
{ :failure => "stuff", :funny => "business" }.assert_valid_keys([ :failure, :funny ])

0 comments on commit 5bca629

Please sign in to comment.
Something went wrong with that request. Please try again.