diff options
Diffstat (limited to 'spec/ruby/core/hash/shared/select.rb')
| -rw-r--r-- | spec/ruby/core/hash/shared/select.rb | 35 |
1 files changed, 28 insertions, 7 deletions
diff --git a/spec/ruby/core/hash/shared/select.rb b/spec/ruby/core/hash/shared/select.rb index 5170af50d6..b4f6d1b3ac 100644 --- a/spec/ruby/core/hash/shared/select.rb +++ b/spec/ruby/core/hash/shared/select.rb @@ -17,7 +17,7 @@ describe :hash_select, shared: true do it "returns a Hash of entries for which block is true" do a_pairs = { 'a' => 9, 'c' => 4, 'b' => 5, 'd' => 2 }.send(@method) { |k,v| v % 2 == 0 } - a_pairs.should be_an_instance_of(Hash) + a_pairs.should.instance_of?(Hash) a_pairs.sort.should == [['c', 4], ['d', 2]] end @@ -33,11 +33,32 @@ describe :hash_select, shared: true do end it "returns an Enumerator when called on a non-empty hash without a block" do - @hsh.send(@method).should be_an_instance_of(Enumerator) + @hsh.send(@method).should.instance_of?(Enumerator) end it "returns an Enumerator when called on an empty hash without a block" do - @empty.send(@method).should be_an_instance_of(Enumerator) + @empty.send(@method).should.instance_of?(Enumerator) + end + + it "does not retain the default value" do + h = Hash.new(1) + h.send(@method) { true }.default.should == nil + h[:a] = 1 + h.send(@method) { true }.default.should == nil + end + + it "does not retain the default_proc" do + pr = proc { |h, k| h[k] = [] } + h = Hash.new(&pr) + h.send(@method) { true }.default_proc.should == nil + h[:a] = 1 + h.send(@method) { true }.default_proc.should == nil + end + + it "retains compare_by_identity flag" do + h = { a: 9, c: 4 }.compare_by_identity + h2 = h.send(@method) { |k, _| k == :a } + h2.compare_by_identity?.should == true end it_should_behave_like :hash_iteration_no_block @@ -56,7 +77,7 @@ describe :hash_select!, shared: true do it "is equivalent to keep_if if changes are made" do h = { a: 2 } - h.send(@method) { |k,v| v <= 1 }.should equal h + h.send(@method) { |k,v| v <= 1 }.should.equal? h h = { 1 => 2, 3 => 4 } all_args_select = [] @@ -66,7 +87,7 @@ describe :hash_select!, shared: true do it "removes all entries if the block is false" do h = { a: 1, b: 2, c: 3 } - h.send(@method) { |k,v| false }.should equal(h) + h.send(@method) { |k,v| false }.should.equal?(h) h.should == {} end @@ -75,11 +96,11 @@ describe :hash_select!, shared: true do end it "raises a FrozenError if called on an empty frozen instance" do - -> { HashSpecs.empty_frozen_hash.send(@method) { false } }.should raise_error(FrozenError) + -> { HashSpecs.empty_frozen_hash.send(@method) { false } }.should.raise(FrozenError) end it "raises a FrozenError if called on a frozen instance that would not be modified" do - -> { HashSpecs.frozen_hash.send(@method) { true } }.should raise_error(FrozenError) + -> { HashSpecs.frozen_hash.send(@method) { true } }.should.raise(FrozenError) end it_should_behave_like :hash_iteration_no_block |
