Sha256: 31fc7b0645a4e452591656311f33484b8fd5d24125b2ab6989aacfd02fc9c4bd

Contents?: true

Size: 900 Bytes

Versions: 2

Compression:

Stored size: 900 Bytes

Contents

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.call(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

2 entries across 2 versions & 1 rubygems

Version Path
fear-1.0.0 spec/fear/partial_function/empty_spec.rb
fear-0.11.0 spec/fear/partial_function/empty_spec.rb