Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions lib/sus/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -168,11 +168,14 @@ def print_summary(output, assertions)

print_finished_statistics(output, assertions)

if !partial? and assertions.passed?
print_test_feedback(output, assertions)
unless assertions.count.zero?
if !partial? and assertions.passed?
print_test_feedback(output, assertions)
end

print_slow_tests(output, assertions)
end

print_slow_tests(output, assertions)
print_failed_assertions(output, assertions)
end

Expand All @@ -181,9 +184,13 @@ def print_summary(output, assertions)
# @parameter assertions [Assertions] The assertions instance.
def print_finished_statistics(output, assertions)
duration = @clock.duration
rate = assertions.count / duration

output.puts "🏁 Finished in ", @clock, "; #{rate.round(3)} assertions per second."
if assertions.count.zero?
output.puts "🏴 Finished in ", @clock, "."
else
rate = assertions.count / duration
output.puts "🏁 Finished in ", @clock, "; #{rate.round(3)} assertions per second."
end
end

# Print feedback about the test suite.
Expand Down
53 changes: 53 additions & 0 deletions test/sus/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@

require "fixtures"

class Target
def print(output)
output.write("target")
end
end

describe Sus::Config do
include Fixtures

Expand All @@ -14,4 +20,51 @@
it "can load config from file" do
expect(config).not.to be(:nil?)
end

with "summary output" do
let(:io) {StringIO.new}
let(:output) {Sus::Output::Text.new(io)}
let(:assertions) {Sus::Assertions.new(output: Sus::Output.buffered)}

with "errors and no assertions" do
it "suppresses laudatory output but prints timing" do
assertions.nested(Target.new, isolated: true) do |nested|
nested.error!(RuntimeError.new("load error"))
end

config.before_tests(assertions, output: output)
config.after_tests(assertions, output: output)

expect(io.string).to be(:include?, "🏴 Finished in")
expect(io.string).not.to be(:include?, "assertions per second")
expect(io.string).not.to be(:include?, "No slow tests found")
expect(io.string).to be(:include?, "Errored assertions")
end
end

with "no assertions and no errors" do
it "suppresses laudatory output but prints timing" do
config.before_tests(assertions, output: output)
config.after_tests(assertions, output: output)

expect(io.string).to be(:include?, "🏴 Finished in")
expect(io.string).not.to be(:include?, "assertions per second")
expect(io.string).not.to be(:include?, "No slow tests found")
end
end

with "passing assertions" do
it "prints statistics and slow test output" do
assertions.nested(Target.new, isolated: true, measure: true) do |nested|
nested.assert(true)
end

config.before_tests(assertions, output: output)
config.after_tests(assertions, output: output)

expect(io.string).to be(:include?, "Finished in")
expect(io.string).to be(:include?, "No slow tests found")
end
end
end
end
Loading