Sha256: 4f3f5f9a51960b1ef9722ed3a4ecd451f93091b03be4f04709be5ef6dad0b2ac

Contents?: true

Size: 948 Bytes

Versions: 1

Compression:

Stored size: 948 Bytes

Contents

require 'spec_helper'

describe Enumerable do
  
  it 'should allow mapping elements of the collection to hashes associating method names to 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

1 entries across 1 versions & 1 rubygems

Version Path
ruby_core_extensions-0.0.1 spec/enumerable_spec.rb