Method: RSpec::Core::Configuration#prepend_before

Defined in:
lib/rspec/core/configuration.rb

#prepend_before(scope = nil, *meta, &block) ⇒ void

Adds block to the start of the list of before blocks in the same scope (:example, :context, or :suite), in contrast to #before, which adds the hook to the end of the list.

See Hooks#before for full before hook docs.

This method differs from Hooks#prepend_before in only one way: it supports the :suite scope. Hooks with the :suite scope will be run once before the first example of the entire suite is executed. Conditions passed along with :suite are effectively ignored.



2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
# File 'lib/rspec/core/configuration.rb', line 2006

def prepend_before(scope=nil, *meta, &block)
  handle_suite_hook(scope, meta) do
    @before_suite_hooks.unshift Hooks::BeforeHook.new(block, {})
  end || begin
    # defeat Ruby 2.5 lazy proc allocation to ensure
    # the methods below are passed the same proc instances
    # so `Hook` equality is preserved. For more info, see:
    # https://bugs.ruby-lang.org/issues/14045#note-5
    block.__id__

    add_hook_to_existing_matching_groups(meta, scope) { |g| g.prepend_before(scope, *meta, &block) }
    super(scope, *meta, &block)
  end
end