Module: Fix::Doc Private

Defined in:
lib/fix/doc.rb

Overview

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

The Doc module serves as a central registry for storing and managing test specifications. It provides functionality for:

  • Storing specification classes in a structured way

  • Managing the lifecycle of specification documents

  • Extracting test specifications from context objects

  • Validating specification names

The module acts as a namespace for specifications, allowing them to be:

  • Registered with unique names

  • Retrieved by name when needed

  • Protected from name collisions

  • Organized in a hierarchical structure

Examples:

Registering a new specification

Fix::Doc.add(:Calculator, calculator_specification_class)

Retrieving specification contexts

contexts = Fix::Doc.fetch(:Calculator)
specifications = Fix::Doc.extract_specifications(*contexts)

Class Method Summary collapse

Class Method Details

.add(name, klass) ⇒ void

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.

This method returns an undefined value.

Registers a new specification class under the given name in the registry. The name must be a valid Ruby constant name to ensure proper namespace organization.

Examples:

Adding a new specification

class CalculatorSpec < Fix::Dsl
  # specification implementation...
end
Fix::Doc.add(:Calculator, CalculatorSpec)

Invalid name handling

# This will raise Fix::Error::InvalidSpecificationName
Fix::Doc.add(:"invalid-name", some_class)

Parameters:

  • name (Symbol)

    The name to register the specification under

  • klass (Class)

    The specification class to register

Raises:



95
96
97
98
99
# File 'lib/fix/doc.rb', line 95

def self.add(name, klass)
  const_set(name, klass)
rescue ::NameError => _e
  raise Error::InvalidSpecificationName, name
end

.extract_specifications(*contexts) ⇒ Array<Array>

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.

Extracts complete test specifications from a list of context classes. This method processes contexts to build a list of executable test specifications.

Each extracted specification contains:

  • The test environment

  • The source file location

  • The requirement level (MUST, SHOULD, or MAY)

  • The list of challenges to execute

Examples:

Extracting specifications from contexts

contexts = Fix::Doc.fetch(:Calculator)
specifications = Fix::Doc.extract_specifications(*contexts)
specifications.each do |env, location, requirement, challenges|
  # Process each specification...
end

Parameters:

  • contexts (Array<Fix::Dsl>)

    List of context classes to process

Returns:

  • (Array<Array>)

    Array of specification arrays where each contains:

    • 0

      environment [Fix::Dsl] The test environment instance

    • 1

      location [String] The test file location (“path:line”)

    • 2

      requirement [Object] The test requirement (MUST, SHOULD, or MAY)

    • 3

      challenges [Array] Array of test challenges to execute



70
71
72
73
74
# File 'lib/fix/doc.rb', line 70

def self.extract_specifications(*contexts)
  contexts.flat_map do |context|
    extract_context_specifications(context)
  end
end

.fetch(name) ⇒ Array<Fix::Dsl>

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.

Retrieves the array of test contexts associated with a named specification. These contexts define the test environment and requirements for the specification.

Examples:

Retrieving contexts for a calculator specification

contexts = Fix::Doc.fetch(:Calculator)
contexts.each do |context|
  # Process each context...
end

Parameters:

  • name (Symbol)

    The name of the specification to retrieve

Returns:

  • (Array<Fix::Dsl>)

    Array of context classes for the specification

Raises:

  • (NameError)

    If the specification name doesn’t exist in the registry



42
43
44
# File 'lib/fix/doc.rb', line 42

def self.fetch(name)
  const_get("#{name}::CONTEXTS")
end