Add getter for wrapped instance

This commit is contained in:
Michael Miller 2019-01-01 16:40:04 -07:00
parent b53e1b60d8
commit abf7c8831c
3 changed files with 12 additions and 1 deletions

View file

@ -1002,6 +1002,9 @@ module Spectator::DSL
@instance = {{wrapper_class_name.id}}.new(sample_values)
end
# Retrieves the underlying, wrapped instance.
getter instance
# Add the block's content if one was provided.
{% if block.is_a?(Block) %}
{{block.body}}

View file

@ -14,6 +14,11 @@ module Spectator
"DUMMY"
end
# Dummy instance.
def instance
nil
end
# Dummy run that does nothing.
def run_instance
raise "You shouldn't be running this."

View file

@ -2,7 +2,7 @@ require "./example_component"
module Spectator
# Base class for all types of examples.
# Concrete types must implement the `#run_inner` and `#what` methods.
# Concrete types must implement the `#run_inner`, `#what`, and `#instance` methods.
abstract class Example < ExampleComponent
# Indicates whether the example has already been run.
getter? finished = false
@ -10,6 +10,9 @@ module Spectator
# Group that the example belongs to.
getter group : ExampleGroup
# Retrieves the internal wrapped instance.
abstract def instance
# Runs the example code.
# A result is returned, which represents the outcome of the test.
# An example can be run only once.