class Tryouts::ExpectationEvaluators::ResultType
-
Clean expected/actual display focuses on type comparison
- Class resolution through evaluation allows dynamic class references
- Chose is_a? over class == for inheritance support
DESIGN DECISIONS:
- Actual display shows the actual result’s class for easy comparison
- Expected display shows the evaluated class name (e.g., “String”, “Integer”)
- Evaluates expectation content to resolve class constants (String, Array, etc.)
- Uses Ruby’s is_a? method for type checking (supports inheritance)
IMPLEMENTATION DETAILS:
“hello” #=:> Integer # Fail: String is not Integer
“hello” #=:> Object # Pass: String.is_a?(Object) - inheritance
42 #=:> Integer # Pass: Integer.is_a?(Integer)
[1, 2, 3] #=:> Array # Pass: Array.is_a?(Array)
“hello” #=:> String # Pass: String.is_a?(String)
Examples:
SYNTAX: #=:> ClassName
- Provides clean type validation for documentation-style tests
- Supports both exact class matches and inheritance (String is_a? Object)
- Validates that the test result is an instance of the expected class or its ancestors
PURPOSE:
Evaluator for result type expectations using syntax: #=:> ClassName
def self.handles?(expectation_type)
def self.handles?(expectation_type) expectation_type == :result_type end
def evaluate(actual_result = nil)
def evaluate(actual_result = nil) expectation_result = ExpectationResult.from_result(actual_result) expected_class = eval_expectation_content(@expectation.content, expectation_result) build_result( passed: actual_result.is_a?(expected_class), actual: actual_result.class, expected: expected_class, ) rescue StandardError => ex handle_evaluation_error(ex, actual_result) end