mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Support label for aggregate_failures block
This commit is contained in:
parent
4c125d98d4
commit
f53ffabf6b
3 changed files with 17 additions and 6 deletions
|
@ -28,5 +28,14 @@ Spectator.describe Spectator do
|
|||
end
|
||||
end.to_not raise_error(Spectator::ExpectationFailed)
|
||||
end
|
||||
|
||||
it "supports naming the block" do
|
||||
expect do
|
||||
aggregate_failures "contradiction" do
|
||||
expect(true).to be_false
|
||||
expect(false).to be_true
|
||||
end
|
||||
end.to raise_error(Spectator::MultipleExpectationsFailed, /contradiction/)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -172,8 +172,8 @@ module Spectator::DSL
|
|||
# expect(false).to be_true
|
||||
# end
|
||||
# ```
|
||||
def aggregate_failures
|
||||
::Spectator::Harness.current.aggregate_failures do
|
||||
def aggregate_failures(label = nil)
|
||||
::Spectator::Harness.current.aggregate_failures(label) do
|
||||
yield
|
||||
end
|
||||
end
|
||||
|
|
|
@ -100,20 +100,20 @@ module Spectator
|
|||
@deferred << block
|
||||
end
|
||||
|
||||
def aggregate_failures
|
||||
def aggregate_failures(label = nil)
|
||||
previous = @aggregate
|
||||
@aggregate = aggregate = [] of Expectation
|
||||
begin
|
||||
yield.tap do
|
||||
# If there's an nested aggregate (for some reason), allow the top-level one to handle things.
|
||||
check_aggregate(aggregate) unless previous
|
||||
check_aggregate(aggregate, label) unless previous
|
||||
end
|
||||
ensure
|
||||
@aggregate = previous
|
||||
end
|
||||
end
|
||||
|
||||
private def check_aggregate(aggregate)
|
||||
private def check_aggregate(aggregate, label)
|
||||
failures = aggregate.select(&.failed?)
|
||||
case failures.size
|
||||
when 0 then return
|
||||
|
@ -121,7 +121,9 @@ module Spectator
|
|||
expectation = failures.first
|
||||
raise ExpectationFailed.new(expectation, expectation.failure_message)
|
||||
else
|
||||
raise MultipleExpectationsFailed.new(failures, "Got #{failures.size} failures from failure aggregation block")
|
||||
message = "Got #{failures.size} failures from failure aggregation block"
|
||||
message += " \"#{label}\"" if label
|
||||
raise MultipleExpectationsFailed.new(failures, message)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue