Sha256: 1ebf6aa7a17ed0e6377761d69bd7fef2339bda64c778d29ea4e27aa54ae5e637

Contents?: true

Size: 1.18 KB

Versions: 25

Compression:

Stored size: 1.18 KB

Contents

require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')

describe Pupa::Processor::Yielder do
  let :yielder do
    Pupa::Processor::Yielder.new do
      10.times do |n|
        Fiber.yield(n)
      end
    end
  end

  let :raiser do
    Pupa::Processor::Yielder.new do
      raise
    end
  end

  describe '#each' do
    it 'should iterate over the items in the enumeration' do
      array = []
      yielder.each do |n|
        array << n
      end
      array.should == (0..9).to_a
    end

    it 'should be composable with other iterators' do
      yielder.each.map{|n| n}.should == (0..9).to_a
    end
  end

  describe '#next' do
    it 'should return the next item in the enumeration' do
      array = []
      10.times do |n|
        array << yielder.next
      end
      array.should == (0..9).to_a
    end

    it 'should raise an error if the enumerator is at the end' do
      expect{11.times{yielder.next}}.to raise_error(StopIteration)
    end
  end

  describe '#to_enum' do
    it 'should return an enumerator' do
      yielder.to_enum.should be_a(Enumerator)
    end

    it 'should return a lazy enumerator' do
      expect{raiser.to_enum}.to_not raise_error
    end
  end
end

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
pupa-0.1.11 spec/processor/yielder_spec.rb
pupa-0.1.10 spec/processor/yielder_spec.rb
pupa-0.1.9 spec/processor/yielder_spec.rb
pupa-0.1.8 spec/processor/yielder_spec.rb
pupa-0.1.7 spec/processor/yielder_spec.rb
pupa-0.1.6 spec/processor/yielder_spec.rb
pupa-0.1.5 spec/processor/yielder_spec.rb
pupa-0.1.4 spec/processor/yielder_spec.rb
pupa-0.1.3 spec/processor/yielder_spec.rb
pupa-0.1.2 spec/processor/yielder_spec.rb
pupa-0.1.1 spec/processor/yielder_spec.rb
pupa-0.1.0 spec/processor/yielder_spec.rb
pupa-0.0.13 spec/processor/yielder_spec.rb
pupa-0.0.12 spec/processor/yielder_spec.rb
pupa-0.0.11 spec/processor/yielder_spec.rb
pupa-0.0.10 spec/processor/yielder_spec.rb
pupa-0.0.9 spec/processor/yielder_spec.rb
pupa-0.0.8 spec/processor/yielder_spec.rb
pupa-0.0.7 spec/processor/yielder_spec.rb
pupa-0.0.6 spec/processor/yielder_spec.rb