lib/yard/doctest/example.rb
#
# Generates a spec and registers it to Minitest runner.
#
Generates a spec and registers it to Minitest runner.
Generates a spec and registers it to Minitest runner .
def generate
        this = self
        Class.new(this.class).class_eval do
          require 'minitest/autorun'
          %w[. support spec].each do |dir|
            require "#{dir}/doctest_helper" if File.exist?("#{dir}/doctest_helper.rb")
          end
          return if YARD::Doctest.skips.any? { |skip| this.definition.include?(skip) }
          describe this.definition do
            example_name = if this.name.empty?
                             this.definition
                           else
                             "#{this.definition}@#{this.name}"
                           end
            register_hooks(example_name, YARD::Doctest.hooks, this)
            it this.name do
              begin
                object_name = this.definition.split(/#|\./).first
                scope = Object.const_get(object_name) if self.class.const_defined?(object_name)
              rescue NameError
              end
              global_constants = Object.constants
              scope_constants = scope.constants if scope && scope.respond_to?(:constants)
              this.asserts.each do |assert|
                expected, actual = assert[:expected], assert[:actual]
                if expected.empty?
                  evaluate_example(this, actual, scope)
                else
                  assert_example(this, expected, actual, scope)
                end
              end
              clear_extra_constants(Object, global_constants)
              clear_extra_constants(scope, scope_constants) if scope && scope.respond_to?(:constants)
            end
          end
        end
      end
def generate this = self Class . new ( this . class ) . class_eval do require 'minitest/autorun' %w[ . support spec ] . each do | dir | require "#{dir}/doctest_helper" if File . exist? ( "#{dir}/doctest_helper.rb" ) end return if YARD :: Doctest . skips . any? { | skip | this . definition . include? ( skip ) } describe this . definition do example_name = if this . name . empty? this . definition else "#{this.definition}@#{this.name}" end register_hooks ( example_name , YARD :: Doctest . hooks , this ) it this . name do begin object_name = this . definition . split ( / #| \. / ) . first scope = Object . const_get ( object_name ) if self . class . const_defined? ( object_name ) rescue NameError end global_constants = Object . constants scope_constants = scope . constants if scope && scope . respond_to? ( :constants ) this . asserts . each do | assert | expected , actual = assert [ :expected ] , assert [ :actual ] if expected . empty? evaluate_example ( this , actual , scope ) else assert_example ( this , expected , actual , scope ) end end clear_extra_constants ( Object , global_constants ) clear_extra_constants ( scope , scope_constants ) if scope && scope . respond_to? ( :constants ) end end end end
Generates a spec and registers it to Minitest runner.
Generates a spec and registers it to Minitest runner .
# Append this.name to this.definition if YARD's @example tag is followed by # descriptive text, to support hooks for multiple examples per code object.