-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2917ebc
commit 4fb6df6
Showing
4 changed files
with
66 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |