mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Workaround context scope not used in method delegation
This commit is contained in:
parent
153933b044
commit
13061cfb38
1 changed files with 31 additions and 1 deletions
|
@ -99,12 +99,28 @@ module Spectator
|
||||||
# An error will be raised if *klass* doesn't match the test context's type.
|
# An error will be raised if *klass* doesn't match the test context's type.
|
||||||
# The block given to this method will be executed within the test context.
|
# The block given to this method will be executed within the test context.
|
||||||
#
|
#
|
||||||
|
# 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.
|
# TODO: Benchmark compiler performance using this method versus client-side casting in a proc.
|
||||||
def with_context(klass)
|
protected def with_context(klass)
|
||||||
context = klass.cast(@context)
|
context = klass.cast(@context)
|
||||||
with context yield
|
with context yield
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Casts the example's test context to a specific type.
|
||||||
|
# This is an advanced method intended for internal usage only.
|
||||||
|
#
|
||||||
|
# The *klass* defines the type of the test context.
|
||||||
|
# This is typically only known by the code constructing the example.
|
||||||
|
# An error will be raised if *klass* doesn't match the test context's type.
|
||||||
|
#
|
||||||
|
# The context casted to an instance of *klass* is returned.
|
||||||
|
#
|
||||||
|
# TODO: Benchmark compiler performance using this method versus client-side casting in a proc.
|
||||||
|
protected def cast_context(klass)
|
||||||
|
klass.cast(@context)
|
||||||
|
end
|
||||||
|
|
||||||
# Constructs the full name or description of the example.
|
# Constructs the full name or description of the example.
|
||||||
# This prepends names of groups this example is part of.
|
# This prepends names of groups this example is part of.
|
||||||
def to_s(io)
|
def to_s(io)
|
||||||
|
@ -159,6 +175,20 @@ module Spectator
|
||||||
self.class.new(@example, &block)
|
self.class.new(@example, &block)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Executes code within the example's test context.
|
||||||
|
# This is an advanced method intended for internal usage only.
|
||||||
|
#
|
||||||
|
# The *klass* defines the type of the test context.
|
||||||
|
# This is typically only known by the code constructing the example.
|
||||||
|
# An error will be raised if *klass* doesn't match the test context's type.
|
||||||
|
# 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)
|
||||||
|
context = @example.cast_context(klass)
|
||||||
|
with context yield
|
||||||
|
end
|
||||||
|
|
||||||
# Allow instance to behave like an example.
|
# Allow instance to behave like an example.
|
||||||
forward_missing_to @example
|
forward_missing_to @example
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue