Sha256: 5e6755513b6d9c63c160f008a718be09d60b4253acfb5466d82a194165db3f32

Contents?: true

Size: 927 Bytes

Versions: 1

Compression:

Stored size: 927 Bytes

Contents

# frozen_string_literal: true

RSpec.describe Fear::PartialFunction::Empty do
  describe "#defined?" do
    subject { described_class.defined_at?(42) }

    it { is_expected.to be(false) }
  end

  describe "#call" do
    subject { -> { described_class.(42) } }

    it { is_expected.to raise_error(Fear::MatchError, "partial function not defined at: 42") }
  end

  describe "#call_or_else" do
    subject { described_class.call_or_else(42, &default) }
    let(:default) { ->(x) { "default: #{x}" } }

    it { is_expected.to eq("default: 42") }
  end

  describe "#and_then" do
    subject { described_class.and_then { |_x| "then" } }

    it { is_expected.to eq(described_class) }
  end

  describe "#or_else" do
    subject { described_class.or_else(other) }

    let(:other) { Fear.case(proc { true }) { "other" } }

    it { is_expected.to eq(other) }
  end

  it { is_expected.to be_kind_of(Fear::PartialFunction) }
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
fear-3.0.0 spec/fear/partial_function/empty_spec.rb