Move top-level DSL to its own module

This commit is contained in:
Michael Miller 2020-10-17 22:57:27 -06:00
parent 87c8914187
commit c36e006c85
No known key found for this signature in database
GPG key ID: F9A0C5C65B162436
3 changed files with 31 additions and 27 deletions

View file

@ -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.

29
src/spectator/dsl/top.cr Normal file
View file

@ -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