Sha256: 2413b5870a4f0e625aee79396a44a84b6f3e202f0eb436aa7fe90355ab910a54

Contents?: true

Size: 1.33 KB

Versions: 6

Compression:

Stored size: 1.33 KB

Contents

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

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

6 entries across 6 versions & 1 rubygems

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