Sha256: 6e482f1a3fc4eb92a2c904e87b534603d6796118f46b017c353ef2da2ab28970

Contents?: true

Size: 897 Bytes

Versions: 1

Compression:

Stored size: 897 Bytes

Contents

RSpec.describe Fear::EitherPatternMatch do
  include Fear::Either::Mixin

  context 'Right' do
    let(:matcher) do
      described_class.new do |m|
        m.right(:even?) { |x| "#{x} is even" }
        m.right(:odd?) { |x| "#{x} is odd" }
      end
    end

    it do
      expect(matcher.call(Right(4))).to eq('4 is even')
      expect(matcher.call(Right(3))).to eq('3 is odd')
      expect do
        matcher.call(Left(44))
      end.to raise_error(Fear::MatchError)
    end
  end

  context 'Left' do
    let(:matcher) do
      described_class.new do |m|
        m.left(:even?) { |x| "#{x} is even" }
        m.left(:odd?) { |x| "#{x} is odd" }
      end
    end

    it do
      expect(matcher.call(Left(4))).to eq('4 is even')
      expect(matcher.call(Left(3))).to eq('3 is odd')
      expect do
        matcher.call(Right(44))
      end.to raise_error(Fear::MatchError)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
fear-0.11.0 spec/fear/either_pattern_match_spec.rb