Skip to content

Commit

Permalink
Fix Expectations::Be for module type (#14926)
Browse files Browse the repository at this point in the history
  • Loading branch information
straight-shoota authored Aug 22, 2024
1 parent bb75d3b commit 0f906a4
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
23 changes: 23 additions & 0 deletions spec/std/spec/expectations_spec.cr
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
require "spec"

private module MyModule; end

private class Foo
include MyModule
end

private record NoObjectId, to_unsafe : Int32 do
def same?(other : self) : Bool
to_unsafe == other.to_unsafe
end
end

describe "expectations" do
describe "accept a custom failure message" do
it { 1.should be < 3, "custom message!" }
Expand All @@ -25,6 +37,17 @@ describe "expectations" do
array = [1]
array.should_not be [1]
end

it "works with type that does not implement `#object_id`" do
a = NoObjectId.new(1)
a.should be a
a.should_not be NoObjectId.new(2)
end

it "works with module type (#14920)" do
a = Foo.new
a.as(MyModule).should be a.as(MyModule)
end
end

describe "be_a" do
Expand Down
10 changes: 6 additions & 4 deletions src/spec/expectations.cr
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,13 @@ module Spec
end

private def identify(value)
if value.responds_to?(:object_id)
"object_id: #{value.object_id}"
else
value.to_unsafe
if value.responds_to?(:to_unsafe)
if !value.responds_to?(:object_id)
return value.to_unsafe
end
end

"object_id: #{value.object_id}"
end
end

Expand Down

0 comments on commit 0f906a4

Please sign in to comment.