Browse files

Merge pull request #1375 from rspec/formatter_colors

Remove deprecated formatter colours
  • Loading branch information...
2 parents 5fe4dc3 + e3150aa commit 24581295245794fbccb40ef46c8cc57ce91d7e75 @JonRowe JonRowe committed Mar 10, 2014
View
2 Changelog.md
@@ -8,12 +8,14 @@ Breaking Changes for 3.0.0:
class. (Myron Marston)
* Refactor filter manager so that it no longer subclasses Hash and has a
tighter, more domain-specific interface. (Sergey Pchelincev)
+* Remove legacy colours definitions from `BaseTextFormatter`. (Jon Rowe)
Enhancements:
* Add `config.default_formatter` attribute, which can be used to set a
formatter which will only be used if no other formatter is set
(e.g. via `--formatter`). (Myron Marston)
+* Support legacy colour definitions in `LegacyFormatterAdaptor`. (Jon Rowe)
Bug Fixes:
View
35 lib/rspec/core/formatters/base_text_formatter.rb
@@ -191,41 +191,6 @@ def default_color(text)
color(text, RSpec.configuration.default_color)
end
- def red(text)
- RSpec.deprecate("RSpec::Core::Formatters::BaseTextFormatter#red", :replacement => "#failure_color")
- color(text, :red)
- end
-
- def green(text)
- RSpec.deprecate("RSpec::Core::Formatters::BaseTextFormatter#green", :replacement => "#success_color")
- color(text, :green)
- end
-
- def yellow(text)
- RSpec.deprecate("RSpec::Core::Formatters::BaseTextFormatter#yellow", :replacement => "#pending_color")
- color(text, :yellow)
- end
-
- def blue(text)
- RSpec.deprecate("RSpec::Core::Formatters::BaseTextFormatter#blue", :replacement => "#fixed_color")
- color(text, :blue)
- end
-
- def magenta(text)
- RSpec.deprecate("RSpec::Core::Formatters::BaseTextFormatter#magenta")
- color(text, :magenta)
- end
-
- def cyan(text)
- RSpec.deprecate("RSpec::Core::Formatters::BaseTextFormatter#cyan", :replacement => "#detail_color")
- color(text, :cyan)
- end
-
- def white(text)
- RSpec.deprecate("RSpec::Core::Formatters::BaseTextFormatter#white", :replacement => "#default_color")
- color(text, :white)
- end
-
def short_padding
' '
end
View
44 lib/rspec/core/formatters/legacy_formatter.rb
@@ -88,18 +88,60 @@ def stop
end
end
+ module LegacyColorSupport
+ def red(text)
+ RSpec.deprecate("RSpec::Core::Formatters::BaseTextFormatter#red", :replacement => "#failure_color")
+ color(text, :red)
+ end
+
+ def green(text)
+ RSpec.deprecate("RSpec::Core::Formatters::BaseTextFormatter#green", :replacement => "#success_color")
+ color(text, :green)
+ end
+
+ def yellow(text)
+ RSpec.deprecate("RSpec::Core::Formatters::BaseTextFormatter#yellow", :replacement => "#pending_color")
+ color(text, :yellow)
+ end
+
+ def blue(text)
+ RSpec.deprecate("RSpec::Core::Formatters::BaseTextFormatter#blue", :replacement => "#fixed_color")
+ color(text, :blue)
+ end
+
+ def magenta(text)
+ RSpec.deprecate("RSpec::Core::Formatters::BaseTextFormatter#magenta")
+ color(text, :magenta)
+ end
+
+ def cyan(text)
+ RSpec.deprecate("RSpec::Core::Formatters::BaseTextFormatter#cyan", :replacement => "#detail_color")
+ color(text, :cyan)
+ end
+
+ def white(text)
+ RSpec.deprecate("RSpec::Core::Formatters::BaseTextFormatter#white", :replacement => "#default_color")
+ color(text, :white)
+ end
+ end
+
# @api private
attr_reader :formatter
# @api public
#
# @param formatter
def initialize(formatter_class, *args)
- if formatter_class.ancestors.include?(BaseFormatter)
+ if defined?(BaseFormatter) && formatter_class.ancestors.include?(BaseFormatter)
formatter_class.class_eval do
include LegacyInterface
end
end
+ if defined?(BaseTextFormatter) && formatter_class.ancestors.include?(BaseTextFormatter)
+ formatter_class.class_eval do
+ include LegacyColorSupport
+ end
+ end
@formatter = formatter_class.new(*args)
end
View
23 spec/rspec/core/formatters/base_text_formatter_spec.rb
@@ -277,27 +277,4 @@ def run_all_and_dump_failures
expect(formatter.colorize('abc', :cyan)).to eq "\e[36mabc\e[0m"
end
end
-
- described_class::VT100_COLORS.each do |name, number|
- next if name == :black
-
- describe "##{name}" do
- before do
- allow(RSpec.configuration).to receive(:color_enabled?) { true }
- allow(RSpec).to receive(:deprecate)
- end
-
- it "prints the text using the color code for #{name}" do
- expect(formatter.send(name, "text")).to eq("\e[#{number}mtext\e[0m")
- end
-
- it "prints a deprecation warning" do
- expect(RSpec).to receive(:deprecate) {|*args|
- expect(args.first).to match(/#{name}/)
- }
- formatter.send(name, "text")
- end
- end
- end
-
end
View
26 spec/rspec/core/formatters/legacy_formatter_spec.rb
@@ -134,4 +134,30 @@ def initialize(*args)
end
end
end
+
+ describe LegacyFormatterUsingSubClassing do
+ let(:legacy_formatter) { formatter.formatter }
+
+ described_class::VT100_COLORS.each do |name, number|
+ next if name == :black
+
+ describe "##{name}" do
+ before do
+ allow(RSpec.configuration).to receive(:color_enabled?) { true }
+ allow(RSpec).to receive(:deprecate)
+ end
+
+ it "prints the text using the color code for #{name}" do
+ expect(legacy_formatter.send(name, "text")).to eq("\e[#{number}mtext\e[0m")
+ end
+
+ it "prints a deprecation warning" do
+ expect(RSpec).to receive(:deprecate) {|*args|
+ expect(args.first).to match(/#{name}/)
+ }
+ legacy_formatter.send(name, "text")
+ end
+ end
+ end
+ end
end

0 comments on commit 2458129

Please sign in to comment.