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

Prevent formater loader registering duplicate listeners #1990

Merged
merged 1 commit into from
Jun 12, 2015

Conversation

JonRowe
Copy link
Member

@JonRowe JonRowe commented Jun 11, 2015

Fixes #1987

JonRowe added a commit that referenced this pull request Jun 11, 2015
@JonRowe JonRowe force-pushed the fix_duplicate_formatters branch from fb323b5 to 87dfa07 Compare June 11, 2015 05:03
@JonRowe
Copy link
Member Author

JonRowe commented Jun 11, 2015

Ping @myronmarston

@reporter.register_listener formatter, *notifications_for(formatter_class)
elsif defined?(RSpec::LegacyFormatters)
formatter = RSpec::LegacyFormatters.load_formatter formatter_class, *args
return formatter if duplicate_formatter_exists?(formatter)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You've got two return statements here but only one spec. Presumably only one of them is tested? Would it be easy to add a test for the other branch?

Alternately (or maybe in addition...), there's duplication here, and it's definitely duplicated knowledge. Instead of return formatter if ...; @reporter.register_listener, WDYT about extracting a private register_listener helper method that would do the duplicate_formatter_exists? check and then call @reporter.register_listener? I'd feel better about having a spec for only one of these branches if they were going through a shared helper method.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@JonRowe JonRowe force-pushed the fix_duplicate_formatters branch from 87dfa07 to 1218273 Compare June 11, 2015 23:51
@@ -163,7 +163,6 @@ def add(formatter_to_use, *paths)
WARNING
return
end
@formatters << formatter unless duplicate_formatter_exists?(formatter)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that we no longer mutate @formatter after the if/elseif/else/end block, should we remove the return on line 164?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, done

@myronmarston
Copy link
Member

LGTM

@JonRowe JonRowe force-pushed the fix_duplicate_formatters branch from 1218273 to 4455319 Compare June 12, 2015 00:03
@myronmarston
Copy link
Member

Merge when green.

myronmarston added a commit that referenced this pull request Jun 12, 2015
Prevent formater loader registering duplicate listeners
@myronmarston myronmarston merged commit b5c37e5 into master Jun 12, 2015
@myronmarston myronmarston deleted the fix_duplicate_formatters branch June 12, 2015 06:12
MatheusRich pushed a commit to MatheusRich/rspec-core that referenced this pull request Oct 30, 2020
Prevent formater loader registering duplicate listeners
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants