summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2021-03-26 16:29:21 +0900
committerGitHub <noreply@github.com>2021-03-26 16:29:21 +0900
commit9143d21b1bf2f16b1e847d569a588510726d8860 (patch)
tree8e2d3e939c64a5bd29c26e4416e753b89cfb5333 /spec
parent6a352e275bfdad84bec479b84dd2bc6d76697226 (diff)
Enumerable#tally with the resulting hash [Feature #17744]
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/4318 Merged-By: nobu <nobu@ruby-lang.org>
Diffstat (limited to 'spec')
-rw-r--r--spec/ruby/core/enumerable/tally_spec.rb28
1 files changed, 28 insertions, 0 deletions
diff --git a/spec/ruby/core/enumerable/tally_spec.rb b/spec/ruby/core/enumerable/tally_spec.rb
index 363b3def21..1367453f44 100644
--- a/spec/ruby/core/enumerable/tally_spec.rb
+++ b/spec/ruby/core/enumerable/tally_spec.rb
@@ -33,3 +33,31 @@ ruby_version_is "2.7" do
end
end
end
+
+ruby_version_is "3.1" do
+ describe "Enumerable#tally with a hash" do
+ before :each do
+ ScratchPad.record []
+ end
+
+ it "returns a hash with counts according to the value" do
+ enum = EnumerableSpecs::Numerous.new('foo', 'bar', 'foo', 'baz')
+ enum.tally({ 'foo' => 1 }).should == { 'foo' => 3, 'bar' => 1, 'baz' => 1}
+ end
+
+ it "ignores the default value" do
+ enum = EnumerableSpecs::Numerous.new('foo', 'bar', 'foo', 'baz')
+ enum.tally(Hash.new(100)).should == { 'foo' => 2, 'bar' => 1, 'baz' => 1}
+ end
+
+ it "ignores the default proc" do
+ enum = EnumerableSpecs::Numerous.new('foo', 'bar', 'foo', 'baz')
+ enum.tally(Hash.new {100}).should == { 'foo' => 2, 'bar' => 1, 'baz' => 1}
+ end
+
+ it "needs the values counting each elements to be an integer" do
+ enum = EnumerableSpecs::Numerous.new('foo')
+ -> { enum.tally({ 'foo' => 'bar' }) }.should raise_error(TypeError)
+ end
+ end
+end