mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Add context instances
This commit is contained in:
parent
65da494e52
commit
387e129a89
5 changed files with 30 additions and 6 deletions
|
@ -4,7 +4,7 @@ require "./spectator/*"
|
|||
module Spectator
|
||||
VERSION = "0.1.0"
|
||||
|
||||
ALL_EXAMPLES = [] of Example
|
||||
ROOT_CONTEXT = Context.new
|
||||
|
||||
macro describe(what, source_file = __FILE__, source_line = __LINE__, &block)
|
||||
module Spectator
|
||||
|
@ -15,6 +15,6 @@ module Spectator
|
|||
end
|
||||
|
||||
at_exit do
|
||||
Runner.new(ALL_EXAMPLES).run
|
||||
Runner.new(ROOT_CONTEXT).run
|
||||
end
|
||||
end
|
||||
|
|
20
src/spectator/context.cr
Normal file
20
src/spectator/context.cr
Normal file
|
@ -0,0 +1,20 @@
|
|||
require "./example"
|
||||
|
||||
module Spectator
|
||||
class Context
|
||||
getter examples = [] of Example
|
||||
getter contexts = [] of Context
|
||||
|
||||
def all_examples
|
||||
add_examples
|
||||
end
|
||||
|
||||
protected def add_examples(array = [] of Example)
|
||||
array.concat(@examples)
|
||||
contexts.each do |context|
|
||||
context.add_examples(array)
|
||||
end
|
||||
array
|
||||
end
|
||||
end
|
||||
end
|
|
@ -14,6 +14,9 @@ module Spectator
|
|||
module {{module_name.id}}
|
||||
include ::Spectator::DSL
|
||||
|
||||
CURRENT_CONTEXT = ::Spectator::Context.new
|
||||
{{context_module.id}}::CURRENT_CONTEXT.contexts << CURRENT_CONTEXT
|
||||
|
||||
CONTEXT_MODULE = {{context_module.id}}::{{module_name.id}}
|
||||
GIVEN_VARIABLES = [
|
||||
{{ parent_given_vars.join(", ").id }}
|
||||
|
@ -55,14 +58,14 @@ module Spectator
|
|||
end
|
||||
|
||||
{% if given_vars.empty? %}
|
||||
::Spectator::ALL_EXAMPLES << {{class_name.id}}.new
|
||||
CURRENT_CONTEXT.examples << {{class_name.id}}.new
|
||||
{% else %}
|
||||
{% for given_var in given_vars %}
|
||||
{% var_name = given_var[0] %}
|
||||
{% collection = given_var[1] %}
|
||||
{{collection}}.each do |{{var_name}}|
|
||||
{% end %}
|
||||
::Spectator::ALL_EXAMPLES << {{class_name.id}}.new({{var_names.join(", ").id}})
|
||||
CURRENT_CONTEXT.examples << {{class_name.id}}.new({{var_names.join(", ").id}})
|
||||
{% for given_var in given_vars %}
|
||||
end
|
||||
{% end %}
|
||||
|
|
|
@ -4,6 +4,7 @@ module Spectator
|
|||
module Examples
|
||||
include ::Spectator::DSL
|
||||
|
||||
CURRENT_CONTEXT = Spectator::ROOT_CONTEXT
|
||||
CONTEXT_MODULE = ::Spectator::Examples
|
||||
GIVEN_VARIABLES = [] of Object
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@ require "./successful_example_result"
|
|||
|
||||
module Spectator
|
||||
class Runner
|
||||
def initialize(@examples : Enumerable(Example),
|
||||
def initialize(@context : Context,
|
||||
@reporter : Reporters::Reporter = Reporters::StandardReporter.new)
|
||||
end
|
||||
|
||||
|
@ -11,7 +11,7 @@ module Spectator
|
|||
results = [] of ExampleResult
|
||||
elapsed = Time.measure do
|
||||
@reporter.start_suite
|
||||
results = @examples.map do |example|
|
||||
results = @context.all_examples.map do |example|
|
||||
@reporter.start_example(example)
|
||||
run_example(example).tap do |result|
|
||||
@reporter.end_example(result)
|
||||
|
|
Loading…
Reference in a new issue