Skip to content

Commit ce34d7c

Browse files
authored
Suppress laudatory summary output when no assertions are executed. (#46)
1 parent 5f19f03 commit ce34d7c

File tree

2 files changed

+65
-5
lines changed

2 files changed

+65
-5
lines changed

lib/sus/config.rb

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -168,11 +168,14 @@ def print_summary(output, assertions)
168168

169169
print_finished_statistics(output, assertions)
170170

171-
if !partial? and assertions.passed?
172-
print_test_feedback(output, assertions)
171+
unless assertions.count.zero?
172+
if !partial? and assertions.passed?
173+
print_test_feedback(output, assertions)
174+
end
175+
176+
print_slow_tests(output, assertions)
173177
end
174178

175-
print_slow_tests(output, assertions)
176179
print_failed_assertions(output, assertions)
177180
end
178181

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

186-
output.puts "🏁 Finished in ", @clock, "; #{rate.round(3)} assertions per second."
188+
if assertions.count.zero?
189+
output.puts "🏴 Finished in ", @clock, "."
190+
else
191+
rate = assertions.count / duration
192+
output.puts "🏁 Finished in ", @clock, "; #{rate.round(3)} assertions per second."
193+
end
187194
end
188195

189196
# Print feedback about the test suite.

test/sus/config.rb

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@
55

66
require "fixtures"
77

8+
class Target
9+
def print(output)
10+
output.write("target")
11+
end
12+
end
13+
814
describe Sus::Config do
915
include Fixtures
1016

@@ -14,4 +20,51 @@
1420
it "can load config from file" do
1521
expect(config).not.to be(:nil?)
1622
end
23+
24+
with "summary output" do
25+
let(:io) {StringIO.new}
26+
let(:output) {Sus::Output::Text.new(io)}
27+
let(:assertions) {Sus::Assertions.new(output: Sus::Output.buffered)}
28+
29+
with "errors and no assertions" do
30+
it "suppresses laudatory output but prints timing" do
31+
assertions.nested(Target.new, isolated: true) do |nested|
32+
nested.error!(RuntimeError.new("load error"))
33+
end
34+
35+
config.before_tests(assertions, output: output)
36+
config.after_tests(assertions, output: output)
37+
38+
expect(io.string).to be(:include?, "🏴 Finished in")
39+
expect(io.string).not.to be(:include?, "assertions per second")
40+
expect(io.string).not.to be(:include?, "No slow tests found")
41+
expect(io.string).to be(:include?, "Errored assertions")
42+
end
43+
end
44+
45+
with "no assertions and no errors" do
46+
it "suppresses laudatory output but prints timing" do
47+
config.before_tests(assertions, output: output)
48+
config.after_tests(assertions, output: output)
49+
50+
expect(io.string).to be(:include?, "🏴 Finished in")
51+
expect(io.string).not.to be(:include?, "assertions per second")
52+
expect(io.string).not.to be(:include?, "No slow tests found")
53+
end
54+
end
55+
56+
with "passing assertions" do
57+
it "prints statistics and slow test output" do
58+
assertions.nested(Target.new, isolated: true, measure: true) do |nested|
59+
nested.assert(true)
60+
end
61+
62+
config.before_tests(assertions, output: output)
63+
config.after_tests(assertions, output: output)
64+
65+
expect(io.string).to be(:include?, "Finished in")
66+
expect(io.string).to be(:include?, "No slow tests found")
67+
end
68+
end
69+
end
1770
end

0 commit comments

Comments
 (0)