1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
require_relative '../../spec_helper'
require_relative 'fixtures/classes'
describe 'Enumerable#filter_map' do
before :each do
@numerous = EnumerableSpecs::Numerous.new(*(1..8).to_a)
end
it 'returns an empty array if there are no elements' do
EnumerableSpecs::Empty.new.filter_map { true }.should == []
end
it 'returns an array with truthy results of passing each element to block' do
@numerous.filter_map { |i| i * 2 if i.even? }.should == [4, 8, 12, 16]
@numerous.filter_map { |i| i * 2 }.should == [2, 4, 6, 8, 10, 12, 14, 16]
@numerous.filter_map { 0 }.should == [0, 0, 0, 0, 0, 0, 0, 0]
@numerous.filter_map { false }.should == []
@numerous.filter_map { nil }.should == []
end
it 'returns an enumerator when no block given' do
@numerous.filter_map.should be_an_instance_of(Enumerator)
end
end
|