Class: SpecForge::Forge

Inherits:
Object
  • Object
show all
Defined in:
lib/spec_forge/forge.rb,
lib/spec_forge/forge/hooks.rb,
lib/spec_forge/forge/timer.rb,
lib/spec_forge/forge/action.rb,
lib/spec_forge/forge/runner.rb,
lib/spec_forge/forge/context.rb,
lib/spec_forge/forge/display.rb,
lib/spec_forge/forge/callbacks.rb,
lib/spec_forge/forge/variables.rb,
lib/spec_forge/forge/actions/call.rb,
lib/spec_forge/forge/actions/debug.rb,
lib/spec_forge/forge/actions/store.rb,
lib/spec_forge/forge/actions/expect.rb,
lib/spec_forge/forge/actions/request.rb,
lib/spec_forge/forge/runner/array_io.rb,
lib/spec_forge/forge/runner/reporter.rb,
lib/spec_forge/forge/runner/header_validator.rb,
lib/spec_forge/forge/runner/schema_validator.rb,
lib/spec_forge/forge/runner/content_validator.rb

Overview

The main execution engine for running blueprints

Forge orchestrates the execution of blueprints by managing the execution context, HTTP client, variable storage, and display output. It processes each step sequentially and tracks statistics across the run.

Defined Under Namespace

Classes: Action, Call, Callbacks, Context, Debug, Display, Expect, Hooks, Request, Runner, Store, Timer, Variables

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(blueprints, verbosity_level: 0, hooks: {}) ⇒ Forge

Creates a new Forge instance with the specified blueprints

Parameters:

  • blueprints (Array<Blueprint>)

    The blueprints to execute

  • verbosity_level (Integer) (defaults to: 0)

    Output verbosity (0-3)

  • hooks (Hash) (defaults to: {})

    Forge-level event hooks



117
118
119
120
121
122
123
124
125
126
127
128
129
130
# File 'lib/spec_forge/forge.rb', line 117

def initialize(blueprints, verbosity_level: 0, hooks: {})
  @blueprints = blueprints
  @callbacks = Callbacks.new
  @display = Display.new(verbosity_level:)
  @failures = []
  @hooks = Step::Call.wrap_hooks(hooks)
  @http_client = HTTP::Client.new
  @runner = Runner.new
  @stats = {}
  @timer = Timer.new
  @variables = Variables.new(static: SpecForge.configuration.global_variables)

  reset_stats
end

Instance Attribute Details

#blueprintsArray<Blueprint> (readonly)

Returns The blueprints being executed.

Returns:



79
80
81
# File 'lib/spec_forge/forge.rb', line 79

def blueprints
  @blueprints
end

#callbacksCallbacks (readonly)

Returns Callback registry for this forge run.

Returns:

  • (Callbacks)

    Callback registry for this forge run



82
83
84
# File 'lib/spec_forge/forge.rb', line 82

def callbacks
  @callbacks
end

#displayDisplay (readonly)

Returns Display handler for output formatting.

Returns:

  • (Display)

    Display handler for output formatting



85
86
87
# File 'lib/spec_forge/forge.rb', line 85

def display
  @display
end

#failuresArray<Hash> (readonly)

Returns List of failed expectations.

Returns:

  • (Array<Hash>)

    List of failed expectations



88
89
90
# File 'lib/spec_forge/forge.rb', line 88

def failures
  @failures
end

#hooksHash{Symbol => Array<Step::Call>} (readonly)

Returns Forge-level before and after hooks.

Returns:

  • (Hash{Symbol => Array<Step::Call>})

    Forge-level before and after hooks



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

def hooks
  @hooks
end

#http_clientHTTP::Client (readonly)

Returns HTTP client for making requests.

Returns:



94
95
96
# File 'lib/spec_forge/forge.rb', line 94

def http_client
  @http_client
end

#runnerRunner (readonly)

Returns RSpec runner for executing expectations.

Returns:

  • (Runner)

    RSpec runner for executing expectations



97
98
99
# File 'lib/spec_forge/forge.rb', line 97

def runner
  @runner
end

#statsHash (readonly)

Returns Statistics about the current run.

Returns:

  • (Hash)

    Statistics about the current run



100
101
102
# File 'lib/spec_forge/forge.rb', line 100

def stats
  @stats
end

#timerTimer (readonly)

Returns Timer for tracking execution duration.

Returns:

  • (Timer)

    Timer for tracking execution duration



103
104
105
# File 'lib/spec_forge/forge.rb', line 103

def timer
  @timer
end

#variablesVariables (readonly)

Returns Variable storage for the current run.

Returns:

  • (Variables)

    Variable storage for the current run



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

def variables
  @variables
end

Class Method Details

.contextContext?

Returns the current execution context for the current thread

Returns:

  • (Context, nil)

    The current context or nil if not executing



44
45
46
# File 'lib/spec_forge/forge.rb', line 44

def context
  Thread.current[:spec_forge_context]
end

.igniteClass

Initializes SpecForge by loading the forge_helper and factories

Returns:

  • (Class)

    self for chaining



18
19
20
21
22
23
24
# File 'lib/spec_forge/forge.rb', line 18

def ignite
  load_forge_helper
  Factory.load_and_register

  # Return for chaining
  self
end

.run(blueprints) ⇒ void

This method returns an undefined value.

Creates and runs a new Forge instance with the given blueprints

Parameters:

  • blueprints (Array<Blueprint>)

    The blueprints to execute

  • verbosity_level (Hash)

    a customizable set of options

  • hooks (Hash)

    a customizable set of options



35
36
37
# File 'lib/spec_forge/forge.rb', line 35

def run(blueprints, **)
  new(blueprints, **).run
end

.with_context(context) { ... } ⇒ Object

Executes a block with a given context

Parameters:

  • context (Context)

    The context to use during execution

Yields:

  • Block to execute with the context

Returns:

  • (Object)

    The result of the block



57
58
59
60
61
62
63
# File 'lib/spec_forge/forge.rb', line 57

def with_context(context)
  old_context = Thread.current[:spec_forge_context]
  Thread.current[:spec_forge_context] = context
  yield
ensure
  Thread.current[:spec_forge_context] = old_context
end

Instance Method Details

#runvoid

This method returns an undefined value.

Executes all blueprints and their steps



137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
# File 'lib/spec_forge/forge.rb', line 137

def run
  context = Context.new(variables:)

  Forge.with_context(context) do
    forge_start

    @blueprints.each do |blueprint|
      blueprint_start(blueprint)

      blueprint.steps.each do |step|
        step_start(blueprint, step)
        step_action(blueprint, step)
        step_end(blueprint, step)
      rescue => e
        step_end(blueprint, step, error: e)
        break
      end

      blueprint_end(blueprint)
    end
  ensure
    forge_end
  end
end