Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Make colors customizable in configuration #709

Merged
merged 17 commits into from

8 participants

@charliemaffitt

No description provided.

@robin850

Just giving :+1: for this feature. It's not a huge amount of code but it adds a nice way to customize Rspec.

lib/rspec/core/formatters/base_text_formatter.rb
((9 lines not shown))
else
- green(summary)
+ custom_color(summary, RSpec.configuration.success_color)
@myronmarston Owner

It looks like there used to be red, yellow and green methods...can these be safely removed?

@myronmarston Owner

Actually, looking at the source of this file, I'm seeing lots more color methods: blue, magenta, cyan, etc.

We should figure out what those are used for and add settings for them as well. As this stands, half the the colors are configurable and half aren't....and it'd be nice to get a fully consistent color config system.

I replaced the methods named by color with methods named by what they're being used for, and tied them all into the config settings. I didn't think it would make sense to leave the methods named by color if the color it returned was going to be configurable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
lib/rspec/core/formatters/base_text_formatter.rb
@@ -108,6 +109,10 @@ def close
def color(text, color_code)
color_enabled? ? "#{color_code}#{text}\e[0m" : text
end
+
+ def custom_color(text, color_code)
+ color_enabled? ? RSpec::Core::Formatters::TerminalColor.colorize(text, color_code) : text
+ end
@myronmarston Owner

Can this leverage the existing color method? (or maybe that one should be removed entirely?) There's a good deal of duplication here.

Good note, I combined the two methods into one color method.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
lib/rspec/core/formatters/terminal_color.rb
((4 lines not shown))
+ class TerminalColor
+
+ VT100_COLORS = {
+ :black => 30,
+ :red => 31,
+ :green => 32,
+ :yellow => 33,
+ :blue => 34,
+ :magenta => 35,
+ :cyan => 36,
+ :white => 37
+ }
+
+ def self.colorize(text, code_or_symbol)
+ code = VT100_COLORS.fetch(code_or_symbol) { code_or_symbol }
+ "\e[#{code}m#{text}\e[0m"
@myronmarston Owner

Currently, if someone tries to use a color symbol that's not in the VT100_COLORS hash (or if they fat finger it) this'll happily insert the symbol as a color code directly in the string...which is going to make for some wonky output.

I don't think it should raise an error here in that case (raising an error in a formatter could potentially halt the spec run), but maybe it can:

  • Print a warning
  • Use white instead
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
lib/rspec/core/formatters/terminal_color.rb
((9 lines not shown))
+ :green => 32,
+ :yellow => 33,
+ :blue => 34,
+ :magenta => 35,
+ :cyan => 36,
+ :white => 37
+ }
+
+ def self.colorize(text, code_or_symbol)
+ code = VT100_COLORS.fetch(code_or_symbol) { code_or_symbol }
+ "\e[#{code}m#{text}\e[0m"
+ end
+ end
+ end
+ end
+end
@myronmarston Owner

This worked out nicely as a separate class, but what do you think about moving the code back into the original base_text_formatter file? Every additional require statement adds to the time it takes to load rspec (particularly on 1.9.2, which has well-known perf issues with require), and I think this could live in the other file just fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
spec/rspec/core/formatters/base_text_formatter_spec.rb
@@ -364,4 +364,13 @@ def run_all_and_dump_pending
output.string.should =~ /, 100.0% of total time\):/
end
end
+
+ describe "custom_colors" do
+ before { RSpec.configuration.stub(:color_enabled?) { true } }
+ it "uses the custom success color" do
+ RSpec.configuration.stub(:success_color).and_return(:cyan)
@myronmarston Owner

Stubbin a value object (like RSpec.configuration) is a bit of a code smell, I think. You can just set color_enabled and success_color through the configuration APIs provided by RSpec::Configuration -- no need to stub.

The sandboxed thing in spec_helper.rb takes care of preventing changes to the configuration object in one example from leaking into other examples.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
lib/rspec/core/configuration.rb
@@ -190,6 +195,9 @@ def initialize
@filter_manager = FilterManager.new
@preferred_options = {}
@seed = srand % 0xFFFF
+ @failure_color = 31
+ @success_color = 32
+ @pending_color = 33
@myronmarston Owner

I think it'd be more intention revealing to use the symbols (e.g. :green) here rather than the numbers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
lib/rspec/core/configuration.rb
@@ -122,6 +122,11 @@ def self.add_setting(name, opts={})
# Run all examples if none match the configured filters (default: `false`).
add_setting :run_all_when_everything_filtered
+
+ # Allow user to configure their own success/pending/failure colors
+ add_setting :success_color
+ add_setting :pending_color
+ add_setting :failure_color
@myronmarston Owner

I think we need some YARD docs here, particularly to list all the color symbols that are valid. Otherwise users will have to look at the source to discover that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@myronmarston

Thanks for the pull request, @charliemaffitt! What you have here is a great start for this feature. I left a few comments -- let me know if you have questions are don't feel like you'll have the time to get to them.

@alindeman
Collaborator

@charliemaffitt, are you able to wrap up with these comments? The core team can knock them out, but it may take a bit longer.

@charliemaffitt

@alindeman Yes, I'm adding it to my list of things to take care of this iteration, will try to address as many of the comments as possible within the next week.

@dolzenko

Hopefully this will get merged in at some point because default colors are impossible to follow with black text on white background color scheme.

@dchelimsky
Owner

@dolzenko that's the first time I've heard anybody say that. Which colors are confusing to you?

@dolzenko

@dchelimsky now as you said that I realized that I should really just fix colors in my terminal instead, sorry for all the confusion.

@dchelimsky
Owner

@dolzenko :) No worries.

@greggroth

Is there anything left to do to wrap up this PR?

@charliemaffitt

@greggroth I pushed changes here #709 (commits) that cover most of the original comments, if there is anything I've left undone which is specifically preventing the pull request from being accepted, let me know.

@myronmarston

@charliemaffitt -- I'll take a look at merging this tomorrow. Thanks for your work!

@charliemaffitt

@myronmarston thanks, if there is anything I forgot to do or still needs love, let me know, I'll be happy to look at it some more.

@myronmarston

@charliemaffitt -- I intended to spend most of today working on rspec but I was in the middle of a large refactoring at work that I didn't want to set aside...so I haven't had time to review this. Feel free to get on my case in a couple days if I still haven't responded.

lib/rspec/core/formatters/base_text_formatter.rb
((9 lines not shown))
+ :black => 30,
+ :red => 31,
+ :green => 32,
+ :yellow => 33,
+ :blue => 34,
+ :magenta => 35,
+ :cyan => 36,
+ :white => 37
+ }
+
+ def colorize(text, code_or_symbol)
+ if VT100_COLORS.key?(code_or_symbol) || VT100_COLORS.value?(code_or_symbol)
+ code = VT100_COLORS.fetch(code_or_symbol) { code_or_symbol }
+ "\e[#{code}m#{text}\e[0m"
+ else # defaults to white
+ "\e[37m#{text}\e[0m"
@myronmarston Owner

Rather than hardcoding this to 37, maybe this should use the configured default color?

@myronmarston Owner

Actually, thinking about this some more, I can see now that there needs to be a fallback for the case where :default is misconfigured...so falling back to white seems OK.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
lib/rspec/core/formatters/base_text_formatter.rb
((5 lines not shown))
-
- def color(text, color_code)
- color_enabled? ? "#{color_code}#{text}\e[0m" : text
+ VT100_COLORS = {
+ :black => 30,
+ :red => 31,
+ :green => 32,
+ :yellow => 33,
+ :blue => 34,
+ :magenta => 35,
+ :cyan => 36,
+ :white => 37
+ }
+
+ def colorize(text, code_or_symbol)
+ if VT100_COLORS.key?(code_or_symbol) || VT100_COLORS.value?(code_or_symbol)
@myronmarston Owner

This key? or value? logic is a bit counter-intuitive. What do you think about something like this instead?

VT100_COLORS = { ... }
VT100_COLOR_CODES = VT100_COLORS.values.to_set

def color_code_for(code_or_symbol)
  if VT100_COLOR_CODES.include?(code_or_symbol)
    code_or_symbol
  else
    VT100_COLORS.fetch(code_or_symbol) do
      color_code_for(:white)
    end
  end
end


def colorize(text, code_or_symbol)
  "\e[#{color_code_for(code_or_symbol)}m#{text}\e[0m"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@myronmarston

@charliemaffitt -- Things are looking really good. Besides the couple of comments I left, I've got a couple more general comments:

  • The pull request diff is kinda confusing, as it apparently includes several unrelated commits that are in master. Not sure what you did, but if you feel up for it, you might consider rebasing (and maybe even squashing your commits together as this is one logical changeset) so that diff is a bit easier to understand.
  • It'd be good to have a cuke documenting this so the examples on relish include an example of how to use the color configuration (sorry about forgetting to suggest that before!).

I want to make sure this gets merged soon, and am willing to take care of addressing my last couple of concerns myself if you're short on time or whatever...but I'm happy to let you take care of addressing my last couple comments if you want to. Just let me know either way. Thanks!

@charliemaffitt

@myronmarston thanks for the comments. I'm going to try and get everything wrapped up this week, will let you know once I make further changes.

lib/rspec/core/formatters/base_text_formatter.rb
((33 lines not shown))
end
- def red(text)
@alindeman Collaborator
12-20 16:28:52 <@alindeman> myronmarston: Do you think that nuking `red` and `green` and such (which were `protected`) is a breaking change for custom (third-party) formatters?
12-20 16:29:33 <+myronmarston> alindeman: hmm
12-20 16:29:35 <+myronmarston> alindeman: I hadn't thought about that
12-20 16:29:57 <+myronmarston> alindeman: given that they were not documented as part of the public API, I feel a bit better about it
12-20 16:30:14 <+myronmarston> alindeman: but if it's not difficult, it'd probably be good to add back deprecated red/green methods that delegate to the new ones
12-20 16:30:22 <+myronmarston> alindeman: and then we can remove them in soon in rspec 3
12-20 16:30:26 <@alindeman> myronmarston: That was my thought exactly

Does this make sense? Maybe clump them together so they can be easily removed later.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
charliemaffitt added some commits
@charliemaffitt charliemaffitt Updates BaseTextFormatter#colorize to check against a set of values
If it doesn't find the code in the set of values, it looks in the hash of VT_100 codes and values. If it can't find it there, it defaults to white.
868a861
@charliemaffitt charliemaffitt Restores color-named methods in BaseTextFormatter
in case they are being used by 3rd-party applications. Uses color symbol instead of code for clarity.
64c8739
@charliemaffitt charliemaffitt Adds method for magenta to BaseTextFormatter
which I overlooked in 64c8739
44e4679
@charliemaffitt

@myronmarston I was able to clean up the diff and get rid of the unrelated commits thanks to @alindeman's help. I also just pushed up a couple more tweaks to the methods based on your suggestions.

The only thing I still have a question about is the cuke: How would I go about evaluating that the output is the right color? I'm a little unsure of how to test that. Do you have any suggestions? Also, do you think I should add to the existing features/formatters/custom_formatter.feature or create a new feature for the configurable terminal colors?

@charliemaffitt

@myronmarston here is what I have so far for that cucumber:

Feature: configurable colors

  Terminal output colors can be customized in Rspec configuration

  Given a file named "configurable_colors_spec.rb" with:
    """ruby
    RSpec.configure do |config|
      config.color_enabled = true
      config.tty = true
    end

    describe "success_color" do

      it "can be overridden in configuration" do
        RSpec.configuration.success_color = :cyan
      end
    end
    """
  When I run `rspec ./configurable_colors_spec.rb`
  Then ?
@myronmarston

@charliemaffitt -- I wouldn't consider a cuke a prerequisite for merging this, but thanks for taking a stab at it!

Anyhow, you can do something like:

When I run `rspec ./configurable_colors_spec.rb --format progress`
Then the progress dots should be printed in cyan

You'll need to define the Then the progress dots should be printed in cyan step. I haven't done much with ansi color codes (and I've done nothing with aruba and the color codes) but hopefully there's a simple way to look at the output string from aruba and verify the proper color codes are there.

lib/rspec/core/formatters/base_text_formatter.rb
((96 lines not shown))
end
def white(text)
- color(text, "\e[37m")
+ color(text, :cyan)
end
@myronmarston Owner

Shouldn't this be :white?

Yes it should. I'll correct.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
lib/rspec/core/formatters/base_text_formatter.rb
((66 lines not shown))
end
def red(text)
- color(text, "\e[31m")
+ color(text, :red)
end
@myronmarston Owner

I'm glad to see these methods kept for backwards compatibility, but I'd like to see them deprecated (with the plan to remove them in 3.0) so that formatter authors will be notified to use the new methods (which respect the user's color configs) instead.

Would that look like this?

# @deprecated
# use failure_color(text) instead
def red(text)
  color(text, :red)
end
@myronmarston Owner

We also want a deprecation warning to be printed, so that folks using this notice that it has been deprecated (updating the docs isn't usually enough). You can use RSpec.deprecate for this....something like:

def red(text)
  RSpec.deprecate("RSpec::Core::Formatters::BaseTextFormatter#red", "#failure_color", "3.0")
  color(text, :red)
end

(you should check the produced message to make sure it makes sense).

As a side note: do we think that this method should continue to color things red (regardless of the configured failure color) or should it start using the configured failure color? (This question applies to all the other deprecated methods, too).

Thanks, I can follow that pattern.

In my opinion, the method should continue to color things red. I was thinking about this earlier and I decided I didn't like the idea of methods explicitly named for their colors producing different colors than their names. But I it would be easy enough to change it to just use the configured color if you or others disagree.

@myronmarston Owner

No, you're reasoning makes sense, and I agree.

From what I can tell #magenta wasn't really being used for any type of message (it isn't referenced elsewhere in the code that I can find): Do you think it would it be better to add one more generic configurable method or just put a message referencing the configurable methods in the second argument of the deprecation warning for #magenta?

@myronmarston Owner

If there's no alternate method to use, you can pass nil:

RSpec.deprecate("RSpec::Core::Formatters::BaseTextFormatter#magenta", nil, "3.0")

Deprecation warnings have been added.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@myronmarston myronmarston merged commit f15615a into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Dec 20, 2012
  1. @charliemaffitt @alindeman

    Make colors customizable in configuration

    charliemaffitt authored alindeman committed
  2. @charliemaffitt @alindeman
  3. @charliemaffitt @alindeman
  4. @charliemaffitt @alindeman
  5. @charliemaffitt @alindeman
  6. @charliemaffitt @alindeman

    Removes requirement for terminal_color class which was moved back int…

    charliemaffitt authored alindeman committed
    …o base_text_formatter
  7. @charliemaffitt @alindeman
  8. @charliemaffitt @alindeman
  9. @charliemaffitt @alindeman
  10. @charliemaffitt @alindeman

    Fixes bad syntax in bold definition

    charliemaffitt authored alindeman committed
  11. @charliemaffitt @alindeman
  12. @charliemaffitt

    Updates BaseTextFormatter#colorize to check against a set of values

    charliemaffitt authored
    If it doesn't find the code in the set of values, it looks in the hash of VT_100 codes and values. If it can't find it there, it defaults to white.
  13. @charliemaffitt

    Restores color-named methods in BaseTextFormatter

    charliemaffitt authored
    in case they are being used by 3rd-party applications. Uses color symbol instead of code for clarity.
  14. @charliemaffitt

    Adds method for magenta to BaseTextFormatter

    charliemaffitt authored
    which I overlooked in 64c8739
Commits on Dec 21, 2012
  1. @charliemaffitt
Commits on Dec 22, 2012
  1. @charliemaffitt
  2. @charliemaffitt

    Nil is not a string

    charliemaffitt authored
This page is out of date. Refresh to see the latest.
View
15 lib/rspec/core/configuration.rb
@@ -128,6 +128,15 @@ def self.add_setting(name, opts={})
# Run all examples if none match the configured filters (default: `false`).
add_setting :run_all_when_everything_filtered
+ # Allow user to configure their own success/pending/failure colors
+ # @param [Symbol] should be one of the following: [:black, :white, :red, :green, :yellow, :blue, :magenta, :cyan]
+ add_setting :success_color
+ add_setting :pending_color
+ add_setting :failure_color
+ add_setting :default_color
+ add_setting :fixed_color
+ add_setting :detail_color
+
# Seed for random ordering (default: generated randomly each run).
#
# When you run specs with `--order random`, RSpec generates a random seed
@@ -195,6 +204,12 @@ def initialize
@filter_manager = FilterManager.new
@preferred_options = {}
@seed = srand % 0xFFFF
+ @failure_color = :red
+ @success_color = :green
+ @pending_color = :yellow
+ @default_color = :white
+ @fixed_color = :blue
+ @detail_color = :cyan
end
# @private
View
104 lib/rspec/core/formatters/base_text_formatter.rb
@@ -33,11 +33,11 @@ def dump_failures
# @param [String] string
def colorise_summary(summary)
if failure_count > 0
- red(summary)
+ color(summary, RSpec.configuration.failure_color)
elsif pending_count > 0
- yellow(summary)
+ color(summary, RSpec.configuration.pending_color)
else
- green(summary)
+ color(summary, RSpec.configuration.success_color)
end
end
@@ -61,7 +61,7 @@ def dump_commands_to_rerun_failed_examples
output.puts
failed_examples.each do |example|
- output.puts(red("rspec #{RSpec::Core::Metadata::relative_path(example.location)}") + " " + cyan("# #{example.full_description}"))
+ output.puts(failure_color("rspec #{RSpec::Core::Metadata::relative_path(example.location)}") + " " + detail_color("# #{example.full_description}"))
end
end
@@ -83,7 +83,7 @@ def dump_profile
sorted_examples.each do |example|
output.puts " #{example.full_description}"
- output.puts cyan(" #{red(format_seconds(example.execution_result[:run_time]))} #{red("seconds")} #{format_caller(example.location)}")
+ output.puts detail_color(" #{failure_color(format_seconds(example.execution_result[:run_time]))} #{failure_color("seconds")} #{format_caller(example.location)}")
end
end
@@ -103,9 +103,9 @@ def dump_pending
output.puts
output.puts "Pending:"
pending_examples.each do |pending_example|
- output.puts yellow(" #{pending_example.full_description}")
- output.puts cyan(" # #{pending_example.execution_result[:pending_message]}")
- output.puts cyan(" # #{format_caller(pending_example.location)}")
+ output.puts pending_color(" #{pending_example.full_description}")
+ output.puts detail_color(" # #{pending_example.execution_result[:pending_message]}")
+ output.puts detail_color(" # #{format_caller(pending_example.location)}")
if pending_example.execution_result[:exception] \
&& RSpec.configuration.show_failures_in_pending_blocks?
dump_failure_info(pending_example)
@@ -125,42 +125,100 @@ def close
output.close if IO === output && output != $stdout
end
+ VT100_COLORS = {
+ :black => 30,
+ :red => 31,
+ :green => 32,
+ :yellow => 33,
+ :blue => 34,
+ :magenta => 35,
+ :cyan => 36,
+ :white => 37
+ }
+
+ VT100_COLOR_CODES = VT100_COLORS.values.to_set
+
+ def color_code_for(code_or_symbol)
+ if VT100_COLOR_CODES.include?(code_or_symbol)
+ code_or_symbol
+ else
+ VT100_COLORS.fetch(code_or_symbol) do
+ color_code_for(:white)
+ end
+ end
+ end
+
+ def colorize(text, code_or_symbol)
+ "\e[#{color_code_for(code_or_symbol)}m#{text}\e[0m"
+ end
+
protected
+ def bold(text)
+ color_enabled? ? "\e[1m#{text}\e[0m" : text
+ end
+
def color(text, color_code)
- color_enabled? ? "#{color_code}#{text}\e[0m" : text
+ color_enabled? ? colorize(text, color_code) : text
+ end
+
+ def failure_color(text)
+ color(text, RSpec.configuration.failure_color)
end
- def bold(text)
- color(text, "\e[1m")
+ def success_color(text)
+ color(text, RSpec.configuration.success_color)
+ end
+
+ def pending_color(text)
+ color(text, RSpec.configuration.pending_color)
+ end
+
+ def fixed_color(text)
+ color(text, RSpec.configuration.fixed_color)
+ end
+
+ def detail_color(text)
+ color(text, RSpec.configuration.detail_color)
+ end
+
+ def default_color(text)
+ color(text, RSpec.configuration.default_color)
end
def red(text)
- color(text, "\e[31m")
+ RSpec.deprecate("RSpec::Core::Formatters::BaseTextFormatter#red", "#failure_color", "3.0")
+ color(text, :red)
end
def green(text)
- color(text, "\e[32m")
+ RSpec.deprecate("RSpec::Core::Formatters::BaseTextFormatter#green", "#success_color", "3.0")
+ color(text, :green)
end
def yellow(text)
- color(text, "\e[33m")
+ RSpec.deprecate("RSpec::Core::Formatters::BaseTextFormatter#yellow", "#pending_color", "3.0")
+ color(text, :yellow)
end
def blue(text)
- color(text, "\e[34m")
+ RSpec.deprecate("RSpec::Core::Formatters::BaseTextFormatter#blue", "#fixed_color", "3.0")
+ color(text, :blue)
end
def magenta(text)
- color(text, "\e[35m")
+ RSpec.deprecate("RSpec::Core::Formatters::BaseTextFormatter#magenta", nil, "3.0")
+ color(text, :magenta)
end
def cyan(text)
- color(text, "\e[36m")
+ RSpec.deprecate("RSpec::Core::Formatters::BaseTextFormatter#cyan", "#detail_color", "3.0")
+ color(text, :cyan)
end
def white(text)
- color(text, "\e[37m")
+ RSpec.deprecate("RSpec::Core::Formatters::BaseTextFormatter#white", "#default_color", "3.0")
+ color(text, :white)
end
def short_padding
@@ -179,13 +237,13 @@ def format_caller(caller_info)
def dump_backtrace(example)
format_backtrace(example.execution_result[:exception].backtrace, example).each do |backtrace_info|
- output.puts cyan("#{long_padding}# #{backtrace_info}")
+ output.puts detail_color("#{long_padding}# #{backtrace_info}")
end
end
def dump_pending_fixed(example, index)
output.puts "#{short_padding}#{index.next}) #{example.full_description} FIXED"
- output.puts blue("#{long_padding}Expected pending '#{example.metadata[:execution_result][:pending_message]}' to fail. No Error was raised.")
+ output.puts fixed_color("#{long_padding}Expected pending '#{example.metadata[:execution_result][:pending_message]}' to fail. No Error was raised.")
end
def pending_fixed?(example)
@@ -199,9 +257,9 @@ def dump_failure(example, index)
def dump_failure_info(example)
exception = example.execution_result[:exception]
- output.puts "#{long_padding}#{red("Failure/Error:")} #{red(read_failed_line(exception, example).strip)}"
- output.puts "#{long_padding}#{red(exception.class.name << ":")}" unless exception.class.name =~ /RSpec/
- exception.message.to_s.split("\n").each { |line| output.puts "#{long_padding} #{red(line)}" } if exception.message
+ output.puts "#{long_padding}#{failure_color("Failure/Error:")} #{failure_color(read_failed_line(exception, example).strip)}"
+ output.puts "#{long_padding}#{failure_color(exception.class.name << ":")}" unless exception.class.name =~ /RSpec/
+ exception.message.to_s.split("\n").each { |line| output.puts "#{long_padding} #{failure_color(line)}" } if exception.message
if shared_group = find_shared_group(example)
dump_shared_failure_info(shared_group)
end
View
6 lib/rspec/core/formatters/documentation_formatter.rb
@@ -38,7 +38,7 @@ def example_failed(example)
end
def failure_output(example, exception)
- red("#{current_indentation}#{example.description.strip} (FAILED - #{next_failure_index})")
+ failure_color("#{current_indentation}#{example.description.strip} (FAILED - #{next_failure_index})")
end
def next_failure_index
@@ -47,11 +47,11 @@ def next_failure_index
end
def passed_output(example)
- green("#{current_indentation}#{example.description.strip}")
+ success_color("#{current_indentation}#{example.description.strip}")
end
def pending_output(example, message)
- yellow("#{current_indentation}#{example.description.strip} (PENDING: #{message})")
+ pending_color("#{current_indentation}#{example.description.strip} (PENDING: #{message})")
end
def current_indentation
View
6 lib/rspec/core/formatters/progress_formatter.rb
@@ -7,17 +7,17 @@ class ProgressFormatter < BaseTextFormatter
def example_passed(example)
super(example)
- output.print green('.')
+ output.print success_color('.')
end
def example_pending(example)
super(example)
- output.print yellow('*')
+ output.print pending_color('*')
end
def example_failed(example)
super(example)
- output.print red('F')
+ output.print failure_color('F')
end
def start_dump
View
27 spec/rspec/core/formatters/base_text_formatter_spec.rb
@@ -364,4 +364,31 @@ def run_all_and_dump_pending
output.string.should =~ /, 100.0% of total time\):/
end
end
+
+ describe "custom_colors" do
+ it "uses the custom success color" do
+ RSpec.configure do |config|
+ config.color_enabled = true
+ config.tty = true
+ config.success_color = :cyan
+ end
+ formatter.dump_summary(0,1,0,0)
+ output.string.should include("\e[36m")
+ end
+ end
+
+ describe "#colorize" do
+ it "accepts a VT100 integer code and formats the text with it" do
+ formatter.colorize('abc', 32).should == "\e[32mabc\e[0m"
+ end
+
+ it "accepts a symbol as a color parameter and translates it to the correct integer code, then formats the text with it" do
+ formatter.colorize('abc', :green).should == "\e[32mabc\e[0m"
+ end
+
+ it "accepts a non-default color symbol as a parameter and translates it to the correct integer code, then formats the text with it" do
+ formatter.colorize('abc', :cyan).should == "\e[36mabc\e[0m"
+ end
+ end
+
end
Something went wrong with that request. Please try again.