Sha256: d7261e4b5f4e0fadfc43430417be0ebd360f430462900527fa1e97bd6415e88c

Contents?: true

Size: 1.57 KB

Versions: 83

Compression:

Stored size: 1.57 KB

Contents

require File.dirname(File.join(__rhoGetCurrentDir(), __FILE__)) + '/../../spec_helper'
require File.dirname(File.join(__rhoGetCurrentDir(), __FILE__)) + '/fixtures/classes'

describe "Enumerable#zip" do

  it "combines each element of the receiver with the element of the same index in arrays given as arguments" do
    EnumerableSpecs::Numerous.new(1,2,3).zip([4,5,6],[7,8,9]).should == [[1,4,7],[2,5,8],[3,6,9]]
    EnumerableSpecs::Numerous.new(1,2,3).zip.should == [[1],[2],[3]]
  end
  
  it "passes each element of the result array to a block and return nil if a block is given" do
    expected = [[1,4,7],[2,5,8],[3,6,9]]
    EnumerableSpecs::Numerous.new(1,2,3).zip([4,5,6],[7,8,9]) do |result_component|
      result_component.should == expected.shift
    end.should == nil
    expected.size.should == 0
  end
  
  it "fills resulting array with nils if an argument array is too short" do
    EnumerableSpecs::Numerous.new(1,2,3).zip([4,5,6], [7,8]).should == [[1,4,7],[2,5,8],[3,6,nil]]
  end
  
  ruby_version_is ''...'1.9' do
    it "converts arguments to arrays using #to_a" do
      convertable = EnumerableSpecs::ArrayConvertable.new(4,5,6)
      EnumerableSpecs::Numerous.new(1,2,3).zip(convertable).should == [[1,4],[2,5],[3,6]]
      convertable.called.should == :to_a
    end
  end
  
  ruby_version_is '1.9' do
    it "converts arguments to arrays using #to_ary" do
      convertable = EnumerableSpecs::ArrayConvertable.new(4,5,6)
      EnumerableSpecs::Numerous.new(1,2,3).zip(convertable).should == [[1,4],[2,5],[3,6]]
      convertable.called.should == :to_ary
    end
  end
  
end

Version data entries

83 entries across 83 versions & 1 rubygems

Version Path
rhodes-3.1.1 spec/framework_spec/app/spec/core/enumerable/zip_spec.rb
rhodes-3.1.1.beta spec/framework_spec/app/spec/core/enumerable/zip_spec.rb
rhodes-3.1.0 spec/framework_spec/app/spec/core/enumerable/zip_spec.rb
rhodes-3.1.0.beta.5 spec/framework_spec/app/spec/core/enumerable/zip_spec.rb
rhodes-3.1.0.beta.4 spec/framework_spec/app/spec/core/enumerable/zip_spec.rb
rhodes-3.1.0.beta.3 spec/framework_spec/app/spec/core/enumerable/zip_spec.rb
rhodes-3.1.0.beta.2 spec/framework_spec/app/spec/core/enumerable/zip_spec.rb
rhodes-3.1.0.beta.1 spec/framework_spec/app/spec/core/enumerable/zip_spec.rb
rhodes-3.0.2 spec/framework_spec/app/spec/core/enumerable/zip_spec.rb
rhodes-3.0.2.beta.1 spec/framework_spec/app/spec/core/enumerable/zip_spec.rb
rhodes-3.0.1 spec/framework_spec/app/spec/core/enumerable/zip_spec.rb
rhodes-3.0.1.beta.8 spec/framework_spec/app/spec/core/enumerable/zip_spec.rb
rhodes-3.0.1.beta.7 spec/framework_spec/app/spec/core/enumerable/zip_spec.rb
rhodes-3.0.1.beta.6 spec/framework_spec/app/spec/core/enumerable/zip_spec.rb
rhodes-3.0.1.beta.5 spec/framework_spec/app/spec/core/enumerable/zip_spec.rb
rhodes-3.0.1.beta.4 spec/framework_spec/app/spec/core/enumerable/zip_spec.rb
rhodes-3.0.1.beta.3 spec/framework_spec/app/spec/core/enumerable/zip_spec.rb
rhodes-3.0.1.beta.2 spec/framework_spec/app/spec/core/enumerable/zip_spec.rb
rhodes-3.0.0 spec/framework_spec/app/spec/core/enumerable/zip_spec.rb
rhodes-3.0.0.beta.7 spec/framework_spec/app/spec/core/enumerable/zip_spec.rb