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

Commit 87c832f

Browse files
committed
Merge pull request #2019 from argos83/allow_adding_formatter_subclass
Allow adding a subclass of an already added formatter
2 parents 5bee475 + 17fb14e commit 87c832f

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

lib/rspec/core/formatters.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ def register(formatter, notifications)
182182

183183
def duplicate_formatter_exists?(new_formatter)
184184
@formatters.any? do |formatter|
185-
formatter.class === new_formatter && formatter.output == new_formatter.output
185+
formatter.class == new_formatter.class && formatter.output == new_formatter.output
186186
end
187187
end
188188

spec/rspec/core/formatters_spec.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,19 @@ module RSpec::Core::Formatters
137137
}.to change { loader.formatters.length }
138138
end
139139
end
140+
141+
context "When a custom formatter exists" do
142+
specific_formatter = RSpec::Core::Formatters::JsonFormatter
143+
generic_formatter = specific_formatter.superclass
144+
145+
before { loader.add generic_formatter, output }
146+
147+
it "adds a subclass of that formatter for the same output target" do
148+
expect {
149+
loader.add specific_formatter, output
150+
}.to change { loader.formatters.length }
151+
end
152+
end
140153
end
141154

142155
describe "#setup_default" do

0 commit comments

Comments
 (0)