Permalink
Browse files

Added the first of the coming core extensions

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@349 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
1 parent 7145046 commit f626aece793eab4a414eeb96a3bb3440e98e05d8 @dhh dhh committed Jan 9, 2005
@@ -0,0 +1 @@
+Dir[File.dirname(__FILE__) + "/core_ext/*.rb"].each { |file| require(file) }
@@ -0,0 +1,6 @@
+class Hash
+ def assert_valid_keys(valid_keys)
+ unknown_keys = keys - valid_keys
+ raise(ArgumentError, "Unknown key(s): #{unknown_keys.join(", ")}") unless unknown_keys.empty?
+ end
+end
@@ -0,0 +1,14 @@
+require 'test/unit'
+require File.dirname(__FILE__) + '/../../lib/core_ext/hash_ext'
+
+class HashExtTest < Test::Unit::TestCase
+ def test_assert_valid_keys
+ assert_nothing_raised do
+ { :failure => "stuff", :funny => "business" }.assert_valid_keys([ :failure, :funny ])
+ end
+
+ assert_raises(ArgumentError, "Unknown key(s): failore") do
+ { :failore => "stuff", :funny => "business" }.assert_valid_keys([ :failure, :funny ])
+ end
+ end
+end

0 comments on commit f626aec

Please sign in to comment.