Module: RSpec::Core::Hooks
Defined Under Namespace
Classes: AfterHook, AfterHooks, AroundHook, AroundHooks, BeforeHook, BeforeHooks, Hook, HookCollection
Instance Method Summary
collapse
-
#after(*args, &block) ⇒ Object
-
#around(*args, &block) ⇒ Object
-
#before(*args, &block) ⇒ Object
-
#find_hook(hook, scope, example_group_class) ⇒ Object
-
#hooks ⇒ Object
-
#run_hook(hook, scope, example_group_instance = nil) ⇒ Object
Runs all of the blocks stored with the hook in the context of the example.
-
#run_hook!(hook, scope, example_group_instance) ⇒ Object
Just like run_hook, except it removes the blocks as it evalutes them, ensuring that they will only be run once.
-
#run_hook_filtered(hook, scope, group, example_group_instance) ⇒ Object
Instance Method Details
#after(*args, &block) ⇒ Object
93
94
95
96
|
# File 'lib/rspec/core/hooks.rb', line 93
def after(*args, &block)
scope, options = scope_and_options_from(*args)
hooks[:after][scope] << AfterHook.new(options, &block)
end
|
#around(*args, &block) ⇒ Object
98
99
100
101
|
# File 'lib/rspec/core/hooks.rb', line 98
def around(*args, &block)
scope, options = scope_and_options_from(*args)
hooks[:around][scope] << AroundHook.new(options, &block)
end
|
#before(*args, &block) ⇒ Object
88
89
90
91
|
# File 'lib/rspec/core/hooks.rb', line 88
def before(*args, &block)
scope, options = scope_and_options_from(*args)
hooks[:before][scope] << BeforeHook.new(options, &block)
end
|
#find_hook(hook, scope, example_group_class) ⇒ Object
119
120
121
|
# File 'lib/rspec/core/hooks.rb', line 119
def find_hook(hook, scope, example_group_class)
hooks[hook][scope].find_hooks_for(example_group_class)
end
|
#run_hook(hook, scope, example_group_instance = nil) ⇒ Object
Runs all of the blocks stored with the hook in the context of the example. If no example is provided, just calls the hook directly.
105
106
107
|
# File 'lib/rspec/core/hooks.rb', line 105
def run_hook(hook, scope, example_group_instance=nil)
hooks[hook][scope].run_all(example_group_instance)
end
|
#run_hook!(hook, scope, example_group_instance) ⇒ Object
Just like run_hook, except it removes the blocks as it evalutes them, ensuring that they will only be run once.
111
112
113
|
# File 'lib/rspec/core/hooks.rb', line 111
def run_hook!(hook, scope, example_group_instance)
hooks[hook][scope].run_all!(example_group_instance)
end
|
#run_hook_filtered(hook, scope, group, example_group_instance) ⇒ Object
115
116
117
|
# File 'lib/rspec/core/hooks.rb', line 115
def run_hook_filtered(hook, scope, group, example_group_instance)
find_hook(hook, scope, group).run_all(example_group_instance)
end
|