Skip to content
This repository has been archived by the owner on Oct 27, 2021. It is now read-only.

Commit

Permalink
Remove special case output to STDOUT
Browse files Browse the repository at this point in the history
The spec formatter checks that the output is a tty to decide whether to
use colourized formatting but then bypasses this check if STDOUT is used.
This means spec > output.log has undesirable escape sequences.  The only
purpose for this special casing seems to be preventing the closure of
STDOUT.  Localize this special case to #close so #output_to_tty? works
as expected.
  • Loading branch information
tpope authored and dchelimsky committed May 28, 2008
1 parent 4ce2b04 commit 3457a3a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
9 changes: 2 additions & 7 deletions lib/spec/runner/formatter/base_text_formatter.rb
Expand Up @@ -15,11 +15,6 @@ def initialize(options, where)
super
if where.is_a?(String)
@output = File.open(where, 'w')
elsif where == STDOUT
@output = Kernel
def @output.flush
STDOUT.flush
end
else
@output = where
end
Expand Down Expand Up @@ -81,7 +76,7 @@ def dump_pending
end

def close
if IO === @output
if IO === @output && @output != STDOUT
@output.close
end
end
Expand Down Expand Up @@ -112,7 +107,7 @@ def colour(text, colour_code)

def output_to_tty?
begin
@output == Kernel || @output.tty?
@output.tty?
rescue NoMethodError
false
end
Expand Down
20 changes: 20 additions & 0 deletions spec/spec/runner/formatter/story/plain_text_formatter_spec.rb
Expand Up @@ -320,6 +320,26 @@ module Story
@out.string.should include('When I say hey (SKIPPED)')
end

it "should use colour codes on a tty" do
@out.stub!(:tty?).and_return(true)
@options.stub!(:colour).and_return(true)

@formatter.scenario_started('','')
@formatter.step_succeeded(:given, 'a context')

@out.string.should =~ /\e/m
end

it "should not use colour codes on a non-tty" do
@out.stub!(:tty?).and_return(false)
@options.stub!(:colour).and_return(true)

@formatter.scenario_started('','')
@formatter.step_succeeded(:given, 'a context')

@out.string.should_not =~ /\e/m
end

it "should print steps which succeeded in green" do
@out.stub!(:tty?).and_return(true)
@options.stub!(:colour).and_return(true)
Expand Down

0 comments on commit 3457a3a

Please sign in to comment.