Sha256: 54ec7a76e4b0be3e1edb15376c69dcc9f5041cc4a033c29e4bf20dda06949923
Contents?: true
Size: 1.32 KB
Versions: 2
Compression:
Stored size: 1.32 KB
Contents
require "dry-monads" require "dry/matcher/either_matcher" RSpec.describe "Dry::Matcher::EitherMatcher" do describe "external matching" do subject(:match) { Dry::Matcher::EitherMatcher.(result) do |m| m.success do |v| "Matched success: #{v}" end m.failure do |v| "Matched failure: #{v}" end end } context "successful result" do let(:result) { Dry::Monads::Right("a success") } it "matches on success" do expect(match).to eq "Matched success: a success" end end context "failed result" do let(:result) { Dry::Monads::Left("a failure") } it "matches on failure" do expect(match).to eq "Matched failure: a failure" end end context "result convertible to either" do context "converts to success" do let(:result) { Dry::Monads::Try.lift([StandardError], -> { 'a success' }) } it "matches on success" do expect(match).to eq "Matched success: a success" end end context "converts to failure" do let(:result) { Dry::Monads::Try.lift([StandardError], -> { raise('a failure') }) } it "matches on failure" do expect(match).to eq "Matched failure: a failure" end end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
dry-matcher-0.6.0 | spec/integration/either_matcher_spec.rb |
dry-matcher-0.5.0 | spec/integration/either_matcher_spec.rb |