Sha256: db6f06618d10b336e653d5ac7452f65776b4d79bb9578ff4d4a854b0d617142e

Contents?: true

Size: 1.1 KB

Versions: 3

Compression:

Stored size: 1.1 KB

Contents

require "spec_helper"
require "hamster/list"

describe Hamster::List do
  describe "#grep" do
    it "is lazy" do
      -> { Hamster.stream { fail }.grep(Object) { |item| item } }.should_not raise_error
    end

    context "without a block" do
      [
        [[], []],
        [["A"], ["A"]],
        [[1], []],
        [["A", 2, "C"], %w[A C]],
      ].each do |values, expected|
        context "on #{values.inspect}" do
          it "returns #{expected.inspect}" do
            L[*values].grep(String).should eql(L[*expected])
          end
        end
      end
    end

    context "with a block" do
      [
        [[], []],
        [["A"], ["a"]],
        [[1], []],
        [["A", 2, "C"], %w[a c]],
      ].each do |values, expected|
        context "on #{values.inspect}" do
          let(:list) { L[*values] }

          it "preserves the original" do
            list.grep(String, &:downcase)
            list.should eql(L[*values])
          end

          it "returns #{expected.inspect}" do
            list.grep(String, &:downcase).should eql(L[*expected])
          end
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 2 rubygems

Version Path
files.com-1.0.55 docs/vendor/bundle/ruby/2.5.0/gems/hamster-3.0.0/spec/lib/hamster/list/grep_spec.rb
hamster-3.0.0 spec/lib/hamster/list/grep_spec.rb
hamster-2.0.0 spec/lib/hamster/list/grep_spec.rb