diff --git a/src/spectator.cr b/src/spectator.cr index 5391a78..d45fd13 100644 --- a/src/spectator.cr +++ b/src/spectator.cr @@ -7,6 +7,7 @@ Log.setup_from_env # Module that contains all functionality related to Spectator. module Spectator extend self + include DSL::Top # Current version of the Spectator library. VERSION = {{ `shards version #{__DIR__}`.stringify.chomp }} @@ -14,33 +15,6 @@ module Spectator # Logger for Spectator internals. Log = ::Log.for(self) - # Top-level describe method. - # All specs in a file must be wrapped in this call. - # This takes an argument and a block. - # The argument is what your spec is describing. - # It can be any Crystal expression, - # but is typically a class name or feature string. - # The block should contain all of the specs for what is being described. - # Example: - # ``` - # Spectator.describe Foo do - # # Your specs for `Foo` go here. - # end - # ``` - # NOTE: Inside the block, the `Spectator` prefix is no longer needed. - # Actually, prefixing methods and macros with `Spectator` - # most likely won't work and can cause compiler errors. - macro describe(description, &block) - class ::SpectatorTestContext - example_group({{description}}) {{block}} - end - end - - # :ditto: - macro context(description, &block) - describe({{description}}) {{block}} - end - # Flag indicating whether Spectator should automatically run tests. # This should be left alone (set to true) in typical usage. # There are times when Spectator shouldn't run tests. diff --git a/src/spectator/dsl.cr b/src/spectator/dsl.cr index f4cd763..1e46330 100644 --- a/src/spectator/dsl.cr +++ b/src/spectator/dsl.cr @@ -2,6 +2,7 @@ require "./dsl/builder" require "./dsl/examples" require "./dsl/groups" +require "./dsl/top" module Spectator # Namespace containing methods representing the spec domain specific language. diff --git a/src/spectator/dsl/top.cr b/src/spectator/dsl/top.cr new file mode 100644 index 0000000..d6682b6 --- /dev/null +++ b/src/spectator/dsl/top.cr @@ -0,0 +1,29 @@ +require "./groups" + +module Spectator::DSL + module Top + {% for method in %i[example_group describe context] %} + # Top-level describe method. + # All specs in a file must be wrapped in this call. + # This takes an argument and a block. + # The argument is what your spec is describing. + # It can be any Crystal expression, + # but is typically a class name or feature string. + # The block should contain all of the examples for what is being described. + # Example: + # ``` + # Spectator.describe Foo do + # # Your examples for `Foo` go here. + # end + # ``` + # NOTE: Inside the block, the `Spectator` prefix is no longer needed. + # Actually, prefixing methods and macros with `Spectator` + # most likely won't work and can cause compiler errors. + macro {{method.id}}(description, &block) + class ::SpectatorTestContext + {{method.id}}(\{{description}}) \{{block}} + end + end + {% end %} + end +end