Sha256: 0957524c6318607671633176fb626fdb8cc8482a0ede4a48f1a56e6506113fcd

Contents?: true

Size: 1.2 KB

Versions: 5

Compression:

Stored size: 1.2 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
      expect(array).to eq((0..9).to_a)
    end

    it 'should be composable with other iterators' do
      expect(yielder.each.map{|n| n}).to eq((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
      expect(array).to eq((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
      expect(yielder.to_enum).to 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

5 entries across 5 versions & 1 rubygems

Version Path
pupa-0.2.4 spec/processor/yielder_spec.rb
pupa-0.2.3 spec/processor/yielder_spec.rb
pupa-0.2.2 spec/processor/yielder_spec.rb
pupa-0.2.1 spec/processor/yielder_spec.rb
pupa-0.2.0 spec/processor/yielder_spec.rb