Sha256: fb47df153417ffe7c03b41c66bc404722b26565c89616101f6222e4f0955a57c

Contents?: true

Size: 877 Bytes

Versions: 6

Compression:

Stored size: 877 Bytes

Contents

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

require 'hamster/list'

describe Hamster do

  describe "#cycle" do

    it "is lazy" do
      lambda { Hamster.stream { fail }.cycle }.should_not raise_error
    end

    describe "with an empty list" do

      before do
        original = Hamster.list
        @result = original.cycle
      end

      it "returns an empty list" do
        @result.should be_empty
      end

    end

    describe "with a non-empty list" do

      before do
        @original = Hamster.list("A", "B", "C")
        @result = @original.cycle
      end

      it "preserves the original" do
        @original.should == Hamster.list("A", "B", "C")
      end

      it "infinitely cycles through all values" do
        @result.take(7).should == Hamster.list("A", "B", "C", "A", "B", "C", "A")
      end

    end

  end

end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
hamster-0.2.5 spec/hamster/list/cycle_spec.rb
hamster-0.2.4 spec/hamster/list/cycle_spec.rb
hamster-0.2.3 spec/hamster/list/cycle_spec.rb
hamster-0.2.2 spec/hamster/list/cycle_spec.rb
hamster-0.2.1 spec/hamster/list/cycle_spec.rb
hamster-0.2.0 spec/hamster/list/cycle_spec.rb