Sha256: 433f5b07e6166d8229376b6b6404ceb107d97c23d4f53ce2994d5d15b7acb326

Contents?: true

Size: 1.38 KB

Versions: 6

Compression:

Stored size: 1.38 KB

Contents

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

require 'hamster/list'

describe Hamster::List do

  [:map, :collect].each do |method|

    describe "##{method}" do

      it "is lazy" do
        lambda { Hamster.stream { fail }.map { |item| item } }.should_not raise_error
      end

      [
        [[], []],
        [["A"], ["a"]],
        [["A", "B", "C"], ["a", "b", "c"]],
      ].each do |values, expected|

        describe "on #{values.inspect}" do

          before do
            @original = Hamster.list(*values)
          end

          describe "with a block" do

            before do
              @result = @original.send(method) { |item| item.downcase }
            end

            it "preserves the original" do
              @original.should == Hamster.list(*values)
            end

            it "returns #{expected.inspect}" do
              @result.should == Hamster.list(*expected)
            end

            it "is lazy" do
              count = 0
              @original.send(method) { |item| count += 1 }
              count.should <= 1
            end

          end

          describe "without a block" do

            before do
              @result = @original.send(method)
            end

            it "returns self" do
              @result.should equal(@original)
            end

          end

        end

      end

    end

  end

end

Version data entries

6 entries across 6 versions & 1 rubygems

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