Skip to content

Commit ba3f8f0

Browse files
committed
Add silent option to suppress console output
Usage: SimpleCov::Formatter::HTMLFormatter.new(silent: true) Closes #116.
1 parent 969a771 commit ba3f8f0

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

lib/simplecov-html.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,13 @@ class HTMLFormatter
2222
".css" => "text/css",
2323
}.freeze
2424

25-
def initialize
25+
def initialize(silent: false)
2626
@branch_coverage = SimpleCov.branch_coverage?
2727
@method_coverage = SimpleCov.method_coverage?
2828
@templates = {}
2929
@inline_assets = !ENV["SIMPLECOV_INLINE_ASSETS"].nil?
3030
@public_assets_dir = File.join(File.dirname(__FILE__), "../public/")
31+
@silent = silent
3132
end
3233

3334
def format(result)
@@ -40,7 +41,7 @@ def format(result)
4041
File.open(File.join(output_path, "index.html"), "wb") do |file|
4142
file.puts template("layout").result(binding)
4243
end
43-
puts output_message(result)
44+
puts output_message(result) unless @silent
4445
end
4546

4647
private

test/test_simple_cov-html.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,14 @@ def bad_template.result(_binding)
8989
assert_match(/Encoding problems with file/, output)
9090
end
9191

92+
def test_silenced_output
93+
result = SimpleCov::Result.new({fixtures_path.join("sample.rb").to_s => CoverageFixtures::SAMPLE_RB})
94+
formatter = SimpleCov::Formatter::HTMLFormatter.new(silent: true)
95+
stdout, = capture_io { formatter.format(result) }
96+
97+
assert_empty stdout
98+
end
99+
92100
def test_strength_css_classes
93101
formatter = SimpleCov::Formatter::HTMLFormatter.new
94102

0 commit comments

Comments
 (0)