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

Commit 87dfa07

Browse files
committed
prevent formater loader registering duplicate listeners
1 parent 5778abd commit 87dfa07

File tree

3 files changed

+6
-1
lines changed

3 files changed

+6
-1
lines changed

Changelog.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ Bug Fixes:
7070
where filtered to a particular location. (Ben Axnick, #1963)
7171
* Fix time formatting logic so that it displays 70 seconds as "1 minute,
7272
10 seconds" rather than "1 minute, 1 second". (Paul Brennan, #1984)
73+
* Fix regression where the formatter loader would allow duplicate formatters.
74+
(Jon Rowe, #1990)
7375

7476
### 3.2.3 / 2015-04-06
7577
[Full Changelog](http://github.com/rspec/rspec-core/compare/v3.2.2...v3.2.3)

lib/rspec/core/formatters.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,11 @@ def add(formatter_to_use, *paths)
143143

144144
if !Loader.formatters[formatter_class].nil?
145145
formatter = formatter_class.new(*args)
146+
return formatter if duplicate_formatter_exists?(formatter)
146147
@reporter.register_listener formatter, *notifications_for(formatter_class)
147148
elsif defined?(RSpec::LegacyFormatters)
148149
formatter = RSpec::LegacyFormatters.load_formatter formatter_class, *args
150+
return formatter if duplicate_formatter_exists?(formatter)
149151
@reporter.register_listener formatter, *formatter.notifications
150152
else
151153
call_site = "Formatter added at: #{::RSpec::CallerFilter.first_non_rspec_line}"
@@ -163,7 +165,7 @@ def add(formatter_to_use, *paths)
163165
WARNING
164166
return
165167
end
166-
@formatters << formatter unless duplicate_formatter_exists?(formatter)
168+
@formatters << formatter
167169
formatter
168170
end
169171

spec/rspec/core/formatters_spec.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ module RSpec::Core::Formatters
117117
before { loader.add :documentation, output }
118118

119119
it "doesn't add the formatter for the same output target" do
120+
expect(reporter).to_not receive(:register_listener)
120121
expect {
121122
loader.add :documentation, output
122123
}.not_to change { loader.formatters.length }

0 commit comments

Comments
 (0)