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

Skip output check if output not defined on formatter #2916

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion lib/rspec/core/formatters.rb
Original file line number Diff line number Diff line change
Expand Up @@ -194,10 +194,16 @@ def register(formatter, notifications)

def duplicate_formatter_exists?(new_formatter)
@formatters.any? do |formatter|
formatter.class == new_formatter.class && formatter.output == new_formatter.output
formatter.class == new_formatter.class &&
has_matching_output?(formatter, new_formatter)
end
end

def has_matching_output?(formatter, new_formatter)
return true unless formatter.respond_to?(:output) && new_formatter.respond_to?(:output)
formatter.output == new_formatter.output
end

def existing_formatter_implements?(notification)
@reporter.registered_listeners(notification).any?
end
Expand Down
20 changes: 19 additions & 1 deletion spec/rspec/core/formatters_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,27 @@ module RSpec::Core::Formatters
loader.add :documentation, path
}.to change { loader.formatters.length }
end

plain_old_formatter = Class.new do
RSpec::Core::Formatters.register self, :example_started

def initialize(output)
end
end

it "handles formatters which do not subclass our formatters" do
expect {
loader.add plain_old_formatter, output
}.to change { loader.formatters.length }

# deliberate duplicate to ensure we can check for them correctly
expect {
loader.add plain_old_formatter, output
}.to_not change { loader.formatters.length }
end
end

context "When a custom formatter exists" do
context "when a custom formatter exists" do
specific_formatter = RSpec::Core::Formatters::JsonFormatter
generic_formatter = specific_formatter.superclass

Expand Down