Skip to content
This repository was archived by the owner on Nov 30, 2024. It is now read-only.

Commit ba977f1

Browse files
committed
Merge pull request #1470 from rspec/remove_legacy_formatter_support
Remove support for inherited legacy formatters [WIP]
2 parents 2306eaa + b8440af commit ba977f1

File tree

9 files changed

+47
-801
lines changed

9 files changed

+47
-801
lines changed

features/command_line/require_option.feature

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ Feature: `--require` option
1010
require 'delegate'
1111
1212
class LoggingFormatter < RSpec::Core::Formatters::BaseTextFormatter
13+
RSpec::Core::Formatters.register self, :dump_summary
14+
1315
def initialize(output)
1416
super LoggingIO.new(output)
1517
end

features/formatters/custom_formatter.feature

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -38,30 +38,3 @@ Feature: custom formatters
3838
When I run `rspec example_spec.rb --require ./custom_formatter.rb --format CustomFormatter`
3939
Then the output should contain "example: my example"
4040
And the exit status should be 0
41-
42-
Scenario: A legacy custom formatter
43-
Given a file named "custom_formatter.rb" with:
44-
"""ruby
45-
require "rspec/core/formatters/base_text_formatter"
46-
47-
class CustomFormatter < RSpec::Core::Formatters::BaseTextFormatter
48-
def initialize(output)
49-
super(output)
50-
end
51-
52-
def example_started(proxy)
53-
output << "example: " << proxy.description
54-
end
55-
end
56-
"""
57-
And a file named "example_spec.rb" with:
58-
"""ruby
59-
RSpec.describe "my group" do
60-
specify "my example" do
61-
end
62-
end
63-
"""
64-
When I run `rspec example_spec.rb --require ./custom_formatter.rb --format CustomFormatter`
65-
Then the output should contain "example: my example"
66-
And the output should contain "The CustomFormatter formatter uses the deprecated formatter interface."
67-
And the exit status should be 0

features/formatters/regression_tests.feature

Lines changed: 0 additions & 95 deletions
This file was deleted.

lib/rspec/core/formatters.rb

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
RSpec::Support.require_rspec_core 'formatters/legacy_formatter'
2-
31
# ## Built-in Formatters
42
#
53
# * progress (default) - prints dots for passing examples, `F` for failures, `*` for pending
@@ -116,16 +114,32 @@ def add(formatter_to_use, *paths)
116114
if !Loader.formatters[formatter_class].nil?
117115
formatter = formatter_class.new(*args)
118116
@reporter.register_listener formatter, *notifications_for(formatter_class)
119-
else
120-
formatter = LegacyFormatter.new(formatter_class, *args)
117+
elsif defined?(RSpec::LegacyFormatters)
118+
formatter = RSpec::LegacyFormatters.load_formatter formatter_class, *args
121119
@reporter.register_listener formatter, *formatter.notifications
122-
end
120+
else
121+
line = ::RSpec::CallerFilter.first_non_rspec_line
122+
if line
123+
call_site = "Formatter added at: #{line}"
124+
else
125+
call_site = "The formatter was added via command line flag or your "+
126+
"`.rspec` file."
127+
end
123128

124-
@formatters << formatter unless duplicate_formatter_exists?(formatter)
125-
if formatter.is_a?(LegacyFormatter)
126-
RSpec.warn_deprecation "The #{formatter_class} formatter uses the deprecated formatter interface.\n Formatter added at: #{::RSpec::CallerFilter.first_non_rspec_line}"
129+
RSpec.warn_deprecation <<-WARNING.gsub(/\s*\|/,' ')
130+
|The #{formatter_class} formatter uses the deprecated formatter
131+
|interface not supported directly by RSpec 3.
132+
|
133+
|To continue to use this formatter you must install the
134+
|`rspec-legacy_formatters` gem, which provides support
135+
|for legacy formatters or upgrade the formatter to a
136+
|compatible version.
137+
|
138+
|#{call_site}
139+
WARNING
140+
return
127141
end
128-
142+
@formatters << formatter unless duplicate_formatter_exists?(formatter)
129143
formatter
130144
end
131145

0 commit comments

Comments
 (0)