This repository was archived by the owner on Nov 30, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 753
Fix adding config hooks to existing example groups #2280
Merged
myronmarston
merged 2 commits into
rspec:master
from
eugeneius:fix_adding_hooks_to_existing_groups
Jul 6, 2016
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1749,7 +1749,8 @@ def before(scope=nil, *meta, &block) | |
handle_suite_hook(scope, meta) do | ||
@before_suite_hooks << Hooks::BeforeHook.new(block, {}) | ||
end || begin | ||
on_existing_matching_groups({}) { |g| g.before(scope, *meta, &block) } | ||
metadata = Metadata.build_hash_from(meta.dup) | ||
on_existing_matching_groups(metadata, scope) { |g| g.before(scope, *meta, &block) } | ||
super(scope, *meta, &block) | ||
end | ||
end | ||
|
@@ -1772,7 +1773,8 @@ def prepend_before(scope=nil, *meta, &block) | |
handle_suite_hook(scope, meta) do | ||
@before_suite_hooks.unshift Hooks::BeforeHook.new(block, {}) | ||
end || begin | ||
on_existing_matching_groups({}) { |g| g.prepend_before(scope, *meta, &block) } | ||
metadata = Metadata.build_hash_from(meta.dup) | ||
on_existing_matching_groups(metadata, scope) { |g| g.prepend_before(scope, *meta, &block) } | ||
super(scope, *meta, &block) | ||
end | ||
end | ||
|
@@ -1790,7 +1792,8 @@ def after(scope=nil, *meta, &block) | |
handle_suite_hook(scope, meta) do | ||
@after_suite_hooks.unshift Hooks::AfterHook.new(block, {}) | ||
end || begin | ||
on_existing_matching_groups({}) { |g| g.after(scope, *meta, &block) } | ||
metadata = Metadata.build_hash_from(meta.dup) | ||
on_existing_matching_groups(metadata, scope) { |g| g.after(scope, *meta, &block) } | ||
super(scope, *meta, &block) | ||
end | ||
end | ||
|
@@ -1813,7 +1816,8 @@ def append_after(scope=nil, *meta, &block) | |
handle_suite_hook(scope, meta) do | ||
@after_suite_hooks << Hooks::AfterHook.new(block, {}) | ||
end || begin | ||
on_existing_matching_groups({}) { |g| g.append_after(scope, *meta, &block) } | ||
metadata = Metadata.build_hash_from(meta.dup) | ||
on_existing_matching_groups(metadata, scope) { |g| g.append_after(scope, *meta, &block) } | ||
super(scope, *meta, &block) | ||
end | ||
end | ||
|
@@ -1822,8 +1826,8 @@ def append_after(scope=nil, *meta, &block) | |
# | ||
# See {Hooks#around} for full `around` hook docs. | ||
def around(scope=nil, *meta, &block) | ||
on_existing_matching_groups({}) { |g| g.around(scope, *meta, &block) } | ||
|
||
metadata = Metadata.build_hash_from(meta.dup) | ||
on_existing_matching_groups(metadata, scope) { |g| g.around(scope, *meta, &block) } | ||
super(scope, *meta, &block) | ||
end | ||
|
||
|
@@ -2027,9 +2031,18 @@ def configure_group_with(group, module_list, application_method) | |
end | ||
end | ||
|
||
def on_existing_matching_groups(meta) | ||
world.all_example_groups.each do |group| | ||
yield group if meta.empty? || MetadataFilter.apply?(:any?, meta, group.metadata) | ||
def on_existing_matching_groups(meta, scope=:ignore) | ||
groups = world.example_groups.dup | ||
|
||
until groups.empty? | ||
group = groups.shift | ||
|
||
if scope == :example || scope == :each || scope.nil? || | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This duplicates some very specific hook-related logic:
In the previous implementation this logic were still duplicated, but at least it was still in the |
||
meta.empty? || MetadataFilter.apply?(:any?, meta, group.metadata) | ||
yield group | ||
else | ||
groups.concat(group.children) | ||
end | ||
end | ||
end | ||
|
||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hooks have some scope-specific behaviour, but helper modules don't have a scope - the optional argument feels ugly.