RSpec. How to colorize streamed or redirected output?

In versions of RSpec prior to 2.0, I could pass the color output to a smaller one or redirect it to a file. To do this, I just need to set the RSPEC_COLOR environment variable to true. However, in the new main version of the frame, this variable stopped to determine the type of output (color or monochrome). Is there a way to transfer or redirect color in RSpec 2.0 and higher?

Thank.

Debian GNU / Linux 5.0.7

Ruby 1.9.2;

RSpec 2.4.0.

Update


I found the answer myself.

To achieve the effect, use the configuration parameter tty.

Here is an example:

# spec/spec_helper.rb

RSpec.configure do |config|
  config.tty = true
end
+5
source share
3 answers

, , color_enabled RSpec. , tty, .

, color_enabled = true RSpec, , tty:

module RSpec   
  module Core
    class Configuration
      def color_enabled
        true
      end
    end
  end
end

. , , rspec - , .

, force_color_enabled? , ...

!

+1

:

# spec/spec_helper.rb

RSpec.configure do |config|
  config.color_enabled = true
end
+1

:

# spec/spec_helper.rb

RSpec.configure do |config|
  config.tty = true
end

rspec | grep --color="never" something .

+1

All Articles