Sha256: 7a5cfde54c6c690b37b03faf230fe6800a3c392907a0ece89b1a3d39bd918189
Contents?: true
Size: 1.01 KB
Versions: 4
Compression:
Stored size: 1.01 KB
Contents
# frozen_string_literal: true RSpec.describe Fear::TryPatternMatch 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
4 entries across 4 versions & 1 rubygems