class RSpec::Core::Example

def run(example_group_instance, reporter)

Parameters:
  • example_group_instance () -- the instance of an ExampleGroup subclass

Other tags:
    Api: - private
def run(example_group_instance, reporter)
  @example_group_instance = example_group_instance
  hooks.register_global_singleton_context_hooks(self, RSpec.configuration.hooks)
  RSpec.configuration.configure_example(self)
  RSpec.current_example = self
  start(reporter)
  Pending.mark_pending!(self, pending) if pending?
  begin
    if skipped?
      Pending.mark_pending! self, skip
    elsif !RSpec.configuration.dry_run?
      with_around_and_singleton_context_hooks do
        begin
          run_before_example
          @example_group_instance.instance_exec(self, &@example_block)
          if pending?
            Pending.mark_fixed! self
            raise Pending::PendingExampleFixedError,
                  'Expected example to fail since it is pending, but it passed.',
                  [location]
          end
        rescue Pending::SkipDeclaredInExample
          # no-op, required metadata has already been set by the `skip`
          # method.
        rescue Exception => e
          set_exception(e)
        ensure
          run_after_example
        end
      end
    end
  rescue Exception => e
    set_exception(e)
  ensure
    ExampleGroup.each_instance_variable_for_example(@example_group_instance) do |ivar|
      @example_group_instance.instance_variable_set(ivar, nil)
    end
    @example_group_instance = nil
  end
  finish(reporter)
ensure
  RSpec.current_example = nil
end