Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
icy-arctic-fox committed Jun 24, 2024
1 parent 2917ebc commit 4fb6df6
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 30 deletions.
21 changes: 8 additions & 13 deletions src/spectator/core/context.cr
Original file line number Diff line number Diff line change
@@ -1,20 +1,15 @@
require "./dsl"
require "./hooks"
require "./example"
require "./memoization"
require "./methods"

module Spectator::Core
module Context
include DSL
include Hooks

abstract def context(description, &)

def describe(description, &)
context(description) { with self yield self }
end

abstract def specify(description, &block : Example ->) : Example

def it(description, &block : Example ->) : Example
specify(description, &block)
end
include Memoization
include Methods
end
end

Spectator.def_example_alias(:it)
23 changes: 23 additions & 0 deletions src/spectator/core/dsl.cr
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
module Spectator
EXAMPLE_ALIASES = [] of Nil

macro def_example_alias(name)
{% EXAMPLE_ALIASES << name %}
end

module Core
module DSL
macro finished
{% for example_alias in EXAMPLE_ALIASES %}
macro {{example_alias.id}}(description, &block)
{% verbatim do %}
specify({{description}}) do {% if !block.args.empty? %} |{{block.args.splat}}| {% end %}
{{yield}}
end
{% end %}
end
{% end %}
end
end
end
end
21 changes: 21 additions & 0 deletions src/spectator/core/memoization.cr
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
module Spectator::Core
def self.null_value(type : T.class) : T forall T
value = uninitialized T
end

module Memoization
macro let(name, &block)
%block = -> do
{{yield}}
end

{{name.id}} = ::Spectator::Core.null_value(typeof(%block.call))

before_each do # TODO: Ensure hook is called before all others.
{{name.id}} = %block.call
end

{% debug %}
end
end
end
31 changes: 14 additions & 17 deletions src/spectator/core/methods.cr
Original file line number Diff line number Diff line change
@@ -1,26 +1,23 @@
require "./example"

module Spectator::Core
module Methods
def context(description : String, &)
example_group = ExampleGroup.new(description)
Spectator.current_example_group.push(example_group) do
with self yield
end
end
abstract def context(description, &)

def describe(description : String, &)
context(description) { yield }
def describe(description, &)
context(description) { with self yield self }
end

def it(description : String)
end
abstract def specify(description, &block : Example ->) : Example

def it(description : String, & : Example ->)
end
# def it(description, &block : Example ->) : Example
# specify(description, &block)
# end

def pending(description : String)
end

def pending(description : String, & : Example ->)
end
# macro it(description, &block)
# specify({{description}}) do {% if !block.args.empty? %} |{{block.args.splat}}| {% end %}
# {{yield}}
# end
# end
end
end

0 comments on commit 4fb6df6

Please sign in to comment.