mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Initial work on values DSL
This commit is contained in:
parent
4108a6602d
commit
391325d431
3 changed files with 10 additions and 14 deletions
|
@ -4,6 +4,7 @@ require "./dsl/examples"
|
|||
require "./dsl/groups"
|
||||
require "./dsl/hooks"
|
||||
require "./dsl/top"
|
||||
require "./dsl/values"
|
||||
|
||||
module Spectator
|
||||
# Namespace containing methods representing the spec domain specific language.
|
||||
|
|
|
@ -1,24 +1,18 @@
|
|||
require "../lazy_wrapper"
|
||||
|
||||
module Spectator::DSL
|
||||
# DSL methods for defining test values (subjects).
|
||||
module Values
|
||||
end
|
||||
macro let(name, &block)
|
||||
{% raise "Block required for 'let'" unless block %}
|
||||
|
||||
macro let(name, &block)
|
||||
@%wrapper : ::Spectator::ValueWrapper?
|
||||
@%value = ::Spectator::LazyWrapper.new
|
||||
|
||||
def {{name.id}}
|
||||
{{block.body}}
|
||||
end
|
||||
|
||||
def {{name.id}}
|
||||
if (wrapper = @%wrapper)
|
||||
wrapper.as(::Spectator::TypedValueWrapper(typeof(previous_def))).value
|
||||
else
|
||||
previous_def.tap do |value|
|
||||
@%wrapper = ::Spectator::TypedValueWrapper.new(value)
|
||||
end
|
||||
end
|
||||
@%value.get {{block}}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
macro let!(name, &block)
|
||||
@%wrapper : ::Spectator::ValueWrapper?
|
||||
|
|
|
@ -9,6 +9,7 @@ class SpectatorTestContext < SpectatorContext
|
|||
include ::Spectator::DSL::Examples
|
||||
include ::Spectator::DSL::Groups
|
||||
include ::Spectator::DSL::Hooks
|
||||
include ::Spectator::DSL::Values
|
||||
|
||||
# Initial implicit subject for tests.
|
||||
# This method should be overridden by example groups when an object is described.
|
||||
|
|
Loading…
Reference in a new issue