Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ruby RSpec : No color on output with a Mac

Tags:

ruby

rspec

Developing with my first Mac and I noticed that my Rspec output isn't colorized in my terminal even though I'm using the '-c' flag in the command: bundle exec rspec -c -fd. Any ideas?

like image 347
steve_gallagher Avatar asked Feb 13 '12 17:02

steve_gallagher


3 Answers

Add the following contents to a .rspec file to your project dir root.

--color

like image 185
Jens Tinfors Avatar answered Sep 24 '22 12:09

Jens Tinfors


If you're coming here from Google recently, you may notice that Allen Chun's answer gives a NoMethodError with .color_enabled when using RSpec 3.0 or higher. .color_enabled was removed in 3.0: https://github.com/rspec/rspec-core/blob/master/Changelog.md#300rc1--2014-05-18

Just change .color_enabled to .color in spec_helper.rb:

RSpec.configure do |config|
  # Use color in STDOUT
  config.color = true

  # other config options here...    

end

This worked for me with Ruby 2.1.2p95 on OS X Mavericks 10.9.4.

like image 30
flanger001 Avatar answered Sep 25 '22 12:09

flanger001


You can also put the config on the spec_helper.rb if you don't want to attach --color every time you run rspec.

RSpec.configure do |config|
 # Use color in STDOUT
   config.color_enabled = true

 # Use color not only in STDOUT but also in pagers and files
   config.tty = true

 # Use the specified formatter
   config.formatter = :documentation # :progress, :html, :textmate
end
like image 40
AllenC Avatar answered Sep 24 '22 12:09

AllenC