Sha256: 3ac00c8e0d19d75ddcdb248acf5327eed479c2a676ecdadd67444ec31eb1f5dd

Contents?: true

Size: 844 Bytes

Versions: 4

Compression:

Stored size: 844 Bytes

Contents

require 'facets/core/hash/has_only_keys'

class Hash

  # Returns true is hash has only then given keys,
  # otherwise throws an ArgumentError.
  #
  #   h = { :a => 1, :b => 2 }
  #   h.assert_has_only_keys( :a, :b )   #=> true
  #   h.assert_has_only_keys( :a )       #=> ArgumentError
  #
  def assert_has_only_keys(*check_keys)
    raise(ArgumentError, "has unexpected key(s)") unless has_only_keys?(*check_keys)
  end

end


#  _____         _
# |_   _|__  ___| |_
#   | |/ _ \/ __| __|
#   | |  __/\__ \ |_
#   |_|\___||___/\__|
#
=begin test

  require 'test/unit'

  class TCHash < Test::Unit::TestCase

    def test_assert_has_only_keys
      assert_nothing_raised {  { :a=>1,:b=>2,:c=>3 }.assert_has_only_keys(:a,:b,:c) }
      assert_raises( ArgumentError ) { { :a=>1,:b=>2,:c=>3 }.assert_has_only_keys(:a,:b) }
    end

  end

=end

Version data entries

4 entries across 4 versions & 2 rubygems

Version Path
facets-1.8.49 lib/facets/core/hash/assert_has_only_keys.rb
facets-1.8.51 lib/facets/core/hash/assert_has_only_keys.rb
facets-1.8.54 lib/facets/core/hash/assert_has_only_keys.rb
quarry-0.4.0 work/sandbox/testunit/assertions/assert_has_only_keys.rb