Rspec-core: How can you force color without tty?

Created on 25 Aug 2012  ·  3Comments  ·  Source: rspec/rspec-core

I'm running rspec manually (without the rspec command), and I want to set the color configuration to true.

I've tried:

RSpec.configure do |c|
  c.tty = true
  c.color = true
end

p RSpec.configuration.tty? # => true
p RSpec.configuration.color? # => false

And as you can see that doesn't work.

Looking at the output_to_tty? method:

def output_to_tty?
  begin
    output_stream.tty? || tty?
  rescue NoMethodError
    false
  end
end

I'm guessing that it's throwing NoMethodError on output_stream.tty? and returning false - therefore, color can't be enabled, since the color option depends on this method returning true.

So how can I (with code), force the color configuration to true?

Most helpful comment

I found that --color --tty made this work for me. My tests are running in a headless continuous integration system which isn't writing to a TTY, but the CI system can capture the colored output and render it appropriately in a web browser, so we wanted to use color if possible.

All 3 comments

RSpec.configure do |c|
  def c.color; true; end
end

Admittedly a hack, but that's OK since you're using RSpec in a way for which it is not really designed.

This works great - thank you for supporting me with this.

I found that --color --tty made this work for me. My tests are running in a headless continuous integration system which isn't writing to a TTY, but the CI system can capture the colored output and render it appropriately in a web browser, so we wanted to use color if possible.

Was this page helpful?
0 / 5 - 0 ratings