Class: TestTube::Experiment Private

Inherits:
BasicObject
Defined in:
lib/test_tube/experiment.rb

Overview

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

Abstract class representing the state and result of a test experiment. This class inherits from BasicObject to provide a minimal interface and avoid any method conflicts with the objects being tested.

It provides three main attributes:

  • actual: The value being tested

  • error: Any error that occurred during the test

  • got: The boolean result of the matcher

Examples:

Examining a test result

experiment = TestTube.invoke(matcher: SomeMatcher.new, negate: false) { 42 }
experiment.actual # => 42
experiment.error  # => nil
experiment.got    # => true

Direct Known Subclasses

Invoker, Passer

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#actualObject? (readonly)

Expectation’s actual value. This represents the value that was actually produced during the test, whether it came from a direct value (Passer) or a block execution (Invoker).

Returns:

  • (Object)

    The actual value being tested

  • (nil)

    If an error occurred during the test



29
30
31
# File 'lib/test_tube/experiment.rb', line 29

def actual
  @actual
end

#errorException? (readonly)

Expectation’s raised error. Stores any exception that occurred during the test execution, including system-level exceptions (SystemExit, SignalException, etc.) when using Invoker.

Returns:

  • (Exception, nil)

    Any error that occurred during the test



39
40
41
# File 'lib/test_tube/experiment.rb', line 39

def error
  @error
end

#gotBoolean? (readonly)

Expectation’s returned boolean value. The result of applying the matcher to the actual value. Will be nil if an error occurred during the test.

Returns:

  • (Boolean)

    true if the matcher matched (considering negate)

  • (nil)

    if an error occurred during the test



49
50
51
# File 'lib/test_tube/experiment.rb', line 49

def got
  @got
end

Instance Method Details

#inspectString Also known as: to_s

A string containing a human-readable representation of the experiment. Useful for debugging and logging test results.

Examples:

experiment.inspect
# => "<TestTube actual=42 error=nil got=true>"

Returns:

  • (String)

    Human-readable representation of the experiment



61
62
63
# File 'lib/test_tube/experiment.rb', line 61

def inspect
  "<TestTube actual=#{actual.inspect} error=#{error.inspect} got=#{got.inspect}>"
end