File: cycle_spec.rb

package info (click to toggle)
ruby-immutable-ruby 0.1.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,852 kB
  • sloc: ruby: 16,556; makefile: 4
file content (28 lines) | stat: -rw-r--r-- 632 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
require 'spec_helper'

describe Immutable do
  describe '#cycle' do
    it 'is lazy' do
      -> { Immutable.stream { fail }.cycle }.should_not raise_error
    end

    context 'with an empty list' do
      it 'returns an empty list' do
        L.empty.cycle.should be_empty
      end
    end

    context 'with a non-empty list' do
      let(:list) { L['A', 'B', 'C'] }

      it 'preserves the original' do
        list.cycle
        list.should == L['A', 'B', 'C']
      end

      it 'infinitely cycles through all values' do
        list.cycle.take(7).should == L['A', 'B', 'C', 'A', 'B', 'C', 'A']
      end
    end
  end
end