Sha256: e5e7796092c07aa6b6302c6cb5b0d9d11f3a0a67cfd53cfc8de14d2d8c7d516a

Contents?: true

Size: 1.33 KB

Versions: 2

Compression:

Stored size: 1.33 KB

Contents

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

require 'hamster/list'

describe Hamster::List do

  describe "#grep" do

    it "is lazy" do
      lambda { Hamster.stream { fail }.grep(Object) { |item| item } }.should_not raise_error
    end

    describe "without a block" do

      [
        [[], []],
        [["A"], ["A"]],
        [[1], []],
        [["A", 2, "C"], ["A", "C"]],
      ].each do |values, expected|

        describe "on #{values.inspect}" do

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

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

        end

      end

    end

    describe "with a block" do

      [
        [[], []],
        [["A"], ["a"]],
        [[1], []],
        [["A", 2, "C"], ["a", "c"]],
      ].each do |values, expected|

        describe "on #{values.inspect}" do

          before do
            @original = Hamster.list(*values)
            @result = @original.grep(String) { |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

        end

      end

    end

  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
hamster-0.2.7 spec/hamster/list/grep_spec.rb
hamster-0.2.6 spec/hamster/list/grep_spec.rb