Sha256: 7245ffb3e61e681067644ef3e65952e200a468ed1cf801b7febc864982207a0e
Contents?: true
Size: 1.37 KB
Versions: 1
Compression:
Stored size: 1.37 KB
Contents
require "dry-monads" require "dry/matcher/result_matcher" RSpec.describe "Class enhancement with Dry::Matcher.for" do let(:operation) { Class.new do include Dry::Matcher.for(:call, with: Dry::Matcher::ResultMatcher) def call(bool) bool ? Dry::Monads::Success("a success") : Dry::Monads::Failure("a failure") end end.new } describe "match blocks" do subject(:match) { operation.call(input) do |m| m.success do |v| "Matched success: #{v}" end m.failure do |v| "Matched failure: #{v}" end end } context "successful result" do let(:input) { true } it "matches on success" do expect(match).to eq "Matched success: a success" end end context "failed result" do let(:input) { false } it "matches on failure" do expect(match).to eq "Matched failure: a failure" end end end describe "without match blocks" do subject(:result) { operation.call(input) } context "successful result" do let(:input) { true } it "returns the result" do expect(result).to eq Dry::Monads::Success("a success") end end context "failed result" do let(:input) { false } it "returns the result" do expect(result).to eq Dry::Monads::Failure("a failure") end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
dry-matcher-0.7.0 | spec/integration/class_enhancement_spec.rb |