Sha256: 09b71e8342d564148173cee0d97d237b0414f65060274221f4e4b66c8cb0fa70

Contents?: true

Size: 1.46 KB

Versions: 52

Compression:

Stored size: 1.46 KB

Contents

describe :enumerable_collect, :shared => true do
  before :each do
    ScratchPad.record []
  end

  it "returns a new array with the results of passing each element to block" do
    entries = [0, 1, 3, 4, 5, 6]
    numerous = EnumerableSpecs::Numerous.new(*entries)
    numerous.send(@method) { |i| i % 2 }.should == [0, 1, 1, 0, 1, 0]
    numerous.send(@method) { |i| i }.should == entries
  end

  it "passes through the values yielded by #each_with_index" do
    [:a, :b].each_with_index.send(@method) { |x, i| ScratchPad << [x, i]; nil }
    ScratchPad.recorded.should == [[:a, 0], [:b, 1]]
  end

  ruby_version_is "" ... "1.9" do
    it "gathers whole arrays as elements when each yields multiple" do
      multi = EnumerableSpecs::YieldsMulti.new
      multi.send(@method) {|e| e}.should == [[1,2],[3,4,5],[6,7,8,9]]
    end
  end

  ruby_version_is "1.9" do
    it "gathers initial args as elements when each yields multiple" do
      multi = EnumerableSpecs::YieldsMulti.new
      multi.send(@method) {|e| e}.should == [1,3,6]
    end
  end

  ruby_version_is "" ... "1.9" do
    it "returns to_a when no block given" do
      EnumerableSpecs::Numerous.new.send(@method).should == [2, 5, 3, 6, 1, 4]
    end
  end

  ruby_version_is "1.9" do
    it "returns an enumerator when no block given" do
      enum = EnumerableSpecs::Numerous.new.send(@method)
      enum.should be_an_instance_of(enumerator_class)
      enum.each { |i| -i }.should == [-2, -5, -3, -6, -1, -4]
    end
  end
end

Version data entries

52 entries across 52 versions & 2 rubygems

Version Path
rhodes-7.6.0 spec/framework_spec/app/spec/core/enumerable/shared/collect.rb
rhodes-7.5.1 spec/framework_spec/app/spec/core/enumerable/shared/collect.rb
rhodes-7.4.1 spec/framework_spec/app/spec/core/enumerable/shared/collect.rb
rhodes-7.1.17 spec/framework_spec/app/spec/core/enumerable/shared/collect.rb
rhodes-6.2.0 spec/framework_spec/app/spec/core/enumerable/shared/collect.rb
rhodes-6.0.11 spec/framework_spec/app/spec/core/enumerable/shared/collect.rb
rhodes-5.5.18 spec/framework_spec/app/spec/core/enumerable/shared/collect.rb
rhodes-5.5.17 spec/framework_spec/app/spec/core/enumerable/shared/collect.rb
rhodes-5.5.15 spec/framework_spec/app/spec/core/enumerable/shared/collect.rb
rhodes-5.5.0.22 spec/framework_spec/app/spec/core/enumerable/shared/collect.rb
rhodes-5.5.2 spec/framework_spec/app/spec/core/enumerable/shared/collect.rb
rhodes-5.5.0.7 spec/framework_spec/app/spec/core/enumerable/shared/collect.rb
rhodes-5.5.0.3 spec/framework_spec/app/spec/core/enumerable/shared/collect.rb
rhodes-5.5.0 spec/framework_spec/app/spec/core/enumerable/shared/collect.rb
tauplatform-1.0.3 spec/framework_spec/app/spec/core/enumerable/shared/collect.rb
tauplatform-1.0.2 spec/framework_spec/app/spec/core/enumerable/shared/collect.rb
tauplatform-1.0.1 spec/framework_spec/app/spec/core/enumerable/shared/collect.rb
rhodes-3.5.1.12 spec/framework_spec/app/spec/core/enumerable/shared/collect.rb
rhodes-3.3.5 spec/framework_spec/app/spec/core/enumerable/shared/collect.rb
rhodes-3.4.2 spec/framework_spec/app/spec/core/enumerable/shared/collect.rb