Sha256: c494a70ad9604029e58b29ab085d1e126bccbd463d58fe0f8becf702da746388

Contents?: true

Size: 553 Bytes

Versions: 5

Compression:

Stored size: 553 Bytes

Contents

describe Array do
  describe "#element_counts" do
    it "without a block" do
      expect([].element_counts).to eq({})
      expect([1].element_counts).to eq({1 => 1})
      expect([nil].element_counts).to eq({nil => 1})
      expect([1, 2, 3, 1, 3, 1].element_counts).to eq({1 => 3, 2 => 1, 3 => 2})
    end

    it "with a block" do
      expect([].element_counts(&:size)).to eq({})
      expect(%w(a).element_counts(&:size)).to eq({1 => 1})
      expect(%w(a aa aaa a aaa a).element_counts(&:size)).to eq({1 => 3, 2 => 1, 3 => 2})
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
more_core_extensions-3.2.0 spec/core_ext/array/element_counts_spec.rb
more_core_extensions-3.1.1 spec/core_ext/array/element_counts_spec.rb
more_core_extensions-3.1.0 spec/core_ext/array/element_counts_spec.rb
more_core_extensions-3.0.0 spec/core_ext/array/element_counts_spec.rb
more_core_extensions-2.0.0 spec/core_ext/array/element_counts_spec.rb