module Test
VERSION = "0.1.0"
class Divisible
def initialize(@div : Int32)
end
def ===(other : Int32)
(other % @div) == 0
end
end
end
require "./spec_helper"
require "../src/test"
Spectator.describe Test::Divisible do
let(i) { 3 }
subject { described_class.new(i) }
describe "#===" do
it "must call === and compare the other object" do
expect(subject).to be === 6
end
end
end
Output
$ shards install
Resolving dependencies
Fetching https://gitlab.com/arctic-fox/spectator.git
Using spectator (0.9.36)
$ crystal spec
Test::Divisible
#===
must call === and compare the other object
Failures:
1) Test::Divisible#=== must call === and compare the other object
Failure: subject does not equal 6
actual: #<Test::Divisible:0x7f2fbab6abd0 @div=3>
expected: 6
# spec/test_spec.cr:9
Finished in 341 microseconds
1 examples, 1 failures, 0 errors, 0 pending
Workaround
However, if we explicitly call subject#=== within expect(), it works:
it "must call === and compare the other object" do
expect(subject === 6).to be(true)
end
$ crystal spec
Test::Divisible
#===
must call === and compare the other object
Finished in 104 microseconds
1 examples, 0 failures, 0 errors, 0 pending
Looks like Spectator is missing some be variants that RSpec has. The docs don't show be ===, but the code does. I'll look into getting this added soon.
Ran into this when testing custom
#===
methods.Example Code
Output
Workaround
However, if we explicitly call
subject#===
withinexpect()
, it works: