Sha256: b35fc8ed4f77914e7ae4c4ef3b28edfbce88455228abfcd7b59e60faee151f85

Contents?: true

Size: 690 Bytes

Versions: 4

Compression:

Stored size: 690 Bytes

Contents

# frozen_string_literal: true

RSpec.describe Fear::Option do
  describe "pattern matching" do
    subject do
      case value
      in Fear::Some(Integer => int)
        "some of #{int}"
      in Fear::None
        "none"
      else
        "something else"
      end
    end

    context "when value is some of integer" do
      let(:value) { Fear.some(42) }

      it { is_expected.to eq("some of 42") }
    end

    context "when value is none" do
      let(:value) { Fear.none }

      it { is_expected.to eq("none") }
    end

    context "when value is not some of integer" do
      let(:value) { Fear.some("42") }

      it { is_expected.to eq("something else") }
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
fear-3.0.0 spec/fear/option_pattern_matching_spec.rb
fear-2.0.1 spec/fear/option_pattern_matching_spec.rb
fear-2.0.0 spec/fear/option_pattern_matching_spec.rb
fear-1.2.0 spec/fear/option_pattern_matching_spec.rb