mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Reimplement given
as provided
and deprecate
The behavior is slightly different now. Nested example blocks aren't allowed in `provided`. The block produces one example, not multiple.
This commit is contained in:
parent
71a5c39f6c
commit
704c28e822
4 changed files with 46 additions and 2 deletions
|
@ -19,6 +19,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||
### Changed
|
||||
- Simplify and reduce defined types and generics. Should speed up compilation times.
|
||||
- `around_each` hooks wrap `before_all` and `after_all` hooks. [#12](https://github.com/icy-arctic-fox/spectator/issues/12)
|
||||
- `given` (now `provided`) blocks changed to produce a single example. `it` can no longer be nested in a `provided` block.
|
||||
- The "should" syntax no longer reports the source as inside Spectator.
|
||||
- Short-hand "should" syntax must be included by using `require "spectator/should"` - `it { should eq("foo") }`
|
||||
- Overhaul example creation and handling.
|
||||
|
@ -31,9 +32,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||
|
||||
### Deprecated
|
||||
- `pending` blocks will behave differently in v0.11.0. They will mimic RSpec in that they _compile and run_ the block expecting it to fail. Use a `skip` (or `xit`) block instead to prevent compiling the example.
|
||||
- `given` has been renamed to `provided`. The `given` keyword may be reused later for memoization.
|
||||
|
||||
### Removed
|
||||
- Removed one-liner it syntax without braces (block).
|
||||
- Removed one-liner `it`-syntax without braces (block).
|
||||
|
||||
## [0.9.38] - 2021-05-27
|
||||
### Fixed
|
||||
|
|
41
src/spectator/dsl/concise.cr
Normal file
41
src/spectator/dsl/concise.cr
Normal file
|
@ -0,0 +1,41 @@
|
|||
require "./examples"
|
||||
require "./groups"
|
||||
require "./memoize"
|
||||
|
||||
module Spectator::DSL
|
||||
# DSL methods and macros for shorter syntax.
|
||||
module Concise
|
||||
# Defines an example and input values in a shorter syntax.
|
||||
# The only arguments given to this macro are one or more assignments.
|
||||
# The names in the assigments will be available in the example code.
|
||||
#
|
||||
# If the code block is omitted, then the example is skipped (marked as not implemented).
|
||||
#
|
||||
# Tags and metadata cannot be used with this macro.
|
||||
#
|
||||
# ```
|
||||
# given x = 42 do
|
||||
# expect(x).to eq(42)
|
||||
# end
|
||||
# ```
|
||||
macro provided(*assignments, &block)
|
||||
class Given%given < {{@type.id}}
|
||||
{% for assignment in assignments %}
|
||||
let({{assignment.target}}) { {{assignment.value}} }
|
||||
{% end %}
|
||||
|
||||
{% if block %}
|
||||
example {{block}}
|
||||
{% else %}
|
||||
example {{assignments.splat.stringify}}
|
||||
{% end %}
|
||||
end
|
||||
end
|
||||
|
||||
# :ditto:
|
||||
@[Deprecated("Use `provided` instead.")]
|
||||
macro given(*assignments, &block)
|
||||
provided({{assignments.splat}}) {{block}}
|
||||
end
|
||||
end
|
||||
end
|
|
@ -116,6 +116,6 @@ module Spectator::DSL
|
|||
|
||||
define_example_group :xcontext, skip: "Temporarily skipped with xcontext"
|
||||
|
||||
# TODO: sample, random_sample, and given
|
||||
# TODO: sample, random_sample
|
||||
end
|
||||
end
|
||||
|
|
|
@ -8,6 +8,7 @@ require "./tags"
|
|||
# This type is intentionally outside the `Spectator` module.
|
||||
# The reason for this is to prevent name collision when using the DSL to define a spec.
|
||||
class SpectatorTestContext < SpectatorContext
|
||||
include ::Spectator::DSL::Concise
|
||||
include ::Spectator::DSL::Examples
|
||||
include ::Spectator::DSL::Expectations
|
||||
include ::Spectator::DSL::Groups
|
||||
|
|
Loading…
Reference in a new issue