diff --git a/src/spectator/dsl/nested_example_group_builder.cr b/src/spectator/dsl/nested_example_group_builder.cr index dfb995c..3ce071c 100644 --- a/src/spectator/dsl/nested_example_group_builder.cr +++ b/src/spectator/dsl/nested_example_group_builder.cr @@ -16,7 +16,8 @@ module Spectator::DSL # ``` # The value would be "String" for the describe block # and "with an empty string" for the context block. - def initialize(@what : String) + # Use a `Symbol` when referencing a type name. + def initialize(@what : Symbol | String) end # Builds the example group. diff --git a/src/spectator/dsl/structure_dsl.cr b/src/spectator/dsl/structure_dsl.cr index 4583ec5..d9a69b2 100644 --- a/src/spectator/dsl/structure_dsl.cr +++ b/src/spectator/dsl/structure_dsl.cr @@ -271,7 +271,15 @@ module Spectator::DSL # Start a new group. ::Spectator::DSL::Builder.start_group( - {{what.is_a?(StringLiteral) ? what : what.stringify}} + {% if what.is_a?(StringLiteral) %} + {% if what.starts_with?("#") || what.starts_with?(".") %} + {{what.id.symbolize}} + {% else %} + {{what}} + {% end %} + {% else %} + {{what.symbolize}} + {% end %} ) # Nest the block's content in the module. @@ -1487,6 +1495,11 @@ module Spectator::DSL # Retrieves the underlying, wrapped test code. getter instance + # Indicates whether the example references a method. + def symbolic? + {{what.starts_with?('#') ? true : false}} + end + # Add the block's content if one was provided. {% if block.is_a?(Block) %} {{block.body}} diff --git a/src/spectator/dummy_example.cr b/src/spectator/dummy_example.cr index f58f91f..82ddcb8 100644 --- a/src/spectator/dummy_example.cr +++ b/src/spectator/dummy_example.cr @@ -14,6 +14,11 @@ module Spectator "DUMMY" end + # Dummy symbolic flag. + def symbolic? + false + end + # Dummy source. def source Source.new(__FILE__, __LINE__) diff --git a/src/spectator/example_component.cr b/src/spectator/example_component.cr index 7814960..9c9fa95 100644 --- a/src/spectator/example_component.cr +++ b/src/spectator/example_component.cr @@ -13,5 +13,8 @@ module Spectator # Lookup the example with the specified index. abstract def [](index : Int) : Example + + # Indicates that the component references a type or method. + abstract def symbolic? : Bool end end diff --git a/src/spectator/nested_example_group.cr b/src/spectator/nested_example_group.cr index a6d82e6..c30a7d9 100644 --- a/src/spectator/nested_example_group.cr +++ b/src/spectator/nested_example_group.cr @@ -5,7 +5,8 @@ module Spectator # This group can be nested under other groups. class NestedExampleGroup < ExampleGroup # Description from the user of the group's contents. - getter what : String + # This is a symbol when referencing a type. + getter what : Symbol | String # Group that this is nested in. getter parent : ExampleGroup @@ -21,6 +22,11 @@ module Spectator super(hooks, conditions) end + # Indicates wheter the group references a type. + def symbolic? + @what.is_a?(Symbol) + end + # Runs all of the `before_all` hooks. # This should run prior to any examples in the group. # The hooks will be run only once. diff --git a/src/spectator/root_example_group.cr b/src/spectator/root_example_group.cr index c2c8566..83ee641 100644 --- a/src/spectator/root_example_group.cr +++ b/src/spectator/root_example_group.cr @@ -9,6 +9,11 @@ module Spectator "ROOT" end + # Indicates that the group is symbolic. + def symbolic? + true + end + # Does nothing. # This prevents the root group # from showing up in output.