Ability to enumerate each result in report

This commit is contained in:
Michael Miller 2019-03-23 14:44:00 -06:00
parent 4d38bf3ab2
commit 4890cafefa
2 changed files with 20 additions and 0 deletions

View file

@ -44,6 +44,15 @@ describe Spectator::Report do
end
end
describe "#each" do
it "yields all results" do
results = new_results
report = Spectator::Report.new(results)
# The `#each` method is tested through `Enumerable#to_a`.
report.to_a.should eq(results)
end
end
describe "#runtime" do
it "is the expected value" do
span = Time::Span.new(10, 10, 10)

View file

@ -1,6 +1,10 @@
require "./result"
module Spectator
# Outcome of all tests in a suite.
class Report
include Enumerable(Result)
# Total length of time it took to execute the test suite.
# This includes examples, hooks, and framework processes.
getter runtime : Time::Span
@ -51,6 +55,13 @@ module Spectator
initialize(results, runtime)
end
# Yields each result in turn.
def each
@results.each do |result|
yield result
end
end
# Number of examples.
def example_count
@results.size