Class: SpecForge::Forge::Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/spec_forge/forge/runner.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

Executes expectations using RSpec as the underlying test framework

Runner wraps RSpec to run individual expectation blocks, capturing results and formatting them for display. It creates isolated RSpec example groups for each expectation.

Defined Under Namespace

Classes: ArrayIO, ContentValidator, HeaderValidator, Reporter, SchemaValidator

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cli_args = []) ⇒ Runner

Creates a new RSpec runner with the specified CLI arguments

Parameters:

  • cli_args (Array<String>) (defaults to: [])

    Command line arguments for RSpec configuration



26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/spec_forge/forge/runner.rb', line 26

def initialize(cli_args = [])
  options = RSpec::Core::ConfigurationOptions.new(cli_args)

  @configuration = RSpec.configuration.deep_dup
  @configuration.reset

  @world = RSpec::Core::World.new
  @runner = RSpec::Core::Runner.new(options, @configuration, @world)

  @output_io = ArrayIO.new
  @error_io = StringIO.new
  @runner.configure(@error_io, @output_io)
end

Instance Attribute Details

#error_ioStringIO (readonly)

Returns Error stream for RSpec formatter.

Returns:

  • (StringIO)

    Error stream for RSpec formatter



17
18
19
# File 'lib/spec_forge/forge/runner.rb', line 17

def error_io
  @error_io
end

#output_ioArrayIO (readonly)

Returns Output stream for RSpec formatter.

Returns:

  • (ArrayIO)

    Output stream for RSpec formatter



14
15
16
# File 'lib/spec_forge/forge/runner.rb', line 14

def output_io
  @output_io
end

Instance Method Details

#run(forge, step, expectation) ⇒ Array<Hash>

Runs an expectation and returns any failed examples

Parameters:

  • forge (Forge)

    The forge instance

  • step (Step)

    The current step

  • expectation (Step::Expect)

    The expectation to run

Returns:

  • (Array<Hash>)

    List of failed examples (empty if all passed)



49
50
51
52
53
54
55
56
# File 'lib/spec_forge/forge/runner.rb', line 49

def run(forge, step, expectation)
  configure_formatters(forge)

  @runner.run_specs([create_example_group(forge, step, expectation)])

  entry = @output_io.entries.last.to_h
  entry[:examples].reject { |ex| ex[:status] == "passed" }
end