Pretify stub and call output

Fix some tests.
This commit is contained in:
Michael Miller 2022-07-12 17:47:05 -06:00
parent 36cc035417
commit d7ea969f55
No known key found for this signature in database
GPG key ID: 32B47AE8F388A1FF
3 changed files with 29 additions and 15 deletions

View file

@ -30,6 +30,12 @@ Spectator.describe Spectator::Matchers::ReceiveMatcher do
is_expected.to contain("test_method")
end
context "without an argument constraint" do
it "mentions it accepts any arguments" do
is_expected.to contain("any args")
end
end
context "with no arguments" do
let(matcher) { no_args_matcher }
@ -42,7 +48,7 @@ Spectator.describe Spectator::Matchers::ReceiveMatcher do
let(matcher) { args_matcher }
it "lists the arguments" do
is_expected.to contain("1, \"test\", Symbol, foo: #{/bar/}")
is_expected.to contain("1, \"test\", Symbol, foo: #{/bar/.inspect}")
end
end
end
@ -146,17 +152,17 @@ Spectator.describe Spectator::Matchers::ReceiveMatcher do
end
it "has the expected call listed" do
is_expected.to contain({:expected, stub.to_s})
is_expected.to contain({:expected, "#test_method(1, \"test\", Symbol, foo: #{/bar/.inspect})"})
end
it "has the list of called methods" do
is_expected.to contain({
:actual,
[
"test_method(no args)",
"test_method(1, \"test\", :xyz, foo: \"foobarbaz\"",
"irrelevant(\"foo\")",
],
<<-SIGNATURES
#test_method(no args)
#test_method(1, "wrong", :xyz, foo: "foobarbaz")
#irrelevant("foo")
SIGNATURES
})
end
end
@ -249,17 +255,17 @@ Spectator.describe Spectator::Matchers::ReceiveMatcher do
end
it "has the expected call listed" do
is_expected.to contain({:expected, stub.to_s})
is_expected.to contain({:expected, "Not #{stub}"})
end
it "has the list of called methods" do
is_expected.to contain({
:actual,
[
"test_method(no args)",
"test_method(1, \"test\", :xyz, foo: \"foobarbaz\"",
"irrelevant(\"foo\")",
],
<<-SIGNATURES
#test_method(no args)
#test_method(1, "test", :xyz, foo: "foobarbaz")
#irrelevant("foo")
SIGNATURES
})
end
end

View file

@ -71,13 +71,16 @@ module Spectator::Matchers
private def values(actual : Expression(T)) forall T
{
expected: @stub.to_s,
actual: actual.value._spectator_calls.inspect,
actual: actual.value._spectator_calls.join("\n"),
}
end
# Additional information about the match failure when negated.
private def negated_values(actual : Expression(T)) forall T
values(actual)
{
expected: "Not #{@stub}",
actual: actual.value._spectator_calls.join("\n"),
}
end
end
end

View file

@ -29,5 +29,10 @@ module Spectator
constraint === call.arguments
end
# String representation of the stub, formatted as a method call.
def to_s(io : IO) : Nil
io << "#" << method << (constraint || "(any args)")
end
end
end