Permalink
Browse files

Ensure Hash#except is allowed on a frozen hash. References #382

Signed-off-by: Pratik Naik <pratiknaik@gmail.com>
  • Loading branch information...
1 parent 91c14e9 commit 980c2985fd16ec51c32cc90794be655d0cd08c49 @mislav mislav committed with lifo Sep 13, 2008
@@ -10,7 +10,7 @@ module Hash #:nodoc:
module Except
# Returns a new hash without the given keys.
def except(*keys)
- clone.except!(*keys)
+ dup.except!(*keys)
end
# Replaces the hash without only the given keys.
@@ -310,6 +310,20 @@ def test_except
assert_equal expected, original.except!(:c)
assert_equal expected, original
end
+
+ def test_except_with_original_frozen
+ original = { :a => 'x', :b => 'y' }
+ original.freeze
+ assert_nothing_raised { original.except(:a) }
+ end
+
+ uses_mocha 'except with expectation' do
+ def test_except_with_mocha_expectation_on_original
+ original = { :a => 'x', :b => 'y' }
+ original.expects(:delete).never
+ original.except(:a)
+ end
+ end
end
class IWriteMyOwnXML

0 comments on commit 980c298

Please sign in to comment.