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/groups"
|
||||||
require "./dsl/hooks"
|
require "./dsl/hooks"
|
||||||
require "./dsl/top"
|
require "./dsl/top"
|
||||||
|
require "./dsl/values"
|
||||||
|
|
||||||
module Spectator
|
module Spectator
|
||||||
# Namespace containing methods representing the spec domain specific language.
|
# Namespace containing methods representing the spec domain specific language.
|
||||||
|
|
|
@ -1,24 +1,18 @@
|
||||||
|
require "../lazy_wrapper"
|
||||||
|
|
||||||
module Spectator::DSL
|
module Spectator::DSL
|
||||||
|
# DSL methods for defining test values (subjects).
|
||||||
module Values
|
module Values
|
||||||
end
|
macro let(name, &block)
|
||||||
|
{% raise "Block required for 'let'" unless block %}
|
||||||
|
|
||||||
macro let(name, &block)
|
@%value = ::Spectator::LazyWrapper.new
|
||||||
@%wrapper : ::Spectator::ValueWrapper?
|
|
||||||
|
|
||||||
def {{name.id}}
|
def {{name.id}}
|
||||||
{{block.body}}
|
@%value.get {{block}}
|
||||||
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
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
macro let!(name, &block)
|
macro let!(name, &block)
|
||||||
@%wrapper : ::Spectator::ValueWrapper?
|
@%wrapper : ::Spectator::ValueWrapper?
|
||||||
|
|
|
@ -9,6 +9,7 @@ class SpectatorTestContext < SpectatorContext
|
||||||
include ::Spectator::DSL::Examples
|
include ::Spectator::DSL::Examples
|
||||||
include ::Spectator::DSL::Groups
|
include ::Spectator::DSL::Groups
|
||||||
include ::Spectator::DSL::Hooks
|
include ::Spectator::DSL::Hooks
|
||||||
|
include ::Spectator::DSL::Values
|
||||||
|
|
||||||
# Initial implicit subject for tests.
|
# Initial implicit subject for tests.
|
||||||
# This method should be overridden by example groups when an object is described.
|
# This method should be overridden by example groups when an object is described.
|
||||||
|
|
Loading…
Reference in a new issue