Move DSL-based code to subclass of SpectatorContext

This resolves a circular dependency.
This commit is contained in:
Michael Miller 2020-09-12 18:39:21 -06:00
parent 67ac06e4d6
commit 6752c7c254
No known key found for this signature in database
GPG key ID: FB9F12F7C646A4AD
3 changed files with 25 additions and 15 deletions

View file

@ -1,5 +1,5 @@
require "./spectator/includes"
require "./spectator_context"
require "./spectator_test_context"
# Module that contains all functionality related to Spectator.
module Spectator
@ -38,7 +38,7 @@ module Spectator
# For more information on how the DSL works, see the `DSL` module.
# Root-level class that contains all examples and example groups.
class SpectatorContext
class ::SpectatorTestContext
# Pass off the description argument and block to `DSL::StructureDSL.describe`.
# That method will handle creating a new group for this spec.
describe({{description}}) {{block}}

View file

@ -4,17 +4,4 @@
# This type is intentionally outside the `Spectator` module.
# The reason for this is to prevent name collision when using the DSL to define a spec.
abstract class SpectatorContext
# Initial implicit subject for tests.
# This method should be overridden by example groups when an object is described.
private def _spectator_implicit_subject
nil
end
# Initial subject for tests.
# Returns the implicit subject.
# This method should be overridden when an explicit subject is defined by the DSL.
# TODO: Subject needs to be cached.
private def subject
_spectator_implicit_subject
end
end

View file

@ -0,0 +1,23 @@
require "./spectator_context"
require "./spectator/dsl"
class SpectatorTestContext < SpectatorContext
include ::Spectator::DSL::Groups
# Initial implicit subject for tests.
# This method should be overridden by example groups when an object is described.
private def _spectator_implicit_subject
nil
end
# Initial subject for tests.
# Returns the implicit subject.
# This method should be overridden when an explicit subject is defined by the DSL.
# TODO: Subject needs to be cached.
private def subject
_spectator_implicit_subject
end
# def initialize(@spectator_test_values : ::Spectator::TestValues)
# end
end