rspec

package
v0.46.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 5, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExtractFailingLine

func ExtractFailingLine(filePath string, lineNumber int) string

ExtractFailingLine reads the specified line from a file

This manual extraction is necessary because RSpec's JSON output only provides the line number where the test is defined, not the actual failing assertion. We need to read the source file and find the likely failing line within the test body. This is a heuristic approach that looks for common patterns like 'expect', 'raise', etc.

func FormatFailedExamples

func FormatFailedExamples(failures []FailureDetail) string

FormatFailedExamples formats the list of failed examples for the summary

func FormatFailure

func FormatFailure(index int, failure FailureDetail) string

FormatFailure formats a single failure for display

Manual string indentation is necessary here to match RSpec's exact output format. RSpec uses specific indentation levels for different parts of the failure output: - 2 spaces for the failure number and description - 5 spaces for "Failure/Error:" label - 7 spaces for error messages and expected/actual values This precise formatting ensures compatibility with tools that parse RSpec output.

func GetFormatterPath

func GetFormatterPath(formattersPath string) (string, error)

GetFormatterPath returns the path to the JSON rows formatter, creating it in the cache directory if it doesn't exist

func NewOutputParser

func NewOutputParser() types.TestOutputParser

NewOutputParser creates a new RSpec output parser

Types

type Example

type Example struct {
	ID              string     `json:"id"`
	Description     string     `json:"description"`
	FullDescription string     `json:"full_description"`
	Status          string     `json:"status"`
	FilePath        string     `json:"file_path"`
	LineNumber      int        `json:"line_number"`
	RunTime         float64    `json:"run_time"`
	Exception       *Exception `json:"exception,omitempty"`
}

Example represents a single test example in the JSON output

type ExampleGroup

type ExampleGroup struct {
	Description string `json:"description"`
	FilePath    string `json:"file_path"`
	LineNumber  int    `json:"line_number"`
}

ExampleGroup matches the group format from the Ruby formatter

type Exception

type Exception struct {
	Class     string   `json:"class"`
	Message   string   `json:"message"`
	Backtrace []string `json:"backtrace"`
}

Exception represents failure information

type FailureDetail

type FailureDetail struct {
	Description string
	FilePath    string
	LineNumber  int
	ErrorClass  string
	Message     string
	Backtrace   []string
}

FailureDetail represents a formatted failure for display

func ExtractFailures

func ExtractFailures(examples []Example) []FailureDetail

ExtractFailures extracts failure details from RSpec examples

type JSONOutput

type JSONOutput struct {
	Version  string    `json:"version"`
	Examples []Example `json:"examples"`
	Summary  Summary   `json:"summary"`
}

JSONOutput represents the root structure of RSpec JSON output

type LoadSummary

type LoadSummary struct {
	Count    int     `json:"count"`
	LoadTime float64 `json:"load_time"`
}

LoadSummary represents the load_summary message's summary field

type StreamExample

type StreamExample struct {
	Description     string           `json:"description"`
	FullDescription string           `json:"full_description"`
	Location        string           `json:"location"`
	FilePath        string           `json:"file_path"`
	LineNumber      int              `json:"line_number"`
	Status          string           `json:"status"`
	RunTime         float64          `json:"run_time"`
	PendingMessage  string           `json:"pending_message,omitempty"`
	Exception       *StreamException `json:"exception,omitempty"`
}

StreamExample matches the example format from the Ruby formatter

type StreamException

type StreamException struct {
	Class     string   `json:"class"`
	Message   string   `json:"message"`
	Backtrace []string `json:"backtrace"`
}

StreamException matches the exception format from the Ruby formatter

type StreamingMessage

type StreamingMessage struct {
	Type            string         `json:"type"`
	Example         *StreamExample `json:"example,omitempty"`
	ExampleGroup    *ExampleGroup  `json:"group,omitempty"`
	Summary         *LoadSummary   `json:"summary,omitempty"`
	Message         string         `json:"message,omitempty"`
	FormattedOutput string         `json:"formatted_output,omitempty"`
	// dump_summary fields (flat at root level)
	ExampleCount int     `json:"example_count,omitempty"`
	FailureCount int     `json:"failure_count,omitempty"`
	PendingCount int     `json:"pending_count,omitempty"`
	ErrorCount   int     `json:"errors_outside_of_examples_count,omitempty"`
	Duration     float64 `json:"duration,omitempty"`
}

StreamingMessage represents a single PLUR_JSON line from the formatter

type Summary

type Summary struct {
	Duration      float64 `json:"duration"`
	ExampleCount  int     `json:"example_count"`
	FailureCount  int     `json:"failure_count"`
	PendingCount  int     `json:"pending_count"`
	ErrorsOutside int     `json:"errors_outside_of_examples_count"`
}

Summary represents the summary statistics

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL