[rspec-devel] --colour with progress bar

David Chelimsky dchelimsky at gmail.com
Thu Oct 5 09:29:33 EDT 2006


On 10/5/06, KAKUTANI Shintaro <shintaro at kakutani.com> wrote:
> Hello, everyone.
>
> Thaks for RSpec 0.6.4 release and its '--color' option is great!!
> (I'm a grren bar lover.)
>
> I want to see colorized texts not only on summary line but on progress bar.
> Following patch represents what I want to :
>
> Index: progress_bar_formatter.rb
> ===================================================================
> --- progress_bar_formatter.rb   (revision 855)
> +++ progress_bar_formatter.rb   (working copy)
> @@ -8,12 +8,26 @@
>          end
>
>          def spec_failed(name, counter, failure)
> -          @output << 'F'
> +          prompt = 'F'
> +          if @colour && @output == STDOUT
> +            colour_prefix = "\e[31m"
> +            colour_postfix = "\e[0m"
> +          else
> +            colour_prefix = colour_postfix = ""
> +          end
> +          @output << "#{colour_prefix}#{prompt}#{colour_postfix}"
>            @output.flush
>          end
>
>          def spec_passed(name)
> -          @output << '.'
> +          prompt = '.'
> +          if @colour && @output == STDOUT
> +            colour_prefix = "\e[32m"
> +            colour_postfix = "\e[0m"
> +          else
> +            colour_prefix = colour_postfix = ""
> +          end
> +          @output << "#{colour_prefix}#{prompt}#{colour_postfix}"
>            @output.flush
>          end
>
> @@ -24,4 +38,4 @@
>        end
>      end
>    end
> -end
> \ No newline at end of file
> +end

How about sticking this in a custom formatter?

spec spec -f MyCustomFormatter --require my_custom_formatter.rb


More information about the rspec-devel mailing list