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
  RSpec.current_example = self
  start(reporter)
  begin
    if skipped?
      Pending.mark_pending! self, skip
    elsif !RSpec.configuration.dry_run?
      with_around_example_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
    @example_group_instance.instance_variables.each do |ivar|
      @example_group_instance.instance_variable_set(ivar, nil)
    end
    @example_group_instance = nil
  end
  finish(reporter)
ensure
  RSpec.current_example = nil
end