diff --git a/src/spectator/dsl/builder.cr b/src/spectator/dsl/builder.cr index 9a8571b..60cedb8 100644 --- a/src/spectator/dsl/builder.cr +++ b/src/spectator/dsl/builder.cr @@ -58,7 +58,7 @@ module Spectator end protected def build : ExampleGroup - root_group.build(nil, {} of Symbol => ValueWrapper) + root_group.build(nil, {} of Symbol => Internals::ValueWrapper) end end end diff --git a/src/spectator/dsl/example_factory.cr b/src/spectator/dsl/example_factory.cr index 4320b5f..8867d12 100644 --- a/src/spectator/dsl/example_factory.cr +++ b/src/spectator/dsl/example_factory.cr @@ -4,7 +4,7 @@ module Spectator def initialize(@example_type : Example.class) end - def build(group : ExampleGroup, locals : Hash(Symbol, ValueWrapper)) : Example + def build(group : ExampleGroup, locals : Hash(Symbol, Internals::ValueWrapper)) : Example @example_type.new(group, locals) end end diff --git a/src/spectator/dsl/example_group_builder.cr b/src/spectator/dsl/example_group_builder.cr index 839d1dd..fc4af51 100644 --- a/src/spectator/dsl/example_group_builder.cr +++ b/src/spectator/dsl/example_group_builder.cr @@ -37,7 +37,7 @@ module Spectator @around_each_hooks << block end - def build(parent : ExampleGroup?, locals : Hash(Symbol, ValueWrapper)) : ExampleGroup + def build(parent : ExampleGroup?, locals : Hash(Symbol, Internals::ValueWrapper)) : ExampleGroup ExampleGroup.new(@what, parent, build_hooks).tap do |group| children = @children.map do |child| child.build(group, locals).as(ExampleGroup::Child) diff --git a/src/spectator/dsl/given_example_group_builder.cr b/src/spectator/dsl/given_example_group_builder.cr index 3de65b6..6f8dddb 100644 --- a/src/spectator/dsl/given_example_group_builder.cr +++ b/src/spectator/dsl/given_example_group_builder.cr @@ -4,11 +4,11 @@ module Spectator module DSL class GivenExampleGroupBuilder < ExampleGroupBuilder - def initialize(what : String, @collection : Array(ValueWrapper), @symbol : Symbol) + def initialize(what : String, @collection : Array(Internals::ValueWrapper), @symbol : Symbol) super(what) end - def build(parent : ExampleGroup?, locals : Hash(Symbol, ValueWrapper)) : ExampleGroup + def build(parent : ExampleGroup?, locals : Hash(Symbol, Internals::ValueWrapper)) : ExampleGroup ExampleGroup.new(@what, parent, build_hooks).tap do |group| children = [] of ExampleGroup::Child @collection.each do |value| diff --git a/src/spectator/dsl/structure_dsl.cr b/src/spectator/dsl/structure_dsl.cr index b5be826..3af2a42 100644 --- a/src/spectator/dsl/structure_dsl.cr +++ b/src/spectator/dsl/structure_dsl.cr @@ -4,7 +4,7 @@ module Spectator module DSL module StructureDSL - def initialize(locals : Hash(Symbol, ::Spectator::ValueWrapper)) + def initialize(locals : Hash(Symbol, ::Spectator::Internals::ValueWrapper)) end macro describe(what, &block) @@ -37,13 +37,13 @@ module Spectator {{collection}} end - @%wrapper : ::Spectator::ValueWrapper + @%wrapper : ::Spectator::Internals::ValueWrapper def {{block.args.empty? ? "value".id : block.args.first}} - @%wrapper.as(::Spectator::TypedValueWrapper(typeof(%collection.first))).value + @%wrapper.as(::Spectator::Internals::TypedValueWrapper(typeof(%collection.first))).value end - def initialize(locals : Hash(Symbol, ::Spectator::ValueWrapper)) + def initialize(locals : Hash(Symbol, ::Spectator::Internals::ValueWrapper)) super @%wrapper = locals[:%group] end @@ -70,14 +70,14 @@ module Spectator macro let(name, &block) let!(%value) {{block}} - @%wrapper : ::Spectator::ValueWrapper? + @%wrapper : ::Spectator::Internals::ValueWrapper? def {{name.id}} if (wrapper = @%wrapper) - wrapper.unsafe_as(::Spectator::TypedValueWrapper(typeof(%value))).value + wrapper.unsafe_as(::Spectator::Internals::TypedValueWrapper(typeof(%value))).value else %value.tap do |value| - @%wrapper = ::Spectator::TypedValueWrapper(typeof(%value)).new(value) + @%wrapper = ::Spectator::Internals::TypedValueWrapper(typeof(%value)).new(value) end end end @@ -159,9 +159,9 @@ module Spectator include {{@type.id}} def {{to_a_method_name.id}} - Array(::Spectator::ValueWrapper).new.tap do |array| + Array(::Spectator::Internals::ValueWrapper).new.tap do |array| {{collection_method_name.id}}.each do |item| - array << ::Spectator::TypedValueWrapper(typeof(item)).new(item) + array << ::Spectator::Internals::TypedValueWrapper(typeof(item)).new(item) end end end @@ -173,7 +173,7 @@ module Spectator include ::Spectator::DSL::ExampleDSL include {{@type.id}} - def initialize(locals : Hash(Symbol, ::Spectator::ValueWrapper)) + def initialize(locals : Hash(Symbol, ::Spectator::Internals::ValueWrapper)) super end @@ -185,7 +185,7 @@ module Spectator private macro _spectator_example(example_class_name, wrapper_class_name, base_class, description, &block) class {{example_class_name.id}} < {{base_class.id}} - def initialize(group : ::Spectator::ExampleGroup, locals : Hash(Symbol, ::Spectator::ValueWrapper)) + def initialize(group : ::Spectator::ExampleGroup, locals : Hash(Symbol, ::Spectator::Internals::ValueWrapper)) super @instance = {{wrapper_class_name.id}}.new(locals) end diff --git a/src/spectator/example.cr b/src/spectator/example.cr index dc96495..2270fa4 100644 --- a/src/spectator/example.cr +++ b/src/spectator/example.cr @@ -6,7 +6,7 @@ module Spectator abstract def run : Result abstract def description : String - def initialize(@group, @locals = {} of Symbol => ValueWrapper) + def initialize(@group, @locals = {} of Symbol => Internals::ValueWrapper) end private getter locals diff --git a/src/spectator/internals.cr b/src/spectator/internals.cr new file mode 100644 index 0000000..642f5b6 --- /dev/null +++ b/src/spectator/internals.cr @@ -0,0 +1,6 @@ +require "./internals/*" + +module Spectator + module Internals + end +end diff --git a/src/spectator/internals/typed_value_wrapper.cr b/src/spectator/internals/typed_value_wrapper.cr new file mode 100644 index 0000000..6a3074e --- /dev/null +++ b/src/spectator/internals/typed_value_wrapper.cr @@ -0,0 +1,12 @@ +require "./value_wrapper" + +module Spectator + module Internals + class TypedValueWrapper(T) < ValueWrapper + getter value : T + + def initialize(@value : T) + end + end + end +end diff --git a/src/spectator/internals/value_wrapper.cr b/src/spectator/internals/value_wrapper.cr new file mode 100644 index 0000000..6063ed3 --- /dev/null +++ b/src/spectator/internals/value_wrapper.cr @@ -0,0 +1,11 @@ +module Spectator + module Internals + # Base class for proxying test values to examples. + # This abstraction is required for inferring types. + # The `DSL#let` macro makes heavy use of this. + abstract class ValueWrapper + # Retrieves the underlying value. + abstract def value + end + end +end diff --git a/src/spectator/typed_value_wrapper.cr b/src/spectator/typed_value_wrapper.cr deleted file mode 100644 index 6d3507f..0000000 --- a/src/spectator/typed_value_wrapper.cr +++ /dev/null @@ -1,10 +0,0 @@ -require "./value_wrapper" - -module Spectator - class TypedValueWrapper(T) < ValueWrapper - getter value : T - - def initialize(@value : T) - end - end -end diff --git a/src/spectator/value_wrapper.cr b/src/spectator/value_wrapper.cr deleted file mode 100644 index 95e294f..0000000 --- a/src/spectator/value_wrapper.cr +++ /dev/null @@ -1,9 +0,0 @@ -module Spectator - # Base class for proxying test values to examples. - # This abstraction is required for inferring types. - # The `DSL#let` macro makes heavy use of this. - abstract class ValueWrapper - # Retrieves the underlying value. - abstract def value - end -end