Sha256: 6f8e74769810db1c4d04e7d1c36ecdd02e2858affcdb5d50f113e3e441482f49

Contents?: true

Size: 1.63 KB

Versions: 2

Compression:

Stored size: 1.63 KB

Contents

require "spec_helper"
require "hamster/list"

describe Hamster::List do
  let(:list) { Hamster.list(*values) }
  let(:selected_list) { Hamster.list(*selected_values) }

  describe "#select" do
    it "is lazy" do
      expect { Hamster.stream { fail }.select { |item| false } }.to_not raise_error
    end

    shared_examples "checking values" do
      context "with a block" do
        let(:select) { list.select { |item| item == item.upcase } }

        it "preserves the original" do
          expect(list).to eq(Hamster.list(*values))
        end

        it "returns the selected list" do
          expect(select).to eq(selected_list)
        end
      end

      context "without a block" do
        let(:select) { list.select }

        it "returns itself" do
          expect(select).to eq(list)
        end
      end
    end

    context "with an empty array" do
      let(:values) { [] }
      let(:selected_values) { [] }

      include_examples "checking values"
    end

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

      include_examples "checking values"
    end

    context "with a multi-item array" do
      let(:values) { %w[A B] }
      let(:selected_values) { %w[A B] }

      include_examples "checking values"
    end

    context "with a multi-item single selectable array" do
      let(:values) { %w[A b] }
      let(:selected_values) { ["A"] }

      include_examples "checking values"
    end

    context "with a multi-item multi-selectable array" do
      let(:values) { %w[a b] }
      let(:selected_values) { [] }

      include_examples "checking values"
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
hamster-1.0.1.pre.rc2 spec/hamster/list/select_spec.rb
hamster-1.0.1.pre.rc.1 spec/hamster/list/select_spec.rb