diff --git a/src/spectator/dsl/example_dsl.cr b/src/spectator/dsl/example_dsl.cr index 60b8785..dfc3b2b 100644 --- a/src/spectator/dsl/example_dsl.cr +++ b/src/spectator/dsl/example_dsl.cr @@ -1,3 +1,7 @@ +require "../expectations/expectation_partial" +require "../source" +require "../test_block" +require "../test_value" require "./matcher_dsl" module Spectator::DSL @@ -70,11 +74,11 @@ module Spectator::DSL # The raw block can't be used because it's not clear to the user. {% method_name = block.body.id.split('.')[1..-1].join('.') %} %partial = %proc.partial(subject) - test_block = ::Spectator::TestBlock.new(%partial, {{"#" + method_name}}) + test_block = ::Spectator::TestBlock.create(%partial, {{"#" + method_name}}) {% else %} # In this case, it looks like the short-hand method syntax wasn't used. # Just drop in the proc as-is. - test_block = ::Spectator::TestBlock.new(%proc, {{"`" + block.body.stringify + "`"}}) + test_block = ::Spectator::TestBlock.create(%proc, {{"`" + block.body.stringify + "`"}}) {% end %} source = ::Spectator::Source.new({{_source_file}}, {{_source_line}}) diff --git a/src/spectator/dsl/matcher_dsl.cr b/src/spectator/dsl/matcher_dsl.cr index 408b4f2..30fc916 100644 --- a/src/spectator/dsl/matcher_dsl.cr +++ b/src/spectator/dsl/matcher_dsl.cr @@ -1,4 +1,6 @@ require "../matchers" +require "../test_block" +require "../test_value" module Spectator::DSL # Methods for defining matchers for expectations. diff --git a/src/spectator/test_block.cr b/src/spectator/test_block.cr index b1f1c4f..a955594 100644 --- a/src/spectator/test_block.cr +++ b/src/spectator/test_block.cr @@ -14,12 +14,20 @@ module Spectator super(label) end + def self.create(proc : -> T, label : String) forall T + TestBlock(T).new(proc, label) + end + # Creates the block expression with a generic label. # This is used for the "should" syntax and when the label doesn't matter. def initialize(@proc : -> ReturnType) super("") end + def self.create(proc : -> T) forall T + TestBlock(T).new(proc) + end + # Reports complete information about the expression. def inspect(io) io << label