2012-02-13 26 views
29

用我的第一臺Mac進行開發,我注意到我的終端沒有彩色化Rspec輸出,即使我在命令bundle exec rspec -c -fd中使用'-c'標誌。有任何想法嗎?紅寶石RSpec:與Mac輸出無顏色

+0

dup? http://stackoverflow.com/q/1819614/119790 – 2013-05-21 10:33:38

回答

54

將以下內容添加到您的項目dir root的.rspec文件中。

--color

+10

或者,將.rspec文件放在您的主目錄中以應用所有項目的設置。 – Jimothy 2013-03-07 13:48:45

7

你也可以把對spec_helper.rb的配置,如果你不希望每次運行rspec的時候附上--color。

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 
+0

'config.color_enabled = true'對我不起作用,但是'config.color = true'。 – 2017-07-14 19:40:26

15

如果你從谷歌最近來到這裏,你可能會注意到,艾倫春的回答使用RSpec的3.0或更高時,給出了一個.color_enabledNoMethodError.color_enabled在3.0移除:https://github.com/rspec/rspec-core/blob/master/Changelog.md#300rc1--2014-05-18

spec_helper.rb只要改變.color_enabled.color

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

    # other config options here...  

end 

這個工作對我使用Ruby 2.1.2p95在OS X小牛10.9.4。

+1

感謝您的更正! :) – 2014-09-15 21:54:54

+0

謝謝,這很容易! – cpursley 2014-10-29 18:38:09