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

Commit 720f2b1

Browse files
committed
Merge pull request #2916 from niceking/bypass-output-check-when-output-undefined
Skip output check if output not defined on formatter
1 parent 18968e0 commit 720f2b1

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

lib/rspec/core/formatters.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,10 +190,16 @@ def register(formatter, notifications)
190190

191191
def duplicate_formatter_exists?(new_formatter)
192192
@formatters.any? do |formatter|
193-
formatter.class == new_formatter.class && formatter.output == new_formatter.output
193+
formatter.class == new_formatter.class &&
194+
has_matching_output?(formatter, new_formatter)
194195
end
195196
end
196197

198+
def has_matching_output?(formatter, new_formatter)
199+
return true unless formatter.respond_to?(:output) && new_formatter.respond_to?(:output)
200+
formatter.output == new_formatter.output
201+
end
202+
197203
def existing_formatter_implements?(notification)
198204
@reporter.registered_listeners(notification).any?
199205
end

spec/rspec/core/formatters_spec.rb

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,9 +144,27 @@ module RSpec::Core::Formatters
144144
loader.add :documentation, path
145145
}.to change { loader.formatters.length }
146146
end
147+
148+
plain_old_formatter = Class.new do
149+
RSpec::Core::Formatters.register self, :example_started
150+
151+
def initialize(output)
152+
end
153+
end
154+
155+
it "handles formatters which do not subclass our formatters" do
156+
expect {
157+
loader.add plain_old_formatter, output
158+
}.to change { loader.formatters.length }
159+
160+
# deliberate duplicate to ensure we can check for them correctly
161+
expect {
162+
loader.add plain_old_formatter, output
163+
}.to_not change { loader.formatters.length }
164+
end
147165
end
148166

149-
context "When a custom formatter exists" do
167+
context "when a custom formatter exists" do
150168
specific_formatter = RSpec::Core::Formatters::JsonFormatter
151169
generic_formatter = specific_formatter.superclass
152170

0 commit comments

Comments
 (0)