Various fixes

This commit is contained in:
Michael Miller 2022-03-26 00:12:37 -06:00
parent bbaa8816b8
commit 1199379833
No known key found for this signature in database
GPG key ID: AC78B32D30CE34A2
3 changed files with 40 additions and 32 deletions

View file

@ -184,36 +184,36 @@ Spectator.describe Spectator::Double do
pp = PrettyPrint.new(io)
hasher = Crystal::Hasher.new
aggregate_failures do
expect { dbl.!=(42) }.to raise_error(Spectator::UnexpectedMessage)
expect { dbl.!~(42) }.to raise_error(Spectator::UnexpectedMessage)
expect { dbl.==(42) }.to raise_error(Spectator::UnexpectedMessage)
expect { dbl.===(42) }.to raise_error(Spectator::UnexpectedMessage)
expect { dbl.=~(42) }.to raise_error(Spectator::UnexpectedMessage)
expect { dbl.class }.to raise_error(Spectator::UnexpectedMessage)
expect { dbl.dup }.to raise_error(Spectator::UnexpectedMessage)
expect { dbl.hash(hasher) }.to raise_error(Spectator::UnexpectedMessage)
expect { dbl.hash }.to raise_error(Spectator::UnexpectedMessage)
expect { dbl.in?([42]) }.to raise_error(Spectator::UnexpectedMessage)
expect { dbl.in?(1, 2, 3) }.to raise_error(Spectator::UnexpectedMessage)
expect { dbl.inspect }.to raise_error(Spectator::UnexpectedMessage)
expect { dbl.itself }.to raise_error(Spectator::UnexpectedMessage)
expect { dbl.not_nil! }.to raise_error(Spectator::UnexpectedMessage)
expect { dbl.pretty_inspect }.to raise_error(Spectator::UnexpectedMessage)
# expect { dbl.pretty_inspect(io) }.to raise_error(Spectator::UnexpectedMessage)
expect { dbl.pretty_print(pp) }.to raise_error(Spectator::UnexpectedMessage)
expect { dbl.tap { nil } }.to raise_error(Spectator::UnexpectedMessage)
expect { dbl.to_json }.to raise_error(Spectator::UnexpectedMessage)
expect { dbl.to_json(io) }.to raise_error(Spectator::UnexpectedMessage)
expect { dbl.to_pretty_json }.to raise_error(Spectator::UnexpectedMessage)
expect { dbl.to_pretty_json(io) }.to raise_error(Spectator::UnexpectedMessage)
expect { dbl.to_s }.to raise_error(Spectator::UnexpectedMessage)
expect { dbl.to_s(io) }.to raise_error(Spectator::UnexpectedMessage)
expect { dbl.to_yaml }.to raise_error(Spectator::UnexpectedMessage)
expect { dbl.to_yaml(io) }.to raise_error(Spectator::UnexpectedMessage)
expect { dbl.try { nil } }.to raise_error(Spectator::UnexpectedMessage)
expect { dbl.object_id }.to raise_error(Spectator::UnexpectedMessage)
expect { dbl.same?(dbl) }.to raise_error(Spectator::UnexpectedMessage)
expect { dbl.same?(nil) }.to raise_error(Spectator::UnexpectedMessage)
expect(dbl.!=(42)).to be_true
expect(dbl.!~(42)).to be_true
expect(dbl.==(42)).to be_false
expect(dbl.===(42)).to be_false
expect(dbl.=~(42)).to be_false
expect(dbl.class).to be_nil
expect(dbl.dup).to eq(dbl)
expect(dbl.hash(hasher)).to eq(42)
expect(dbl.hash).to eq(42)
expect(dbl.in?([42])).to be_false
expect(dbl.in?(1, 2, 3)).to be_false
expect(dbl.inspect).to eq("foo")
expect(dbl.itself).to be(dbl)
expect(dbl.not_nil!).to be(dbl)
expect(dbl.pretty_inspect).to eq("foo")
# expect(dbl.pretty_inspect(io)).to be_nil
expect(dbl.pretty_print(pp)).to be_nil
expect(dbl.tap { nil }).to be(dbl)
expect(dbl.to_json).to eq("foo")
expect(dbl.to_json(io)).to be_nil
expect(dbl.to_pretty_json).to eq("foo")
expect(dbl.to_pretty_json(io)).to be_nil
expect(dbl.to_s).to eq("foo")
expect(dbl.to_s(io)).to be_nil
expect(dbl.to_yaml).to eq("foo")
expect(dbl.to_yaml(io)).to be_nil
expect(dbl.try { nil }).to be_nil
expect(dbl.object_id).to eq(42)
expect(dbl.same?(dbl)).to be_true
expect(dbl.same?(nil)).to be_false
end
end

View file

@ -62,7 +62,7 @@ Spectator.describe Spectator::NullDouble do
end
it "raises on non-matching arguments" do
expect { dbl.foo("bar") }.to raise_error(TypeCastError, /String/)
expect { dbl.foo("bar") }.to raise_error(Spectator::UnexpectedMessage, /foo/)
end
it "raises on non-matching stub" do

View file

@ -4,7 +4,6 @@ require "./stub"
require "./stubbable"
require "./stubbed_name"
require "./unexpected_message"
require "./value_stub"
module Spectator
# Stands in for an object for testing that a SUT calls expected methods.
@ -77,6 +76,15 @@ module Spectator
def initialize(@stubs : Array(Stub) = [] of Stub)
end
# Compares against another object.
#
# Always returns false.
# This method exists as a workaround to provide an alternative to `Object#same?`,
# which only accepts a `Reference` or `Nil`.
def same?(other) : Bool
false
end
# Defines a stub to change the behavior of a method in this double.
#
# NOTE: Defining a stub for a method not defined in the double's type has no effect.