Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

refactor: move some hooks behavior to Hooks module

  • Loading branch information...
commit 0592acad14b606c195c21b5eee347d5a41de3813 1 parent 7bfe871
@dchelimsky dchelimsky authored
Showing with 21 additions and 14 deletions.
  1. +1 −13 lib/rspec/core/example_group.rb
  2. +20 −1 lib/rspec/core/hooks.rb
View
14 lib/rspec/core/example_group.rb
@@ -289,19 +289,7 @@ def self.set_it_up(*args)
args.unshift(symbol_description) if symbol_description
@metadata = RSpec::Core::Metadata.new(superclass_metadata).process(*args)
world.configure_group(self)
- [:before, :after, :around].each do |_when|
- RSpec.configuration.hooks[_when][:each].each do |hook|
- unless ancestors.any? {|a| a.hooks[_when][:each].include? hook }
- hooks[_when][:each] << hook # each's get filtered later per example
- end
- end
- next if _when == :around # no around(:all) hooks
- RSpec.configuration.hooks[_when][:all].each do |hook|
- unless ancestors.any? {|a| a.hooks[_when][:all].include? hook }
- hooks[_when][:all] << hook if hook.options_apply?(self)
- end
- end
- end
+ hooks.register_globals(self, RSpec.configuration.hooks)
end
# @private
View
21 lib/rspec/core/hooks.rb
@@ -96,13 +96,32 @@ def run
end
end
+ module RegistersGlobals
+ def register_globals host, globals
+ [:before, :after, :around].each do |position|
+ process host, globals, position, :each
+ next if position == :around # no around(:all) hooks
+ process host, globals, position, :all
+ end
+ end
+
+ private
+ def process host, globals, position, scope
+ globals[position][scope].each do |hook|
+ unless host.ancestors.any? { |a| a.hooks[position][scope].include? hook }
+ self[position][scope] << hook if scope == :each || hook.options_apply?(host)
+ end
+ end
+ end
+ end
+
# @private
def hooks
@hooks ||= {
:around => { :each => AroundHookCollection.new },
:before => { :each => [], :all => [], :suite => HookCollection.new },
:after => { :each => [], :all => [], :suite => HookCollection.new }
- }
+ }.extend(RegistersGlobals)
end
# @api public
Please sign in to comment.
Something went wrong with that request. Please try again.