Sha256: f20b4215ced67d167a3a3ae4970126a8e3ab19ccacbff12dc8b28aa496e84adc

Contents?: true

Size: 1.36 KB

Versions: 2

Compression:

Stored size: 1.36 KB

Contents

require "spec_helper"
require "hamster/set"

describe Hamster::Set do
  let(:set) { S[*values] }

  describe "#grep" do
    let(:grep) { set.grep(String, &block) }

    shared_examples "check filtered values" do
      it "returns the filtered values" do
        expect(grep).to eq(S[*filtered])
      end
    end

    context "without a block" do
      let(:block) { nil }

      context "with an empty set" do
        let(:values) { [] }
        let(:filtered) { [] }

        include_examples "check filtered values"
      end

      context "with a single item set" do
        let(:values) { ["A"] }
        let(:filtered) { ["A"] }

        include_examples "check filtered values"
      end

      context "with a single item set that doesn't contain match" do
        let(:values) { [1] }
        let(:filtered) { [] }

        include_examples "check filtered values"
      end

      context "with a multi-item set where one isn't a match" do
        let(:values) { ["A", 2, "C"] }
        let(:filtered) { %w[A C] }

        include_examples "check filtered values"
      end
    end

    describe "with a block" do
      let(:block) { ->(item) { item.downcase }}

      context "processes each matching item with the block" do
        let(:values) { ["A", 2, "C"] }
        let(:filtered) { %w[a c] }

        include_examples "check filtered values"
      end
    end
  end
end

Version data entries

2 entries across 2 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/set/grep_spec.rb
hamster-3.0.0 spec/lib/hamster/set/grep_spec.rb