Sha256: 0b79f35ea6b9cdb1e7da5eba580aa5a9050d1df766059a310c6f7b9f51ac7abb

Contents?: true

Size: 779 Bytes

Versions: 4

Compression:

Stored size: 779 Bytes

Contents

# frozen_string_literal: true

RSpec.describe Fear::OptionPatternMatch do
  context "Some" do
    let(:matcher) do
      described_class.new do |m|
        m.some(:even?.to_proc) { |x| "#{x} is even" }
        m.some(:odd?.to_proc) { |x| "#{x} is odd" }
      end
    end

    it do
      expect(matcher.(Fear.some(4))).to eq("4 is even")
      expect(matcher.(Fear.some(3))).to eq("3 is odd")
      expect do
        matcher.(Fear.none)
      end.to raise_error(Fear::MatchError)
    end
  end

  context "None" do
    let(:matcher) do
      described_class.new do |m|
        m.none { "nil" }
      end
    end

    it do
      expect(matcher.(Fear.none)).to eq("nil")
      expect do
        matcher.(Fear.some(3))
      end.to raise_error(Fear::MatchError)
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
fear-2.0.1 spec/fear/option_pattern_match_spec.rb
fear-2.0.0 spec/fear/option_pattern_match_spec.rb
fear-1.2.0 spec/fear/option_pattern_match_spec.rb
fear-1.1.0 spec/fear/option_pattern_match_spec.rb