diff --git a/src/spectator/matchers/alternative_value.cr b/src/spectator/matchers/alternative_value.cr index a094ea7..a2b8103 100644 --- a/src/spectator/matchers/alternative_value.cr +++ b/src/spectator/matchers/alternative_value.cr @@ -2,9 +2,6 @@ module Spectator::Matchers # Selects a value based on whether the value is negated. # This is used when a matcher is negated. private class AlternativeValue(T1, T2) - # Negatable value. - getter value - # Creates the wrapper. def initialize(@value1 : T1, @value2 : T2) @negated = false @@ -15,14 +12,19 @@ module Spectator::Matchers @negated = !@negated end + # Returns the correct value based on the negated status. + def value + @negated ? @value1 : @value2 + end + # Produces a stringified value. def to_s(io) - io << @negated ? @value1 : @value2 + io << value end # Produces a stringified value with additional information. def inspect(io) - (@negated ? @value1 : @value2).inspect(io) + value.inspect(io) end end end diff --git a/src/spectator/matchers/negatable_prefixed_value.cr b/src/spectator/matchers/negatable_prefixed_value.cr index b8d41a9..71106e0 100644 --- a/src/spectator/matchers/negatable_prefixed_value.cr +++ b/src/spectator/matchers/negatable_prefixed_value.cr @@ -2,6 +2,9 @@ module Spectator::Matchers # Wraps a prefixed value that can be negated. # This is used when a matcher is negated. private class NegatablePrefixedValue(T) + # Negatable value. + getter value + # Creates the wrapper. def initialize(@positive_prefix : String, @negative_prefix : String, @value : T) @negated = false @@ -12,15 +15,20 @@ module Spectator::Matchers @negated = !@negated end + # Returns the correct prefix based on the negated status. + private def prefix + @negated ? @negative_prefix : @positive_prefix + end + # Produces a stringified value. def to_s(io) - io << @negated ? @negative_prefix : @positive_prefix + io << prefix io << @value end # Produces a stringified value with additional information. def inspect(io) - io << @negated ? @negative_prefix : @positive_prefix + io << prefix @value.inspect(io) end end