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

Commit d1976e1

Browse files
committed
dup formater_loader.formatters when returning from config
1 parent 1e4783c commit d1976e1

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

lib/rspec/core/configuration.rb

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -641,9 +641,16 @@ def default_formatter=(value)
641641
formatter_loader.default_formatter = value
642642
end
643643

644-
# @private
644+
# @api public
645+
#
646+
# Returns a duplicate of the formatters currently loaded in
647+
# the `FormatterLoader` for introspection.
648+
#
649+
# Note as this is a duplicate, any mutations will be disregarded.
650+
#
651+
# @return [Array] the formatters currently loaded
645652
def formatters
646-
formatter_loader.formatters
653+
formatter_loader.formatters.dup
647654
end
648655

649656
# @private

spec/rspec/core/configuration_spec.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -853,6 +853,14 @@ def metadata_hash(*args)
853853
end
854854
end
855855

856+
describe "#formatters" do
857+
it "returns a dup of the formatter_loader formatters" do
858+
config.add_formatter 'doc'
859+
config.formatters.clear
860+
expect(config.formatters).to_not eq []
861+
end
862+
end
863+
856864
describe "#default_formatter" do
857865
it 'defaults to `progress`' do
858866
expect(config.default_formatter).to eq('progress')

0 commit comments

Comments
 (0)