Sha256: 0f96f695a33ecb9d1d69abb91ed39afcacbddbbc4991a166267249320ff014e4

Contents?: true

Size: 1.24 KB

Versions: 7

Compression:

Stored size: 1.24 KB

Contents

require File.expand_path('../test_helper', __FILE__)

describe "Array#take_and_map" do
  before do
    @array = %w{ foo bar baz foo/bar.baz foo/bar/baz }
  end
  
  it "should remove elements from the array for which the block evaluates to true" do
    @array.take_and_map { |x| x =~ /^ba/ }
    @array.should == %w{ foo foo/bar.baz foo/bar/baz }
  end
  
  it "should return a new array of the return values of each block call that evaluates to true" do
    @array.take_and_map { |x| $1 if x =~ /^ba(\w)/ }.should == %w{ r z }
  end
  
  it "should flatten and compact the result array" do
    @array.take_and_map do |x|
      x =~ /^ba/ ? %w{ f o o } : [nil]
    end.should == %w{ f o o f o o }
  end
  
  it "should not flatten and compact the result array if specified" do
    @array.take_and_map(nil, false) do |x|
      x =~ /^ba/ ? %w{ f o o } : [nil]
    end.should == [[nil], %w{ f o o }, %w{ f o o }, [nil], [nil]]
  end
  
  it "should take only files matching the pattern" do
    @array.take_and_map('**/*') { |x| x.reverse }.should ==
      %w{ foo/bar.baz foo/bar/baz }.map { |s| s.reverse }
  end
  
  it "should not remove files not matching the pattern" do
    @array.take_and_map('**/*') { |x| x }
    @array.should == %w{ foo bar baz }
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
kicker-2.4.0 test/core_ext_test.rb
kicker-2.3.1 test/core_ext_test.rb
kicker-2.3.0 test/core_ext_test.rb
kicker-2.2.3 test/core_ext_test.rb
kicker-2.2.2 test/core_ext_test.rb
kicker-2.2.1 test/core_ext_test.rb
kicker-2.2.0 test/core_ext_test.rb