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 "./builder"
|
||||
require "./tags"
|
||||
require "./values"
|
||||
|
||||
module Spectator::DSL
|
||||
# DSL methods and macros for creating example groups.
|
||||
|
@ -89,13 +90,13 @@ module Spectator::DSL
|
|||
{{described_type}}
|
||||
end
|
||||
|
||||
private def _spectator_implicit_subject
|
||||
{% if described_type < Reference || described_type < Value %}
|
||||
described_class.new
|
||||
{% else %}
|
||||
{% if described_type < Reference || described_type < Value %}
|
||||
subject { described_class.new }
|
||||
{% else %}
|
||||
private def subject
|
||||
described_class
|
||||
{% end %}
|
||||
end
|
||||
end
|
||||
{% end %}
|
||||
{% else %}
|
||||
private def _spectator_implicit_subject
|
||||
{{what}}
|
||||
|
|
|
@ -53,11 +53,15 @@ module Spectator::DSL
|
|||
# The block is evaluated only the first time the subject is referenced
|
||||
# and the return value is saved for subsequent calls.
|
||||
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 %}
|
||||
def {{name.id}}
|
||||
subject
|
||||
def subject
|
||||
{{name.id}}
|
||||
end
|
||||
{% end %}
|
||||
end
|
||||
|
@ -80,11 +84,15 @@ module Spectator::DSL
|
|||
# The block is evaluated once before the example runs
|
||||
# and the return value is saved for subsequent calls.
|
||||
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 %}
|
||||
def {{name.id}}
|
||||
subject
|
||||
def subject
|
||||
{{name.id}}
|
||||
end
|
||||
{% end %}
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue