Workaround for Crystal compiler bug

See: https://github.com/crystal-lang/crystal/issues/4225
If there are no concrete implementations of a class, an "undefined
method" error is given for abstract methods.
This commit is contained in:
Michael Miller 2018-10-15 15:27:05 -06:00
parent c77a85c97a
commit df36331132
3 changed files with 24 additions and 1 deletions

View file

@ -0,0 +1,22 @@
require "./runnable_example"
module Spectator
# Example that does nothing.
# This is to workaround a Crystal compiler bug.
# See: [Issue 4225](https://github.com/crystal-lang/crystal/issues/4225)
# If there are no concrete implementations of an abstract class,
# the compiler gives an error.
# The error indicates an abstract method is undefined.
# This class shouldn't be used, it's just to trick the compiler.
private class DummyExample < RunnableExample
# Dummy description.
def what
"DUMMY"
end
# Dummy run that does nothing.
def run_instance
# ...
end
end
end

View file

@ -16,6 +16,7 @@ require "./example_component"
require "./example"
require "./runnable_example"
require "./pending_example"
require "./dummy_example"
require "./example_hooks"
require "./example_group"

View file

@ -4,7 +4,7 @@ module Spectator
# Common base for all examples that can be run.
# This class includes all the logic for running example hooks,
# the example code, and capturing a result.
# Sub-classes need to implement the `#run_instance` method.
# Sub-classes need to implement the `#what` and `#run_instance` methods.
abstract class RunnableExample < Example
# Runs the example, hooks, and captures the result
# and translates to a usable result.