From d8621fc43e8ce185d0e3e889c34954035bd97ce0 Mon Sep 17 00:00:00 2001 From: Michael Miller Date: Tue, 11 Sep 2018 15:54:00 -0600 Subject: [PATCH] Store "what" string in context --- src/spectator.cr | 2 +- src/spectator/context.cr | 3 ++- src/spectator/dsl.cr | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/spectator.cr b/src/spectator.cr index d7125b6..68f6bfc 100644 --- a/src/spectator.cr +++ b/src/spectator.cr @@ -4,7 +4,7 @@ require "./spectator/*" module Spectator VERSION = "0.1.0" - ROOT_CONTEXT = Context.new + ROOT_CONTEXT = Context.new("ROOT") macro describe(what, source_file = __FILE__, source_line = __LINE__, &block) module Spectator diff --git a/src/spectator/context.cr b/src/spectator/context.cr index 485eb7e..111d063 100644 --- a/src/spectator/context.cr +++ b/src/spectator/context.cr @@ -2,6 +2,7 @@ require "./example" module Spectator class Context + getter what : String getter parent : Context? getter examples = [] of Example getter contexts = [] of Context @@ -14,7 +15,7 @@ module Spectator @before_all_hooks_run = false @after_all_hooks_run = false - def initialize(@parent = nil) + def initialize(@what, @parent = nil) if (parent = @parent) parent.contexts << self end diff --git a/src/spectator/dsl.cr b/src/spectator/dsl.cr index 49b6d37..0e29cc7 100644 --- a/src/spectator/dsl.cr +++ b/src/spectator/dsl.cr @@ -49,7 +49,7 @@ module Spectator include ::Spectator::DSL PARENT_CONTEXT = {{context_module.id}}::CURRENT_CONTEXT - CURRENT_CONTEXT = ::Spectator::Context.new(PARENT_CONTEXT) + CURRENT_CONTEXT = ::Spectator::Context.new({{what.stringify}}, PARENT_CONTEXT) CONTEXT_MODULE = {{context_module.id}}::{{module_name.id}} GIVEN_VARIABLES = [