This post originated from an RSS feed registered with Ruby Buzz
by Jay Fields.
Original Post: Rails: Hash#assert_valid_keys
Feed Title: Jay Fields Thoughts
Feed URL: http://feeds.feedburner.com/jayfields/mjKQ
Feed Description: Blog about Ruby, Agile, Testing and other topics related to software development.
Usage Hash#assert_valid_keys gives you the ability to verify that each of the keys in the Hash are expected. For example, if you take an options Hash as an argument to a method you may want to validate that only expected options are passed as part of the hash; assert_valid_keys gives the the ability to list the keys you expect.
unit_tests do test "raise argument error on unexpected key"do assert_raises ArgumentErrordo {:invalid_key=>:a,:valid_key=>:b}.assert_valid_keys(:valid_key) end end end