Move spec builder

This commit is contained in:
Michael Miller 2020-09-26 22:51:58 -06:00
parent d663e82c36
commit 579fcacfde
No known key found for this signature in database
GPG key ID: F9A0C5C65B162436
2 changed files with 10 additions and 7 deletions

View file

@ -1,4 +1,5 @@
require "../spec/builder"
require "../spec"
require "../spec_builder"
module Spectator::DSL
# Incrementally builds up a test spec from the DSL.
@ -7,7 +8,7 @@ module Spectator::DSL
extend self
# Underlying spec builder.
@@builder = Spec::Builder.new
@@builder = SpecBuilder.new
# Defines a new example group and pushes it onto the group stack.
# Examples and groups defined after calling this method will be nested under the new group.

View file

@ -1,13 +1,13 @@
require "../example"
require "../example_context_method"
require "../example_group"
require "./example"
require "./example_context_method"
require "./example_group"
module Spectator
# Progressively builds a test spec.
#
# A stack is used to track the current example group.
# Adding an example or group will nest it under the group at the top of the stack.
class Spec::Builder
class SpecBuilder
# Stack tracking the current group.
# The bottom of the stack (first element) is the root group.
# The root group should never be removed.
@ -86,7 +86,9 @@ module Spectator
# Raises an error if there were not symmetrical calls to `#start_group` and `#end_group`.
# This would indicate a logical error somewhere in Spectator or an extension of it.
def build : Spec
raise NotImplementedError.new("#build")
raise "Mismatched start and end groups" unless root?
Spec.new(root_group)
end
# Checks if the current group is the root group.