# RSpec: "--color" not working in spec.opts when combined with

**URL:** <https://www.ruby-forum.com/t/rspec-color-not-working-in-spec-opts-when-combined-with/112414>\
**Category:** Rails\
**Created:** [August 18, 2007, 4:16pm UTC](https://www.ruby-forum.com/t/rspec-color-not-working-in-spec-opts-when-combined-with/112414 "2007-08-18T16:16:49Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Hardbap](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/c89c15/32.png) [@Hardbap](https://www.ruby-forum.com/u/Hardbap)\
**Post date:** [August 18, 2007, 4:16pm UTC](https://www.ruby-forum.com/t/rspec-color-not-working-in-spec-opts-when-combined-with/112414/1 "2007-08-18T16:16:49Z")

</div>

Windows XP SP 2  
ruby 1.8.5

gems:  
rails 1.2.3  
rake 0.7.3  
win32console 1.0.8

plugins:  
rspec 1.0.8  
rspec\_rails 1.0.8

spec.opts:  
–colour  
–format  
progress  
–loadby  
mtime  
–reverse  
–drb

When I run “rake spec” or “ruby script/spec spec --color” this is the  
output:

D:\dev\project\>rake spec  
(in D:/dev/project)  
â†[32m.â†[0mâ†[32m.â†[0mâ†[32m.â†[0mâ†[32m.â†[0mâ†[32m.â†[0mâ†[32m.â†[0mâ†[32m.â†[0mâ†[32m.â†[0m  
â†[32m.â†[0mâ†[32m.â†[0mâ†[32m.â†[0m

Finished in 0.172 seconds

â†[32m11 examples, 0 failuresâ†[0m

If I remove “–drb” from the spec.opts file it runs fine (but slower).

---

<div class="post-metadata">

**Author:** ![Hardbap](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/c89c15/32.png) [@Hardbap](https://www.ruby-forum.com/u/Hardbap)\
**Post date:** [August 19, 2007, 1:19am UTC](https://www.ruby-forum.com/t/rspec-color-not-working-in-spec-opts-when-combined-with/112414/2 "2007-08-19T01:19:16Z")

</div>

I’m having the same problem. Also, “rake spec” doesn’t connect to my  
running spec\_server, but “ruby script/spec spec/models --drb” does. Do  
you have that this problem too?

I’m running:  
Vista  
ruby 1.8.6  
rails 1.2.3  
rake 0.7.3  
win32console 1.0.8  
rspec 1.0.8.  
same spec.opts

---

<div class="post-metadata">

**Author:** ![Hardbap](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/c89c15/32.png) [@Hardbap](https://www.ruby-forum.com/u/Hardbap)\
**Post date:** [August 20, 2007, 3:30pm UTC](https://www.ruby-forum.com/t/rspec-color-not-working-in-spec-opts-when-combined-with/112414/3 "2007-08-20T15:30:12Z")

</div>

I’m not having an issue with “rake spec” not connecting to  
spec\_sever.

Could it be an issue with Vista?

---

<div class="post-metadata">

**Author:** ![Hardbap](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/c89c15/32.png) [@Hardbap](https://www.ruby-forum.com/u/Hardbap)\
**Post date:** [August 20, 2007, 10:22pm UTC](https://www.ruby-forum.com/t/rspec-color-not-working-in-spec-opts-when-combined-with/112414/4 "2007-08-20T22:22:19Z")

</div>

Ok disregard the rake spec not connecting to spec\_server thing - I  
wasn’t using it properly.

I found a workaround to get colour and drb working together:

Add “require ‘Win32/Console/ANSI’” before the last line in your spec  
file and change the STDOUT parameter in the last line to $stdout.

So /script/spec should look like this:

#!/usr/bin/env ruby  
$LOAD\_PATH.unshift(File.expand\_path(File.dirname( **FILE** ) + “/…/  
vendor/plugins/rspec/lib”))  
require ‘spec’  
require ‘Win32/Console/ANSI’  
::Spec:🏃‍♂️:CommandLine.run(ARGV, STDERR, $stdout, true, true)

It’s not perfect. The first run will print the output to the console  
that spec\_server is running in. All subsequent runs will print to the  
correct console though. I couldn’t figure out why it was doing this  
but the way it works is good enough for me.

---

<div class="post-metadata">

**Author:** ![Hardbap](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/c89c15/32.png) [@Hardbap](https://www.ruby-forum.com/u/Hardbap)\
**Post date:** [August 21, 2007, 2:47pm UTC](https://www.ruby-forum.com/t/rspec-color-not-working-in-spec-opts-when-combined-with/112414/5 "2007-08-21T14:47:18Z")

</div>

It worked perfectly! Thank you Rich.

---

<div class="post-metadata">

**Author:** ![Hardbap](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/c89c15/32.png) [@Hardbap](https://www.ruby-forum.com/u/Hardbap)\
**Post date:** [August 21, 2007, 4:13pm UTC](https://www.ruby-forum.com/t/rspec-color-not-working-in-spec-opts-when-combined-with/112414/6 "2007-08-21T16:13:39Z")

</div>

I haven’t tried autotest yet but I’d like to - it sounds awesome. I’ll  
try it tonight and see if I get any output. I also posted that  
workaround as a comment to the bug in rspec’s tracker. Hopefully  
they’ll fix it properly soon.

---

<div class="post-metadata">

**Author:** ![Hardbap](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/c89c15/32.png) [@Hardbap](https://www.ruby-forum.com/u/Hardbap)\
**Post date:** [August 21, 2007, 3:16pm UTC](https://www.ruby-forum.com/t/rspec-color-not-working-in-spec-opts-when-combined-with/112414/7 "2007-08-21T15:16:24Z")

</div>

I did notice that this fix will suppress any output when using  
autotest.
