Add non-captured block argument

Preparing for Crystal 1.8.0
https://github.com/crystal-lang/crystal/issues/8764
This commit is contained in:
Michael Miller 2023-01-26 17:19:31 -07:00
parent 5c08427ca0
commit 726a2e1515
No known key found for this signature in database
GPG key ID: AC78B32D30CE34A2
18 changed files with 48 additions and 47 deletions

View file

@ -17,6 +17,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed
- Expectations using 'should' syntax report file and line where the 'should' keyword is instead of the test start.
- Add non-captured block argument in preparation for Crystal 1.8.0.
## [0.11.5] - 2022-12-18
### Added

View file

@ -168,7 +168,7 @@ Spectator.describe "Double DSL", :smoke do
context "methods accepting blocks" do
double(:test7) do
stub def foo
stub def foo(&)
yield
end

View file

@ -40,17 +40,17 @@ Spectator.describe "Mock DSL", :smoke do
arg
end
def method4 : Symbol
def method4(&) : Symbol
@_spectator_invocations << :method4
yield
end
def method5
def method5(&)
@_spectator_invocations << :method5
yield.to_i
end
def method6
def method6(&)
@_spectator_invocations << :method6
yield
end
@ -60,7 +60,7 @@ Spectator.describe "Mock DSL", :smoke do
{arg, args, kwarg, kwargs}
end
def method8(arg, *args, kwarg, **kwargs)
def method8(arg, *args, kwarg, **kwargs, &)
@_spectator_invocations << :method8
yield
{arg, args, kwarg, kwargs}
@ -80,7 +80,7 @@ Spectator.describe "Mock DSL", :smoke do
"stubbed"
end
stub def method4 : Symbol
stub def method4(&) : Symbol
yield
:block
end
@ -258,12 +258,12 @@ Spectator.describe "Mock DSL", :smoke do
# NOTE: Abstract methods that yield must have yield functionality defined in the method.
# This requires that yielding methods have a default implementation.
# Just providing `&` in the arguments gets dropped by the compiler unless `yield` is in the method definition.
stub def method5
stub def method5(&)
yield
end
# NOTE: Another quirk where a default implementation must be provided because `&` is dropped.
stub def method6 : Symbol
stub def method6(&) : Symbol
yield
end
@ -381,12 +381,12 @@ Spectator.describe "Mock DSL", :smoke do
# NOTE: Abstract methods that yield must have yield functionality defined in the method.
# This requires that yielding methods have a default implementation.
# Just providing `&` in the arguments gets dropped by the compiler unless `yield` is in the method definition.
stub def method5
stub def method5(&)
yield
end
# NOTE: Another quirk where a default implementation must be provided because `&` is dropped.
stub def method6 : Symbol
stub def method6(&) : Symbol
yield
end
end
@ -454,12 +454,12 @@ Spectator.describe "Mock DSL", :smoke do
# NOTE: Abstract methods that yield must have yield functionality defined in the method.
# This requires that yielding methods have a default implementation.
# Just providing `&` in the arguments gets dropped by the compiler unless `yield` is in the method definition.
stub def method5
stub def method5(&)
yield
end
# NOTE: Another quirk where a default implementation must be provided because `&` is dropped.
stub def method6 : Symbol
stub def method6(&) : Symbol
yield
end
@ -577,12 +577,12 @@ Spectator.describe "Mock DSL", :smoke do
# NOTE: Abstract methods that yield must have yield functionality defined in the method.
# This requires that yielding methods have a default implementation.
# Just providing `&` in the arguments gets dropped by the compiler unless `yield` is in the method definition.
stub def method5
stub def method5(&)
yield
end
# NOTE: Another quirk where a default implementation must be provided because `&` is dropped.
stub def method6 : Symbol
stub def method6(&) : Symbol
yield
end
end
@ -620,11 +620,11 @@ Spectator.describe "Mock DSL", :smoke do
:original
end
def method3
def method3(&)
yield
end
def method4 : Int32
def method4(&) : Int32
yield.to_i
end
@ -749,11 +749,11 @@ Spectator.describe "Mock DSL", :smoke do
:original
end
def method3
def method3(&)
yield
end
def method4 : Int32
def method4(&) : Int32
yield.to_i
end
@ -1108,17 +1108,17 @@ Spectator.describe "Mock DSL", :smoke do
arg
end
def method4 : Symbol
def method4(&) : Symbol
@_spectator_invocations << :method4
yield
end
def method5
def method5(&)
@_spectator_invocations << :method5
yield.to_i
end
def method6
def method6(&)
@_spectator_invocations << :method6
yield
end
@ -1128,7 +1128,7 @@ Spectator.describe "Mock DSL", :smoke do
{arg, args, kwarg, kwargs}
end
def method8(arg, *args, kwarg, **kwargs)
def method8(arg, *args, kwarg, **kwargs, &)
@_spectator_invocations << :method8
yield
{arg, args, kwarg, kwargs}
@ -1148,7 +1148,7 @@ Spectator.describe "Mock DSL", :smoke do
"stubbed"
end
stub def method4 : Symbol
stub def method4(&) : Symbol
yield
:block
end

View file

@ -156,7 +156,7 @@ Spectator.describe "Null double DSL" do
context "methods accepting blocks" do
double(:test7) do
stub def foo
stub def foo(&)
yield
end

View file

@ -297,7 +297,7 @@ Spectator.describe Spectator::Double do
arg
end
stub def self.baz(arg)
stub def self.baz(arg, &)
yield
end
end

View file

@ -364,7 +364,7 @@ Spectator.describe Spectator::Mock do
arg
end
def self.baz(arg)
def self.baz(arg, &)
yield
end
@ -929,7 +929,7 @@ Spectator.describe Spectator::Mock do
arg
end
def self.baz(arg)
def self.baz(arg, &)
yield
end
end

View file

@ -259,7 +259,7 @@ Spectator.describe Spectator::NullDouble do
arg
end
stub def self.baz(arg)
stub def self.baz(arg, &)
yield
end
end

View file

@ -5,7 +5,7 @@
# The reason for this is to prevent name collision when using the DSL to define a spec.
abstract class SpectatorContext
# Evaluates the contents of a block within the scope of the context.
def eval
def eval(&)
with self yield
end

View file

@ -182,7 +182,7 @@ module Spectator::DSL
# expect(false).to be_true
# end
# ```
def aggregate_failures(label = nil)
def aggregate_failures(label = nil, &)
::Spectator::Harness.current.aggregate_failures(label) do
yield
end

View file

@ -11,7 +11,7 @@ module Spectator
end
# Calls the `error` method on *visitor*.
def accept(visitor)
def accept(visitor, &)
visitor.error(yield self)
end

View file

@ -164,7 +164,7 @@ module Spectator
# The context casted to an instance of *klass* is provided as a block argument.
#
# TODO: Benchmark compiler performance using this method versus client-side casting in a proc.
protected def with_context(klass)
protected def with_context(klass, &)
context = klass.cast(@context)
with context yield
end
@ -184,7 +184,7 @@ module Spectator
end
# Yields this example and all parent groups.
def ascend
def ascend(&)
node = self
while node
yield node
@ -279,7 +279,7 @@ module Spectator
# The block given to this method will be executed within the test context.
#
# TODO: Benchmark compiler performance using this method versus client-side casting in a proc.
protected def with_context(klass)
protected def with_context(klass, &)
context = @example.cast_context(klass)
with context yield
end

View file

@ -87,7 +87,7 @@ module Spectator
delegate size, unsafe_fetch, to: @nodes
# Yields this group and all parent groups.
def ascend
def ascend(&)
group = self
while group
yield group

View file

@ -24,7 +24,7 @@ module Spectator
end
# Calls the `failure` method on *visitor*.
def accept(visitor)
def accept(visitor, &)
visitor.fail(yield self)
end

View file

@ -13,7 +13,7 @@ module Spectator::Formatting::Components
end
# Increases the indent by the a specific *amount* for the duration of the block.
private def indent(amount = INDENT)
private def indent(amount = INDENT, &)
@indent += amount
yield
@indent -= amount
@ -23,7 +23,7 @@ module Spectator::Formatting::Components
# The contents of the line should be generated by a block provided to this method.
# Ensure that _only_ one line is produced by the block,
# otherwise the indent will be lost.
private def line(io)
private def line(io, &)
@indent.times { io << ' ' }
yield
io.puts

View file

@ -43,7 +43,7 @@ module Spectator
# The value of `.current` is set to the harness for the duration of the test.
# It will be reset after the test regardless of the outcome.
# The result of running the test code will be returned.
def self.run : Result
def self.run(&) : Result
with_harness do |harness|
harness.run { yield }
end
@ -53,7 +53,7 @@ module Spectator
# The `.current` harness is set to the new harness for the duration of the block.
# `.current` is reset to the previous value (probably nil) afterwards, even if the block raises.
# The result of the block is returned.
private def self.with_harness
private def self.with_harness(&)
previous = @@current
begin
@@current = harness = new
@ -70,7 +70,7 @@ module Spectator
# Runs test code and produces a result based on the outcome.
# The test code should be called from within the block given to this method.
def run : Result
def run(&) : Result
elapsed, error = capture { yield }
elapsed2, error2 = capture { run_deferred }
run_cleanup
@ -106,7 +106,7 @@ module Spectator
@cleanup << block
end
def aggregate_failures(label = nil)
def aggregate_failures(label = nil, &)
previous = @aggregate
@aggregate = aggregate = [] of Expectation
begin
@ -135,7 +135,7 @@ module Spectator
# Yields to run the test code and returns information about the outcome.
# Returns a tuple with the elapsed time and an error if one occurred (otherwise nil).
private def capture : Tuple(Time::Span, Exception?)
private def capture(&) : Tuple(Time::Span, Exception?)
error = nil
elapsed = Time.measure do
error = catch { yield }
@ -146,7 +146,7 @@ module Spectator
# Yields to run a block of code and captures exceptions.
# If the block of code raises an error, the error is caught and returned.
# If the block doesn't raise an error, then nil is returned.
private def catch : Exception?
private def catch(&) : Exception?
yield
rescue e
e

View file

@ -97,7 +97,7 @@ module Spectator::Matchers
# Runs a block of code and returns the exception it threw.
# If no exception was thrown, *nil* is returned.
private def capture_exception
private def capture_exception(&)
exception = nil
begin
yield

View file

@ -9,7 +9,7 @@ module Spectator
end
# Calls the `pass` method on *visitor*.
def accept(visitor)
def accept(visitor, &)
visitor.pass(yield self)
end

View file

@ -28,7 +28,7 @@ module Spectator
end
# Calls the `pending` method on the *visitor*.
def accept(visitor)
def accept(visitor, &)
visitor.pending(yield self)
end