Skip to content

Commit

Permalink
merged elizabrock-master and added to comments about silencing output
Browse files Browse the repository at this point in the history
  • Loading branch information
nickmerwin committed Sep 18, 2013
2 parents 84dfc19 + 4711b7f commit 517dd47
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 7 deletions.
4 changes: 2 additions & 2 deletions lib/coveralls/command.rb
Expand Up @@ -39,7 +39,7 @@ def last

desc "version", "See version"
def version
puts Coveralls::VERSION
Coveralls::Output.puts Coveralls::VERSION
end

private
Expand All @@ -50,7 +50,7 @@ def open_token_based_url url
url = url.gsub("%@", config[:repo_token])
`open #{url}`
else
puts "No repo_token configured."
Coveralls::Output.puts "No repo_token configured."
end
end

Expand Down
17 changes: 16 additions & 1 deletion lib/coveralls/output.rb
Expand Up @@ -18,16 +18,25 @@ module Coveralls
# Coveralls::Output.puts("Hello World", :color => "underline")
# # Hello World
# # => nil
#
# To silence output completely:
#
# Coveralls::Output.silent = true
#
# or set this environment variable:
#
# COVERALLS_SILENT

module Output
require 'term/ansicolor'
attr_accessor :silent
attr_writer :output
extend self

def output
(defined?(@output) && @output) || $stdout
end


# Public: Formats the given string with the specified color
# through Term::ANSIColor
#
Expand Down Expand Up @@ -64,6 +73,7 @@ def format(string, options = {})
#
# Returns nil.
def puts(string, options = {})
return if silent?
(options[:output] || output).puts self.format(string, options)
end

Expand All @@ -80,7 +90,12 @@ def puts(string, options = {})
#
# Returns nil.
def print(string, options = {})
return if silent?
(options[:output] || output).print self.format(string, options)
end

def silent?
ENV["COVERALLS_SILENT"] || (defined?(@silent) && @silent)
end
end
end
8 changes: 4 additions & 4 deletions lib/coveralls/simplecov.rb
Expand Up @@ -5,12 +5,12 @@ class Formatter
def display_result(result)
# Log which files would be submitted.
if result.files.length > 0
puts "[Coveralls] Some handy coverage stats:"
Coveralls::Output.puts "[Coveralls] Some handy coverage stats:"
else
Coveralls::Output.puts "[Coveralls] There are no covered files.", :color => "yellow"
end
result.files.each do |f|
print " * "
Coveralls::Output.print " * "
Coveralls::Output.print short_filename(f.filename).to_s, :color => "cyan"
Coveralls::Output.print " => ", :color => "white"
cov = "#{f.covered_percent.round}%"
Expand All @@ -21,7 +21,7 @@ def display_result(result)
else
Coveralls::Output.print cov, :color => "red"
end
puts ""
Coveralls::Output.puts ""
end
true
end
Expand Down Expand Up @@ -70,7 +70,7 @@ def format(result)

# Post to Coveralls.
API.post_json "jobs", {:source_files => source_files, :test_framework => result.command_name.downcase, :run_at => result.created_at}
puts output_message result
Coveralls::Output.puts output_message result

true

Expand Down
22 changes: 22 additions & 0 deletions spec/coveralls/output_spec.rb
Expand Up @@ -33,6 +33,28 @@
end
end

describe 'when silenced' do
before do
@original_stdout = $stdout
@output = StringIO.new
Coveralls::Output.silent = true
$stdout = @output
end
it "should not puts" do
Coveralls::Output.puts "foo"
@output.rewind
@output.read.should == ""
end
it "should not print" do
Coveralls::Output.print "foo"
@output.rewind
@output.read.should == ""
end
after do
$stdout = @original_stdout
end
end

describe '.format' do
it "accepts a color argument" do
string = 'Hello'
Expand Down

0 comments on commit 517dd47

Please sign in to comment.