Sha256: f531dc10b7646f4955ada90203ffb5c31bc2e3d48f52ecd403c25d436ce3491e

Contents?: true

Size: 1.51 KB

Versions: 2

Compression:

Stored size: 1.51 KB

Contents

require "spec_helper"
require "hamster/vector"

describe Hamster::Vector do
  let(:vector) { Hamster.vector(*values) }

  describe "#exists?" do
    let(:exists?) { vector.exists?(&block) }

    context "when created with no values" do
      let(:values) { [] }

      context "with a block" do
        let(:block) { ->(item) { item + 1 } }

        it "returns false" do
          expect(exists?).to be(false)
        end
      end

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

        it "returns false" do
          expect(exists?).to be(false)
        end
      end
    end

    context "when created with values" do
      let(:values) { ["A", "B", 3, nil] }

      context "with a block that returns true" do
        let(:block) { ->(item) { item == 3 } }

        it "returns true" do
          expect(exists?).to be(true)
        end
      end

      context "with a block that doesn't return true" do
        let(:block) { ->(item) { item == "D" } }

        it "returns false" do
          expect(exists?).to be(false)
        end
      end

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

        context "with some values that are truthy" do
          let(:values) { [nil, false, "B"] }

          it "returns true" do
            expect(exists?).to be(true)
          end
        end

        context "with all values that are falsey" do
          let(:values) { [nil, false] }

          it "returns false" do
            expect(exists?).to be(false)
          end
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
hamster-1.0.1.pre.rc2 spec/lib/hamster/vector/exists_spec.rb
hamster-1.0.1.pre.rc.1 spec/lib/hamster/vector/exists_spec.rb