Sha256: a3aaff532b49da307b492c844f79e302113a5645ef0135cc58bae228044102c7

Contents?: true

Size: 717 Bytes

Versions: 4

Compression:

Stored size: 717 Bytes

Contents

# frozen_string_literal: true

RSpec.describe Fear::PatternMatchingApi do
  describe "Fear.match" do
    subject do
      Fear.match(value) do |m|
        m.case(Integer, :even?.to_proc) { |x| "#{x} is even" }
        m.case(Integer, :odd?.to_proc) { |x| "#{x} is odd" }
        m.else { |x| "#{x} is not a number" }
      end
    end

    context "when one branch matches" do
      let(:value) { 42 }

      it { is_expected.to eq("42 is even") }
    end

    context "when another branch matches" do
      let(:value) { 21 }

      it { is_expected.to eq("21 is odd") }
    end

    context "when else matches" do
      let(:value) { "foo" }

      it { is_expected.to eq("foo is not a number") }
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

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