diff options
Diffstat (limited to 'spec/ruby/core/hash/except_spec.rb')
| -rw-r--r-- | spec/ruby/core/hash/except_spec.rb | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/spec/ruby/core/hash/except_spec.rb b/spec/ruby/core/hash/except_spec.rb new file mode 100644 index 0000000000..77a020e9b7 --- /dev/null +++ b/spec/ruby/core/hash/except_spec.rb @@ -0,0 +1,42 @@ +require_relative '../../spec_helper' + +describe "Hash#except" do + before :each do + @hash = { a: 1, b: 2, c: 3 } + end + + it "returns a new duplicate hash without arguments" do + ret = @hash.except + ret.should_not.equal?(@hash) + ret.should == @hash + end + + it "returns a hash without the requested subset" do + @hash.except(:c, :a).should == { b: 2 } + end + + it "ignores keys not present in the original hash" do + @hash.except(:a, :chunky_bacon).should == { b: 2, c: 3 } + end + + it "does not retain the default value" do + h = Hash.new(1) + h.except(:a).default.should == nil + h[:a] = 1 + h.except(:a).default.should == nil + end + + it "does not retain the default_proc" do + pr = proc { |h, k| h[k] = [] } + h = Hash.new(&pr) + h.except(:a).default_proc.should == nil + h[:a] = 1 + h.except(:a).default_proc.should == nil + end + + it "retains compare_by_identity flag" do + h = { a: 9, c: 4 }.compare_by_identity + h2 = h.except(:a) + h2.compare_by_identity?.should == true + end +end |
