diff options
Diffstat (limited to 'spec/ruby/core/enumerable/tally_spec.rb')
-rw-r--r-- | spec/ruby/core/enumerable/tally_spec.rb | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/spec/ruby/core/enumerable/tally_spec.rb b/spec/ruby/core/enumerable/tally_spec.rb index f09a8f533a..e0edc8dc75 100644 --- a/spec/ruby/core/enumerable/tally_spec.rb +++ b/spec/ruby/core/enumerable/tally_spec.rb @@ -49,6 +49,13 @@ ruby_version_is "3.1" do enum.tally(hash).should equal(hash) end + it "calls #to_hash to convert argument to Hash implicitly if passed not a Hash" do + enum = EnumerableSpecs::Numerous.new('foo', 'bar', 'foo', 'baz') + object = Object.new + def object.to_hash; { 'foo' => 1 }; end + enum.tally(object).should == { 'foo' => 3, 'bar' => 1, 'baz' => 1} + end + it "raises a FrozenError and does not update the given hash when the hash is frozen" do enum = EnumerableSpecs::Numerous.new('foo', 'bar', 'foo', 'baz') hash = { 'foo' => 1 }.freeze @@ -56,6 +63,12 @@ ruby_version_is "3.1" do hash.should == { 'foo' => 1 } end + it "raises a FrozenError even if enumerable is empty" do + enum = EnumerableSpecs::Numerous.new() + hash = { 'foo' => 1 }.freeze + -> { enum.tally(hash) }.should raise_error(FrozenError) + end + it "does not call given block" do enum = EnumerableSpecs::Numerous.new('foo', 'bar', 'foo', 'baz') enum.tally({ 'foo' => 1 }) { |v| ScratchPad << v } |