Change Anything to only use case equality

This commit is contained in:
Michael Miller 2021-02-09 21:18:20 -07:00
parent f46856f307
commit 7a5f7adfc2
No known key found for this signature in database
GPG key ID: FB9F12F7C646A4AD
2 changed files with 1 additions and 37 deletions

View file

@ -1,15 +1,6 @@
require "../spec_helper"
Spectator.describe Spectator::Anything do
it "equals everything" do
expect(true).to eq(subject)
expect(false).to eq(subject)
expect(nil).to eq(subject)
expect(42).to eq(subject)
expect(42.as(Int32 | String)).to eq(subject)
expect(["foo", "bar"]).to eq(subject)
end
it "matches everything" do
expect(true).to match(subject)
expect(false).to match(subject)
@ -19,22 +10,6 @@ Spectator.describe Spectator::Anything do
expect(["foo", "bar"]).to match(subject)
end
context "nested in a container" do
it "equals everything" do
expect(["foo", "bar"]).to eq(["foo", subject])
expect({"foo", "bar"}).to eq({"foo", subject})
expect({foo: "bar"}).to eq({foo: subject})
expect({"foo" => "bar"}).to eq({"foo" => subject})
end
it "matches everything" do
expect(["foo", "bar"]).to match(["foo", subject])
expect({"foo", "bar"}).to match({"foo", subject})
expect({foo: "bar"}).to match({foo: subject})
expect({"foo" => "bar"}).to match({"foo" => subject})
end
end
describe "#to_s" do
subject { super.to_s }

View file

@ -4,25 +4,14 @@ module Spectator
# Can be used like so:
# ```
# anything = Spectator::Anything.new
# array = ["foo", anything]
# expect(["foo", "bar"]).to eq(array)
# expect("foo").to match(anything)
# ```
struct Anything
# Always returns true.
def ==(other)
true
end
# Always returns true.
def ===(other)
true
end
# Always returns true.
def =~(other)
true
end
# Displays "anything".
def to_s(io)
io << "anything"