[rspec-devel] [ rspec-Bugs-6317 ] c option for colorizing output does not work with rails_spec

noreply at rubyforge.org noreply at rubyforge.org
Wed Nov 15 22:59:53 EST 2006


Bugs item #6317, was opened at 2006-10-26 07:06
You can respond by visiting: 
http://rubyforge.org/tracker/?func=detail&atid=3149&aid=6317&group_id=797

Category: rails plugin
Group: None
Status: Open
Resolution: None
Priority: 3
Submitted By: Ed Howland (edhowland)
Assigned to: Nobody (None)
Summary: c option for colorizing output does not work with rails_spec

Initial Comment:
When using the -c, --color or --colur option with rails_spec (the sever client) the output is black, not red or green as in using rhe normal spec command.

----------------------------------------------------------------------

Comment By: Shintaro Kakutani (kakutani)
Date: 2006-11-16 12:59

Message:
following patch is better than the last post?


Index: lib/spec/runner/formatter/base_text_formatter.rb
===================================================================
--- lib/spec/runner/formatter/base_text_formatter.rb	(revision 1114)
+++ lib/spec/runner/formatter/base_text_formatter.rb	(working copy)
@@ -96,10 +96,18 @@
         end
 
         def colour(text, colour_code)
-          return text unless @colour && @output == Kernel
+          return text unless @colour && output_to_stdout?
           "#{colour_code}#{text}\e[0m"
         end
     
+        def output_to_stdout?
+          begin
+            @output == Kernel || @output.tty?
+          rescue NoMethodError
+            false
+          end
+        end
+        
         def red(text); colour(text, "\e[31m"); end
         def green(text); colour(text, "\e[32m"); end
         def magenta(text); colour(text, "\e[35m"); end
@@ -107,4 +115,4 @@
       end
     end
   end
-end
\ No newline at end of file
+end




----------------------------------------------------------------------

Comment By: Shintaro Kakutani (kakutani)
Date: 2006-11-16 10:41

Message:
How about following patches.
It's not smart, but works.

Index: lib/spec/runner/formatter/base_text_formatter.rb
===================================================================
--- lib/spec/runner/formatter/base_text_formatter.rb	(revision 1111)
+++ lib/spec/runner/formatter/base_text_formatter.rb	(working copy)
@@ -100,6 +100,14 @@
           "#{colour_code}#{text}\e[0m"
         end
     
+        def output_to_stdout?
+          begin
+            @output == Kernel || @output.stdout?
+          rescue NoMethodError
+            false
+          end
+        end
+        
         def red(text); colour(text, "\e[31m"); end
         def green(text); colour(text, "\e[32m"); end
         def magenta(text); colour(text, "\e[35m"); end
@@ -107,4 +115,4 @@
       end
     end
   end
-end
\ No newline at end of file
+end
Index: vendor/rspec_on_rails/vendor/plugins/rspec/generators/rspec/templates/script/rails_spec
===================================================================
--- vendor/rspec_on_rails/vendor/plugins/rspec/generators/rspec/templates/script/rails_spec	(revision 1111)
+++ vendor/rspec_on_rails/vendor/plugins/rspec/generators/rspec/templates/script/rails_spec	(working copy)
@@ -5,7 +5,10 @@
 begin
   DRb.start_service
   rails_spec_server = DRbObject.new_with_uri("druby://localhost:8989")
+  STDOUT.instance_eval do
+    def stdout?; self == STDOUT end
+  end
   rails_spec_server.run(ARGV, STDERR, STDOUT)
 rescue DRb::DRbConnError
   puts "No rails_spec_server is running. Please start one via 'script/rails_spec_server'"
-end
\ No newline at end of file
+end


----------------------------------------------------------------------

You can respond by visiting: 
http://rubyforge.org/tracker/?func=detail&atid=3149&aid=6317&group_id=797


More information about the rspec-devel mailing list