From 114bfa47c2d7b5f0e7b45fd8652c1c723fb6d206 Mon Sep 17 00:00:00 2001 From: Michael Miller Date: Fri, 9 Aug 2019 11:12:15 -0600 Subject: [PATCH] Genericize TestExpression and make value abstract This seems to resolve issues with the compiler making unions of unrelated test case types. --- src/spectator/expectations/expectation_partial.cr | 6 +++--- src/spectator/test_block.cr | 2 +- src/spectator/test_expression.cr | 4 +++- src/spectator/test_value.cr | 2 +- 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/spectator/expectations/expectation_partial.cr b/src/spectator/expectations/expectation_partial.cr index 2be1475..1cc8831 100644 --- a/src/spectator/expectations/expectation_partial.cr +++ b/src/spectator/expectations/expectation_partial.cr @@ -6,16 +6,16 @@ module Spectator::Expectations # Stores part of an expectation (obviously). # The part of the expectation this type covers is the actual value and source. # This can also cover a block's behavior. - struct ExpectationPartial + struct ExpectationPartial(T) # The actual value being tested. # This also contains its label. - getter actual : TestExpression + getter actual : TestExpression(T) # Location where this expectation was defined. getter source : Source # Creates the partial. - def initialize(@actual, @source) + def initialize(@actual : TestExpression(T), @source : Source) end # Asserts that some criteria defined by the matcher is satisfied. diff --git a/src/spectator/test_block.cr b/src/spectator/test_block.cr index 1b6d4d5..b1f1c4f 100644 --- a/src/spectator/test_block.cr +++ b/src/spectator/test_block.cr @@ -2,7 +2,7 @@ require "./test_expression" module Spectator # Captures an block from a test and its label. - struct TestBlock(ReturnType) < TestExpression + struct TestBlock(ReturnType) < TestExpression(ReturnType) # Calls the block and retrieves the value. def value : ReturnType @proc.call diff --git a/src/spectator/test_expression.cr b/src/spectator/test_expression.cr index 6ec4f27..d5e3cdd 100644 --- a/src/spectator/test_expression.cr +++ b/src/spectator/test_expression.cr @@ -1,6 +1,6 @@ module Spectator # Base type for capturing an expression from a test. - abstract struct TestExpression + abstract struct TestExpression(T) # User-friendly string displayed for the actual expression being tested. # For instance, in the expectation: # ``` @@ -15,6 +15,8 @@ module Spectator def initialize(@label) end + abstract def value : T + # String representation of the expression. def to_s(io) io << label diff --git a/src/spectator/test_value.cr b/src/spectator/test_value.cr index 3071a92..b621562 100644 --- a/src/spectator/test_value.cr +++ b/src/spectator/test_value.cr @@ -2,7 +2,7 @@ require "./test_expression" module Spectator # Captures a value from a test and its label. - struct TestValue(T) < TestExpression + struct TestValue(T) < TestExpression(T) # Actual value. getter value : T