[rspec-users] heres how to get color output in rspec_autotest with rspec 0.7.5

aslak hellesoy aslak.hellesoy at gmail.com
Thu Dec 21 12:14:25 EST 2006


Thanks, I saw the patch in the tracker.

On 12/21/06, Michael Johnston <lastobelus at mac.com> wrote:
> In case anyone else is trying to make this work, here is what I did
> (Before 0.7.4 I had patched the regex in zentest redgreen, but that
> is not used any more)
>
> To use directly, it is very simple. In rspec_autotest/lib/
> rspec_autotest.rb, add a -c to the spec_command in the initializer
> function:
>
>         @spec_command = "spec -c --diff unified"
>
> This won't help however if you want to use rails_spec_server. To do
> that I patched rspec_0.7.5 to add an option to force the adding of
> colour codes (I did it this way because I assumed the check for
> output==Kernel was important for some other situation and I didn't
> want to just throw it away):
>
> diff -upr rspec-0.7.5/lib/spec/runner/formatter/
> base_text_formatter.rb rspec-0.7.5_with_colour_patch/lib/spec/runner/
> formatter/base_text_formatter.rb
> --- rspec-0.7.5/lib/spec/runner/formatter/base_text_formatter.rb
> 2006-12-21 01:42:44.000000000 -0800
> +++ rspec-0.7.5_with_colour_patch/lib/spec/runner/formatter/
> base_text_formatter.rb  2006-12-21 01:47:16.000000000 -0800
> @@ -5,10 +5,11 @@ module Spec
>         # non-text based ones too - just ignore the +output+ constructor
>         # argument.
>         class BaseTextFormatter
> -        def initialize(output, dry_run=false, colour=false)
> +        def initialize(output, dry_run=false, colour=false,
> force_colour=false)
>             @output = output
>             @dry_run = dry_run
> -          @colour = colour
> +          @colour = colour || force_colour
> +          @force_colour = force_colour
>             begin ; require 'Win32/Console/ANSI' if @colour &&
> PLATFORM =~ /win32/ ; rescue LoadError ; raise "You must gem install
> win32console to use colour on Windows" ; end
>               end
> @@ -96,7 +97,7 @@ module Spec
>           end
>           def colour(text, colour_code)
> -          return text unless @colour && @output == Kernel
> +          return text unless @force_colour || (@colour && @output ==
> Kernel)
>             "#{colour_code}#{text}\e[0m"
>           end
>
> diff -upr rspec-0.7.5/lib/spec/runner/option_parser.rb
> rspec-0.7.5_with_colour_patch/lib/spec/runner/option_parser.rb
> --- rspec-0.7.5/lib/spec/runner/option_parser.rb        2006-12-21
> 01:42:44.000000000 -0800
> +++ rspec-0.7.5_with_colour_patch/lib/spec/runner/option_parser.rb
> 2006-12-21 01:38:15.000000000 -0800
> @@ -11,8 +11,7 @@ module Spec
>         def create_context_runner(args, err, out, warn_if_no_files)
>           options = parse(args, err, out, warn_if_no_files)
> -
> -        formatter = options.formatter_type.new(options.out,
> options.dry_run, options.colour)
> +        formatter = options.formatter_type.new(options.out,
> options.dry_run, options.colour, options.force_colour)
>           options.reporter = Reporter.new(formatter,
> options.backtrace_tweaker)
>           # this doesn't really belong here.
> @@ -71,6 +70,10 @@ module Spec
>               options.colour = true
>             end
>
> +          opts.on("-C", "--force-colour", "--force-color", "force
> adding color codes regardless of output method") do
> +            options.force_colour = true
> +          end
> +
>             opts.on("-s", "--spec SPECIFICATION_NAME", "Execute
> context or specification with matching name") do |spec_name|
>               options.spec_name = spec_name
>             end
>
>
>
>
>
>
> then you can set the spec_command in rspec_autotest/lib/
> rspec_autotest.rb to:
>
>      @spec_command = "script/rails_spec -C --diff unified"
>
>
>
> Cheers,
> Michael
>
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users
>


More information about the rspec-users mailing list