mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Initial implementation of one-liner "it" syntax
This commit is contained in:
parent
0c3b3da2b3
commit
033f753dca
1 changed files with 19 additions and 1 deletions
|
@ -1052,9 +1052,27 @@ module Spectator::DSL
|
|||
#
|
||||
# See `ExampleDSL` and `MatcherDSL` for additional macros and methods
|
||||
# that can be used in example code blocks.
|
||||
#
|
||||
# A short-hand, one-liner syntax can also be used.
|
||||
# Typically, this is combined with `#subject`.
|
||||
# For instance:
|
||||
# ```
|
||||
# subject { 1 + 2 }
|
||||
# it is_expected.to eq(3)
|
||||
# ```
|
||||
macro it(what, &block)
|
||||
# Create the wrapper class for the test code.
|
||||
_spectator_example_wrapper(Wrapper%example, %run) {{block}}
|
||||
{% if block.is_a?(Nop) %}
|
||||
{% if what.is_a?(Call) %}
|
||||
_spectator_example_wrapper(Wrapper%example, %run) do
|
||||
{{what}}
|
||||
end
|
||||
{% else %}
|
||||
{% raise "Unrecognized syntax: `it #{what}`" %}
|
||||
{% end %}
|
||||
{% else %}
|
||||
_spectator_example_wrapper(Wrapper%example, %run) {{block}}
|
||||
{% end %}
|
||||
|
||||
# Create a class derived from `RunnableExample` to run the test code.
|
||||
_spectator_example(Example%example, Wrapper%example, ::Spectator::RunnableExample, {{what}}) do
|
||||
|
|
Loading…
Reference in a new issue