blob: 026e454b13cabfff93e1a388d79db04d9b34dd49 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
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 be_nil
h[:a] = 1
h.except(:a).default.should be_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 be_nil
h[:a] = 1
h.except(:a).default_proc.should be_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
|