Sha256: dda4823e0272c3df469ec1f297552f6c83e66ef2e7fb5944995fba079905cbe6

Contents?: true

Size: 912 Bytes

Versions: 4

Compression:

Stored size: 912 Bytes

Contents

require 'spec_helper'

describe Enumerable do

  it 'allow mapping elements to hashes with method names of the returned values for each method' do
    expect([1, 2, 3].map_methods(:to_s, :to_f)).to eq(
      [{ to_s: '1', to_f: 1.0 }, { to_s: '2', to_f: 2.0 }, { to_s: '3', to_f: 3.0 }]
    )
  end


  context 'when detecting and returning the block value' do
    it { expect([1, 2, 3].detect_and_return { |number| number.even? && number * number }).to eq 4 }
    it { expect([1, 3, 5].detect_and_return { |number|
      number.even? && number * number }).to be nil
    }
  end


  it 'should allow selecting by attribute' do
    one = double(name: 'one', type: 'odd')
    two = double(name: 'two', type: 'even')
    thr = double(name: 'thr', type: 'odd')
    expect([one, two, thr].select_by_attr(:type, 'odd')).to eq [one, thr]
    expect([one, two, thr].select_by_attr(:type, 'even')).to eq [two]
  end

end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
ruby_core_extensions-0.4.0 spec/enumerable_spec.rb
ruby_core_extensions-0.3.0 spec/enumerable_spec.rb
ruby_core_extensions-0.2.0 spec/enumerable_spec.rb
ruby_core_extensions-0.1.0 spec/enumerable_spec.rb