From 0acbdd1ed0d2302743525a5188cc5a0d6251680c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alfonso=20Jim=C3=A9nez?= Date: Tue, 20 Nov 2018 11:51:08 +0100 Subject: Adding Enumerable#filter_map [Feature #15323] Closes: https://github.com/ruby/ruby/pull/2017 --- spec/ruby/core/enumerable/filter_map_spec.rb | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 spec/ruby/core/enumerable/filter_map_spec.rb (limited to 'spec/ruby/core/enumerable/filter_map_spec.rb') diff --git a/spec/ruby/core/enumerable/filter_map_spec.rb b/spec/ruby/core/enumerable/filter_map_spec.rb new file mode 100644 index 0000000000..31acc277b4 --- /dev/null +++ b/spec/ruby/core/enumerable/filter_map_spec.rb @@ -0,0 +1,26 @@ +require_relative '../../spec_helper' +require_relative 'fixtures/classes' + +ruby_version_is '2.7' do + 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 +end -- cgit v1.2.3