Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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