mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Use shorter string when stub is treated as a message
This commit is contained in:
parent
e2cdc9e08e
commit
318e4eba89
3 changed files with 26 additions and 14 deletions
|
@ -296,7 +296,7 @@ Spectator.describe Spectator::Matchers::ReceiveMatcher do
|
|||
end
|
||||
|
||||
it "has the expected call listed" do
|
||||
is_expected.to contain({:expected, "Not #{stub}"})
|
||||
is_expected.to contain({:expected, "Not #{stub.message}"})
|
||||
end
|
||||
|
||||
it "has the list of called methods" do
|
||||
|
|
|
@ -81,7 +81,7 @@ module Spectator::Matchers
|
|||
|
||||
# Short text about the matcher's purpose.
|
||||
def description : String
|
||||
"received #{@stub} #{humanize_count}"
|
||||
"received #{@stub.message} #{humanize_count}"
|
||||
end
|
||||
|
||||
# Actually performs the test against the expression (value or block).
|
||||
|
@ -89,10 +89,10 @@ module Spectator::Matchers
|
|||
stubbed = actual.value
|
||||
calls = relevant_calls(stubbed)
|
||||
if @count.includes?(calls.size)
|
||||
SuccessfulMatchData.new("#{actual.label} received #{@stub} #{humanize_count}")
|
||||
SuccessfulMatchData.new("#{actual.label} received #{@stub.message} #{humanize_count}")
|
||||
else
|
||||
FailedMatchData.new("#{actual.label} received #{@stub} #{humanize_count}",
|
||||
"#{actual.label} did not receive #{@stub}", values(actual).to_a)
|
||||
FailedMatchData.new("#{actual.label} received #{@stub.message} #{humanize_count}",
|
||||
"#{actual.label} did not receive #{@stub.message}", values(actual).to_a)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -106,9 +106,9 @@ module Spectator::Matchers
|
|||
stubbed = actual.value
|
||||
calls = relevant_calls(stubbed)
|
||||
if @count.includes?(calls.size)
|
||||
FailedMatchData.new("#{actual.label} did not receive #{@stub}", "#{actual.label} received #{@stub}", negated_values(actual).to_a)
|
||||
FailedMatchData.new("#{actual.label} did not receive #{@stub.message}", "#{actual.label} received #{@stub.message}", negated_values(actual).to_a)
|
||||
else
|
||||
SuccessfulMatchData.new("#{actual.label} did not receive #{@stub} #{humanize_count}")
|
||||
SuccessfulMatchData.new("#{actual.label} did not receive #{@stub.message} #{humanize_count}")
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -120,7 +120,7 @@ module Spectator::Matchers
|
|||
# Additional information about the match failure.
|
||||
private def values(actual : Expression(T)) forall T
|
||||
{
|
||||
expected: @stub.to_s,
|
||||
expected: @stub.message,
|
||||
actual: method_call_list(actual.value),
|
||||
}
|
||||
end
|
||||
|
@ -128,7 +128,7 @@ module Spectator::Matchers
|
|||
# Additional information about the match failure when negated.
|
||||
private def negated_values(actual : Expression(T)) forall T
|
||||
{
|
||||
expected: "Not #{@stub}",
|
||||
expected: "Not #{@stub.message}",
|
||||
actual: method_call_list(actual.value),
|
||||
}
|
||||
end
|
||||
|
|
|
@ -22,6 +22,23 @@ module Spectator
|
|||
def initialize(@method : Symbol, @constraint : AbstractArguments? = nil, @location : Location? = nil)
|
||||
end
|
||||
|
||||
# String representation of the stub, formatted as a method call.
|
||||
def message(io : IO) : Nil
|
||||
io << "#" << method << (constraint || "(any args)")
|
||||
end
|
||||
|
||||
# String representation of the stub, formatted as a method call.
|
||||
def message
|
||||
String.build do |str|
|
||||
message(str)
|
||||
end
|
||||
end
|
||||
|
||||
# String representation of the stub, formatted as a method definition.
|
||||
def to_s(io : IO) : Nil
|
||||
message(io)
|
||||
end
|
||||
|
||||
# Checks if a method call should receive the response from this stub.
|
||||
def ===(call : MethodCall)
|
||||
return false if method != call.method
|
||||
|
@ -29,10 +46,5 @@ 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
|
||||
|
|
Loading…
Reference in a new issue