module RSpec::Core::Hooks

def after(*args, &block)

Other tags:
    See: Configuration -
    See: SharedExampleGroup -
    See: SharedContext -
    See: ExampleGroup -
    See: #around -
    See: #before -

Parameters:
  • conditions (Hash) --
  • scope (Symbol) -- `:each`, `:all`, or `:suite` (defaults to `:each`)

Overloads:
  • after(conditions, &block)
  • after(scope, conditions, &block)
  • after(scope, &block)
  • after(&block)

Other tags:
    Api: - public
def after(*args, &block)
  register_hook :prepend, :after, *args, &block
end

def after_all_hooks_for(group)

def after_all_hooks_for(group)
  GroupHookCollection.new(hooks[:after][:all]).for(group)
end

def after_each_hooks_for(example)

def after_each_hooks_for(example)
  HookCollection.new(parent_groups.map {|a| a.hooks[:after][:each]}.flatten).for(example)
end

def append_after(*args, &block)

See #after for scoping semantics.

scope (`:each`, `:all`, or `:suite`).
Adds `block` to the back of the list of `after` blocks in the same
def append_after(*args, &block)
  register_hook :append, :after, *args, &block
end

def around(*args, &block)

Other tags:
    Note: - `:each` is the only supported scope.
    Note: - the syntax of `around` is similar to that of `before` and `after`

Other tags:
    Yield: - the example to run

Parameters:
  • conditions (Hash) --
  • scope (Symbol) -- `:each` (defaults to `:each`)

Overloads:
  • around(conditions, &block)
  • around(scope, conditions, &block)
  • around(scope, &block)
  • around(&block)

Other tags:
    Api: - public
def around(*args, &block)
  register_hook :prepend, :around, *args, &block
end

def around_each_hooks_for(example, initial_procsy=nil)

Other tags:
    Private: -
def around_each_hooks_for(example, initial_procsy=nil)
  AroundHookCollection.new(parent_groups.map {|a| a.hooks[:around][:each]}.flatten).for(example, initial_procsy)
end

def before(*args, &block)

Other tags:
    Example: before(:all) declared in an {ExampleGroup} -
    Example: before(:each) declared in an {ExampleGroup} -

Other tags:
    See: Configuration -
    See: SharedExampleGroup -
    See: SharedContext -
    See: ExampleGroup -
    See: #around -
    See: #after -

Parameters:
  • conditions (Hash) --
  • scope (Symbol) -- `:each`, `:all`, or `:suite` (defaults to `:each`)

Overloads:
  • before(conditions, &block)
  • before(scope, conditions, &block)
  • before(scope, &block)
  • before(&block)

Other tags:
    Api: - public
def before(*args, &block)
  register_hook :append, :before, *args, &block
end

def before_all_hooks_for(group)

def before_all_hooks_for(group)
  GroupHookCollection.new(hooks[:before][:all]).for(group)
end

def before_each_hooks_for(example)

def before_each_hooks_for(example)
  HookCollection.new(parent_groups.reverse.map {|a| a.hooks[:before][:each]}.flatten).for(example)
end

def extract_scope_from(args)

def extract_scope_from(args)
  if SCOPES.include?(args.first)
    args.shift
  elsif args.any? { |a| a.is_a?(Symbol) }
    raise ArgumentError.new("You must explicitly give a scope (:each, :all, or :suite) when using symbols as metadata for a hook.")
  else
    :each
  end
end

def find_hook(hook, scope, example_or_group, initial_procsy)

def find_hook(hook, scope, example_or_group, initial_procsy)
  case [hook, scope]
  when [:before, :all]
    before_all_hooks_for(example_or_group)
  when [:after, :all]
    after_all_hooks_for(example_or_group)
  when [:around, :each]
    around_each_hooks_for(example_or_group, initial_procsy)
  when [:before, :each]
    before_each_hooks_for(example_or_group)
  when [:after, :each]
    after_each_hooks_for(example_or_group)
  when [:before, :suite], [:after, :suite]
    hooks[hook][:suite].with(example_or_group)
  end
end

def hooks

Other tags:
    Private: -
def hooks
  @hooks ||= {
    :around => { :each => AroundHookCollection.new },
    :before => { :each => HookCollection.new, :all => HookCollection.new, :suite => HookCollection.new },
    :after =>  { :each => HookCollection.new, :all => HookCollection.new, :suite => HookCollection.new }
  }.extend(RegistersGlobals)
end

def prepend_before(*args, &block)

See #before for scoping semantics.

scope (`:each`, `:all`, or `:suite`).
Adds `block` to the front of the list of `before` blocks in the same
def prepend_before(*args, &block)
  register_hook :prepend, :before, *args, &block
end

def register_hook prepend_or_append, hook, *args, &block

def register_hook prepend_or_append, hook, *args, &block
  scope, options = scope_and_options_from(*args)
  hooks[hook][scope].send(prepend_or_append, HOOK_TYPES[hook].new(block, options))
end

def run_hook(hook, scope, example_or_group=ExampleGroup.new, initial_procsy=nil)

Other tags:
    Private: -
def run_hook(hook, scope, example_or_group=ExampleGroup.new, initial_procsy=nil)
  find_hook(hook, scope, example_or_group, initial_procsy).run
end

def scope_and_options_from(*args)

def scope_and_options_from(*args)
  return extract_scope_from(args), build_metadata_hash_from(args)
end