mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Fix various issues with subjects
All tests in crystal spec pass!
This commit is contained in:
parent
948e29a8b7
commit
078058ad05
2 changed files with 21 additions and 12 deletions
|
@ -1,6 +1,7 @@
|
||||||
require "../source"
|
require "../source"
|
||||||
require "./builder"
|
require "./builder"
|
||||||
require "./tags"
|
require "./tags"
|
||||||
|
require "./values"
|
||||||
|
|
||||||
module Spectator::DSL
|
module Spectator::DSL
|
||||||
# DSL methods and macros for creating example groups.
|
# DSL methods and macros for creating example groups.
|
||||||
|
@ -89,13 +90,13 @@ module Spectator::DSL
|
||||||
{{described_type}}
|
{{described_type}}
|
||||||
end
|
end
|
||||||
|
|
||||||
private def _spectator_implicit_subject
|
{% if described_type < Reference || described_type < Value %}
|
||||||
{% if described_type < Reference || described_type < Value %}
|
subject { described_class.new }
|
||||||
described_class.new
|
{% else %}
|
||||||
{% else %}
|
private def subject
|
||||||
described_class
|
described_class
|
||||||
{% end %}
|
end
|
||||||
end
|
{% end %}
|
||||||
{% else %}
|
{% else %}
|
||||||
private def _spectator_implicit_subject
|
private def _spectator_implicit_subject
|
||||||
{{what}}
|
{{what}}
|
||||||
|
|
|
@ -53,11 +53,15 @@ module Spectator::DSL
|
||||||
# The block is evaluated only the first time the subject is referenced
|
# The block is evaluated only the first time the subject is referenced
|
||||||
# and the return value is saved for subsequent calls.
|
# and the return value is saved for subsequent calls.
|
||||||
macro subject(name, &block)
|
macro subject(name, &block)
|
||||||
subject {{block}}
|
{% raise "Block required for 'subject'" unless block %}
|
||||||
|
{% raise "Cannot use 'subject' inside of a test block" if @def %}
|
||||||
|
{% raise "Block argument count for 'subject' must be 0..1" if block.args.size > 1 %}
|
||||||
|
|
||||||
|
let({{name.id}}) {{block}}
|
||||||
|
|
||||||
{% if name.id != :subject.id %}
|
{% if name.id != :subject.id %}
|
||||||
def {{name.id}}
|
def subject
|
||||||
subject
|
{{name.id}}
|
||||||
end
|
end
|
||||||
{% end %}
|
{% end %}
|
||||||
end
|
end
|
||||||
|
@ -80,11 +84,15 @@ module Spectator::DSL
|
||||||
# The block is evaluated once before the example runs
|
# The block is evaluated once before the example runs
|
||||||
# and the return value is saved for subsequent calls.
|
# and the return value is saved for subsequent calls.
|
||||||
macro subject!(name, &block)
|
macro subject!(name, &block)
|
||||||
subject! {{block}}
|
{% raise "Block required for 'subject!'" unless block %}
|
||||||
|
{% raise "Cannot use 'subject!' inside of a test block" if @def %}
|
||||||
|
{% raise "Block argument count for 'subject!' must be 0..1" if block.args.size > 1 %}
|
||||||
|
|
||||||
|
let!({{name.id}}) {{block}}
|
||||||
|
|
||||||
{% if name.id != :subject.id %}
|
{% if name.id != :subject.id %}
|
||||||
def {{name.id}}
|
def subject
|
||||||
subject
|
{{name.id}}
|
||||||
end
|
end
|
||||||
{% end %}
|
{% end %}
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue