Skip to content

Commit

Permalink
Move pattern match tests from unit to integration specs
Browse files Browse the repository at this point in the history
  • Loading branch information
alexkalderimis committed Jul 23, 2024
1 parent 8bf9753 commit 2f35d4c
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 8 deletions.
51 changes: 51 additions & 0 deletions spec/integration/pattern_matching_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,57 @@
# frozen_string_literal: true

RSpec.describe "pattern matching" do
describe "Dry::Monads::Try" do
include Dry::Monads[:try]

context "Value" do
it "matches on the singleton array of the value when value is not an array" do
expect(
(Value(1) in [1])
).to be(true)
end

it "matches on the value when value is an array" do
expect(
(Value([1]) in [1])
).to be(true)
end

it "matches on the empty array when value is Unit" do
expect(
(Value(Dry::Monads::Unit) in [])
).to be(true)
end

it "matches on the value's keys when value acts like a hash" do
expect(
(Value({code: 101, foo: :bar}) in { code: 101 })
).to be(true)
end

it "matches on the empty hash when value doesn't act like a hash" do
expect(
(Value(:foo) in {})
).to be(true)
end
end

context "Error" do
it "matches on the singleton array of the exception" do
exception = StandardError.new("boom")
failure = Try { raise exception }

expect(
(failure in [exception])
).to be(true)

expect(
(failure in Dry::Monads::Try::Error(exception))
).to be(true)
end
end
end

describe "Dry::Monads::Result" do
include Dry::Monads[:result]

Expand Down
8 changes: 0 additions & 8 deletions spec/unit/try_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,6 @@
it { is_expected.to eql(described_class.new([ZeroDivisionError], "foo")) }
it { is_expected.not_to eql(error[division_error]) }

it "deconstructs to the value" do
expect(subject.deconstruct).to eq ["foo"]
end

it "dumps to string" do
expect(subject.to_s).to eql('Try::Value("foo")')
expect(value[[], unit].to_s).to eql("Try::Value()")
Expand Down Expand Up @@ -214,10 +210,6 @@
let(:upcase_value) { described_class.new([ZeroDivisionError], "FOO") }
let(:upcase_error) { try::Error.new(division_error) }

it "deconstructs to the exception" do
expect(subject.deconstruct).to eq [division_error]
end

describe ".call" do
it "is an alias for new" do
expect(try::Error.(division_error)).to eql(subject)
Expand Down

0 comments on commit 2f35d4c

Please sign in to comment.