Module: YardExampleTest

Defined in:
lib/yard_example_test.rb,
lib/yard_example_test/rake.rb,
lib/yard_example_test/example.rb,
lib/yard_example_test/version.rb,
lib/yard_example_test/expectation.rb,
lib/yard_example_test/example/evaluator.rb,
lib/yard_example_test/example/comparison.rb,
lib/yard_example_test/example/constant_sandbox.rb

Overview

Provides configuration and hooks for running YARD @example tags as tests.

Defined Under Namespace

Classes: Example, Expectation, RakeTask

Constant Summary collapse

VERSION =

The current gem version

Returns:

  • (String)

    the current gem version.

'0.2.0'

Class Method Summary collapse

Class Method Details

.after(test = nil, &blk)

This method returns an undefined value.

Registers a block to be called after each example, or after a specific test

The block is evaluated in the same context as the example.

Examples:

Register a global after hook

YardExampleTest.after { puts 'done' }

Register a hook for a specific test

YardExampleTest.after('#my_method') { puts 'my_method done' }

Parameters:

  • test (String, nil) (defaults to: nil)

    the test name to match, or +nil+ for all tests

  • blk (Proc)

    the block to call after the matched example(s)



75
76
77
# File 'lib/yard_example_test.rb', line 75

def self.after(test = nil, &blk)
  hooks[:after] << { test: test, block: blk }
end

.after_run

This method returns an undefined value.

Registers a block to be called after all examples have run

The block is evaluated in a different context from the examples. Delegates to +Minitest.after_run+.

Examples:

YardExampleTest.after_run { puts 'All examples finished' }


91
92
93
# File 'lib/yard_example_test.rb', line 91

def self.after_run(&)
  Minitest.after_run(&)
end

.before(test = nil, &blk)

This method returns an undefined value.

Registers a block to be called before each example, or before a specific test

The block is evaluated in the same context as the example.

Examples:

Register a global before hook

YardExampleTest.before { @value = 1 }

Register a hook for a specific test

YardExampleTest.before('#my_method') { @value = 42 }

Parameters:

  • test (String, nil) (defaults to: nil)

    the test name to match, or +nil+ for all tests

  • blk (Proc)

    the block to call before the matched example(s)



53
54
55
# File 'lib/yard_example_test.rb', line 53

def self.before(test = nil, &blk)
  hooks[:before] << { test: test, block: blk }
end

.configure {|self| ... }

This method returns an undefined value.

Configures YardExampleTest

Examples:

YardExampleTest.configure do |runner|
  runner.before { @value = 1 }
  runner.after { puts 'done' }
end

Yields:

  • (self)

    gives the module itself to the block for configuration



31
32
33
# File 'lib/yard_example_test.rb', line 31

def self.configure
  yield self
end

.hooksHash{Symbol => Array<Hash>}

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns the hash of registered before/after hooks

Returns:

  • (Hash{Symbol => Array<Hash>})

    the registered hooks grouped by type



126
127
128
129
130
131
# File 'lib/yard_example_test.rb', line 126

def self.hooks
  @hooks ||= {}.tap do |hash|
    hash[:before] = []
    hash[:after] = []
  end
end

.skip(test)

This method returns an undefined value.

Registers a test definition to be skipped

Examples:

YardExampleTest.skip '#my_method'

Parameters:

  • test (String)

    the test name or definition path to skip



106
107
108
# File 'lib/yard_example_test.rb', line 106

def self.skip(test)
  skips << test
end

.skipsArray<String>

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns the array of test definitions registered to be skipped

Returns:

  • (Array<String>)

    the registered skip patterns



116
117
118
# File 'lib/yard_example_test.rb', line 116

def self.skips
  @skips ||= []
end