mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Prevent using reserved keywords in let and subject
This commit is contained in:
parent
86a85c0946
commit
3cd569e639
3 changed files with 8 additions and 0 deletions
|
@ -22,6 +22,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||
- Overhaul storage of test values.
|
||||
- Cleanup and simplify DSL implementation.
|
||||
- Better error messages and detection when DSL methods are used when they shouldn't (i.e. `describe` inside `it`).
|
||||
- Prevent usage of reserved keywords in DSL (such as `initialize`).
|
||||
- Other minor internal improvements and cleanup.
|
||||
|
||||
### Removed
|
||||
|
|
|
@ -7,5 +7,8 @@ module Spectator
|
|||
# This also helps keep error traces small.
|
||||
# Documentation only useful for debugging is included in generated code.
|
||||
module DSL
|
||||
# Keywords that cannot be used in specs using the DSL.
|
||||
# These are either problematic or reserved for internal use.
|
||||
RESERVED_KEYWORDS = %i[initialize]
|
||||
end
|
||||
end
|
||||
|
|
|
@ -11,6 +11,7 @@ module Spectator::DSL
|
|||
{% raise "Block required for 'let'" unless block %}
|
||||
{% raise "Cannot use 'let' inside of a test block" if @def %}
|
||||
{% raise "Block argument count for 'let' must be 0..1" if block.args.size > 1 %}
|
||||
{% raise "Cannot use '#{name.id}' for 'let'" if ::Spectator::DSL::RESERVED_KEYWORDS.includes?(name.id.symbolize) %}
|
||||
|
||||
@%value = ::Spectator::LazyWrapper.new
|
||||
|
||||
|
@ -32,6 +33,7 @@ module Spectator::DSL
|
|||
{% raise "Block required for 'let!'" unless block %}
|
||||
{% raise "Cannot use 'let!' inside of a test block" if @def %}
|
||||
{% raise "Block argument count for 'let!' must be 0..1" if block.args.size > 1 %}
|
||||
{% raise "Cannot use '#{name.id}' for 'let!'" if ::Spectator::DSL::RESERVED_KEYWORDS.includes?(name.id.symbolize) %}
|
||||
|
||||
let({{name}}) {{block}}
|
||||
before_each { {{name.id}} }
|
||||
|
@ -58,6 +60,7 @@ module Spectator::DSL
|
|||
{% 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 %}
|
||||
{% raise "Cannot use '#{name.id}' for 'subject'" if ::Spectator::DSL::RESERVED_KEYWORDS.includes?(name.id.symbolize) %}
|
||||
|
||||
let({{name.id}}) {{block}}
|
||||
|
||||
|
@ -89,6 +92,7 @@ module Spectator::DSL
|
|||
{% 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 %}
|
||||
{% raise "Cannot use '#{name.id}' for 'subject!'" if ::Spectator::DSL::RESERVED_KEYWORDS.includes?(name.id.symbolize) %}
|
||||
|
||||
let!({{name.id}}) {{block}}
|
||||
|
||||
|
|
Loading…
Reference in a new issue