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 113de01 commit 96055414d6197b9705e408c17236f79372a007e5 @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 the given keys.
@@ -341,6 +341,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 9605541

Please sign in to comment.