Sha256: e05f04c8e78947aa7c00495490835f1603927ddfa80a3255a72fbdf3ea84a520

Contents?: true

Size: 723 Bytes

Versions: 3

Compression:

Stored size: 723 Bytes

Contents

# frozen_string_literal: true

require_relative '../spec_helper'

describe Enumerable do
  it "map_compact" do
    expect([1, 2, nil, 3, 4].map_compact { |item| item**2 if (nil == item ? nil : item.odd?) }).to eq([1, 9])
  end

  it "map_compact to empty if nothing matches" do
    expect({:a => 'aaa', :b => 'bbb'}.map_compact { |key, value| value if key == :c }).to eq([])
  end

  it "map_compact a hash" do
    expect({:a => 'aaa', :b => 'bbb'}.map_compact { |key, value| value if key == :b }).to eq(['bbb'])
  end

  it "map_compact empty collection" do
    expect([].map_compact { |item| true }).to eq([])
  end

  it "not map_compact false" do
    expect([nil, false].map_compact { |a| a }).to eq([false])
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
invoca-utils-0.6.0 spec/unit/map_compact_spec.rb
invoca-utils-0.5.1 spec/unit/map_compact_spec.rb
invoca-utils-0.5.0 spec/unit/map_compact_spec.rb