Sha256: 11525d7e32212c59826fffbdee89a5786034d7e3aded60ae8795ed6e60747e11

Contents?: true

Size: 1.01 KB

Versions: 1

Compression:

Stored size: 1.01 KB

Contents

# frozen_string_literal: true

RSpec.describe Fear::Try::PatternMatch do
  context "Success" do
    let(:matcher) do
      described_class.new do |m|
        m.success(:even?.to_proc) { |x| "#{x} is even" }
        m.success(:odd?.to_proc) { |x| "#{x} is odd" }
      end
    end

    it do
      expect(matcher.(Fear.success(4))).to eq("4 is even")
      expect(matcher.(Fear.success(3))).to eq("3 is odd")
      expect do
        matcher.(Fear.failure(RuntimeError.new))
      end.to raise_error(Fear::MatchError)
    end
  end

  context "Failure" do
    let(:matcher) do
      described_class.new do |m|
        m.failure(RuntimeError) { |x| "#{x} is first" }
        m.failure(StandardError) { |x| "#{x} is second" }
      end
    end

    it do
      expect(matcher.(Fear.failure(RuntimeError.new))).to eq("RuntimeError is first")
      expect(matcher.(Fear.failure(StandardError.new))).to eq("StandardError is second")
      expect do
        matcher.(Fear.success(44))
      end.to raise_error(Fear::MatchError)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
fear-3.0.0 spec/fear/try/try_pattern_match_spec.rb