Module: Expresenter

Defined in:
lib/expresenter.rb,
lib/expresenter/fail.rb,
lib/expresenter/pass.rb,
lib/expresenter/common.rb

Overview

Namespace for the Expresenter library.

The Expresenter library provides a flexible way to present test expectation results with rich formatting and requirement level support. It is designed to work with test frameworks and assertion libraries that need detailed result reporting.

Each expectation result can be categorized as:

  • Success: The test passed as expected

  • Warning: A non-critical test failure (typically for :SHOULD or :MAY requirements)

  • Info: Additional information about the test

  • Failure: A critical test failure

  • Error: An unexpected error occurred during the test

Examples:

Creating a passing expectation result

result = Expresenter.call(true).with(
  actual: "FOO",
  definition: 'eql "foo"',
  error: nil,
  got: true,
  negate: true,
  level: :MUST
)
result.passed? # => true
result.to_s # => "Success: expected \"FOO\" not to eql \"foo\"."

Creating a failing expectation result

# This will raise an Expresenter::Fail exception
Expresenter.call(false).with(
  actual: "foo",
  definition: "eq 42",
  error: Exception.new("Test failed"),
  got: false,
  negate: false,
  level: :MUST
)

Defined Under Namespace

Modules: Common Classes: Fail, Pass

Class Method Summary collapse

Class Method Details

.call(is_passed) ⇒ Class<Pass>, Class<Fail>

Factory method that returns the appropriate result class based on the assertion outcome.

Examples:

Getting a Pass class for a successful test

result_class = Expresenter.call(true)
result_class # => Expresenter::Pass

Getting a Fail class for a failed test

result_class = Expresenter.call(false)
result_class # => Expresenter::Fail

Parameters:

  • is_passed (Boolean)

    The value of the assertion. True indicates a passing test, false indicates a failing test.

Returns:

  • (Class<Pass>, Class<Fail>)

    Returns the Pass class for passing tests or the Fail class for failing tests. These classes can then be instantiated with detailed test information using #with.



57
58
59
# File 'lib/expresenter.rb', line 57

def self.call(is_passed)
  is_passed ? Pass : Fail
end