Sha256: 2355350b2f86732c8985c471bc87941d55b1ebec28d892d556b9e9bbf1038fe2

Contents?: true

Size: 1.51 KB

Versions: 3

Compression:

Stored size: 1.51 KB

Contents

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

describe Hamster do

  describe ".list" do

    describe "with no arguments" do

      before do
        @list = Hamster.list
      end

      it "always returns the same instance" do
        @list.should equal(Hamster.list)
      end

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

    end

    describe "with a number of items" do

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

      it "always returns a different instance" do
        @list.should_not equal(Hamster.list("A", "B", "C"))
      end

      it "is the same as repeatedly using #cons" do
        @list.should == Hamster.list.cons("C").cons("B").cons("A")
      end

    end

  end

  describe ".stream" do

    describe "with no block" do

      before do
        @stream = Hamster.stream
      end

      it "returns an empty list" do
        @stream.should == Hamster.list
      end

    end

    describe "with a block" do

      before do
        count = 0
        @stream = Hamster.stream { count += 1 }
      end

      it "repeatedly calls the block" do
        @stream.take(5).should == Hamster.list(1, 2, 3, 4, 5)
      end

    end

  end

  [:interval, :range].each do |method|

    describe ".#{method}" do

      before do
        @interval = Hamster.send(method, "A", "D")
      end

      it "is equivalent to a list with explicit values" do
        @interval.should == Hamster.list("A", "B", "C", "D")
      end

    end

  end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
hamster-0.1.14 spec/hamster/list/construction_spec.rb
hamster-0.1.13 spec/hamster/list/construction_spec.rb
hamster-0.1.12 spec/hamster/list/construction_spec.rb