Remove unused and deprecated types

This commit is contained in:
Michael Miller 2021-01-09 12:56:35 -07:00
parent 2e8036d230
commit fbd9713d52
No known key found for this signature in database
GPG key ID: FB9F12F7C646A4AD
7 changed files with 0 additions and 356 deletions

View file

@ -1,41 +0,0 @@
module Spectator
# Collection of checks that run before and after tests.
# The pre-conditions can be used to verify
# that the SUT is in an expected state prior to testing.
# The post-conditions can be used to verify
# that the SUT is in an expected state after tests have finished.
# Each check is just a `Proc` (code block) that runs when invoked.
class ExampleConditions
# Creates an empty set of conditions.
# This will effectively run nothing extra while running a test.
def self.empty
new(
[] of TestMetaMethod,
[] of TestMetaMethod
)
end
# Creates a new set of conditions.
def initialize(
@pre_conditions : Array(TestMetaMethod),
@post_conditions : Array(TestMetaMethod)
)
end
# Runs all pre-condition checks.
# These should be run before every test.
def run_pre_conditions(wrapper : TestWrapper, example : Example)
@pre_conditions.each do |hook|
wrapper.call(hook, example)
end
end
# Runs all post-condition checks.
# These should be run after every test.
def run_post_conditions(wrapper : TestWrapper, example : Example)
@post_conditions.each do |hook|
wrapper.call(hook, example)
end
end
end
end

View file

@ -1,75 +0,0 @@
module Spectator
alias TestMetaMethod = ::SpectatorTest, Example ->
# Collection of hooks that run at various times throughout testing.
# A hook is just a `Proc` (code block) that runs at a specified time.
class ExampleHooks
# Creates an empty set of hooks.
# This will effectively run nothing extra while running a test.
def self.empty
new(
[] of ->,
[] of TestMetaMethod,
[] of ->,
[] of TestMetaMethod,
[] of ::SpectatorTest, Proc(Nil) ->
)
end
# Creates a new set of hooks.
def initialize(
@before_all : Array(->),
@before_each : Array(TestMetaMethod),
@after_all : Array(->),
@after_each : Array(TestMetaMethod),
@around_each : Array(::SpectatorTest, Proc(Nil) ->)
)
end
# Runs all "before-all" hooks.
# These hooks should be run once before all examples in the group start.
def run_before_all
@before_all.each &.call
end
# Runs all "before-each" hooks.
# These hooks should be run every time before each example in a group.
def run_before_each(wrapper : TestWrapper, example : Example)
@before_each.each do |hook|
wrapper.call(hook, example)
end
end
# Runs all "after-all" hooks.
# These hooks should be run once after all examples in group finish.
def run_after_all
@after_all.each &.call
end
# Runs all "after-all" hooks.
# These hooks should be run every time after each example in a group.
def run_after_each(wrapper : TestWrapper, example : Example)
@after_each.each do |hook|
wrapper.call(hook, example)
end
end
# Creates a proc that runs the "around-each" hooks
# in addition to a block passed to this method.
# To call the block and all "around-each" hooks,
# just invoke `Proc#call` on the returned proc.
def wrap_around_each(test, block : ->)
wrapper = block
# Must wrap in reverse order,
# otherwise hooks will run in the wrong order.
@around_each.reverse_each do |hook|
wrapper = wrap_foo(test, hook, wrapper)
end
wrapper
end
private def wrap_foo(test, hook, wrapper)
->{ hook.call(test, wrapper) }
end
end
end

View file

@ -1,54 +0,0 @@
require "./example_group"
module Spectator
# A collection of examples and other example groups.
# This group can be nested under other groups.
class NestedExampleGroup < ExampleGroup
# Description from the user of the group's contents.
# This is a symbol when referencing a type.
getter description : Symbol | String
getter source : Source
# Group that this is nested in.
getter parent : ExampleGroup
# Creates a new example group.
# The *description* argument is a description from the user.
# The *parent* should contain this group.
# After creating this group, the parent's children should be updated.
# The parent's children must contain this group,
# otherwise there may be unexpected behavior.
# The *hooks* are stored to be triggered later.
def initialize(@description, @source, @parent, context)
super(context)
end
# Indicates wheter the group references a type.
def symbolic? : Bool
@description.is_a?(Symbol)
end
# Creates a string representation of the group.
# The string consists of `#description` appended to the parent.
# This results in a string like:
# ```text
# Foo#bar does something
# ```
# for the following structure:
# ```
# describe Foo do
# describe "#bar" do
# it "does something" do
# # ...
# end
# end
# end
# ```
def to_s(io)
parent.to_s(io)
io << ' ' unless (symbolic? || parent.is_a?(RootExampleGroup)) && parent.symbolic?
io << description
end
end
end

View file

@ -1,12 +0,0 @@
require "./example"
module Spectator
# Common class for all examples marked as pending.
# This class will not run example code.
class PendingExample < Example
# Returns a pending result.
private def run_impl : Result
PendingResult.new(self)
end
end
end

View file

@ -1,28 +0,0 @@
require "./example_group"
module Spectator
# Top-most group of examples and sub-groups.
# The root has no parent.
class RootExampleGroup < ExampleGroup
# Dummy value - this should never be used.
def description : Symbol | String
:root
end
def source : Source
Source.new(__FILE__, __LINE__)
end
# Indicates that the group is symbolic.
def symbolic? : Bool
true
end
# Does nothing.
# This prevents the root group
# from showing up in output.
def to_s(io)
# ...
end
end
end

View file

@ -1,82 +0,0 @@
require "./example"
module Spectator
# Includes all the logic for running example hooks,
# the example code, and capturing a result.
class RunnableExample < Example
# Runs the example, hooks, and captures the result
# and translates to a usable result.
def run_impl : Result
result = capture_result
expectations = Harness.current.expectations
translate_result(result, expectations)
end
# Runs all hooks and the example code.
# A captured result is returned.
private def capture_result
context = group.context
ResultCapture.new.tap do |result|
context.run_before_hooks(self)
run_example(result)
@finished = true
context.run_after_hooks(self)
run_deferred(result) unless result.error
end
end
# Runs the test code and captures the result.
private def run_example(result)
context = group.context
wrapper = test_wrapper.around_hook(context)
# Capture how long it takes to run the test code.
result.elapsed = Time.measure do
begin
context.run_pre_conditions(self)
wrapper.call
context.run_post_conditions(self)
rescue ex # Catch all errors and handle them later.
result.error = ex
end
end
end
# Runs the deferred blocks of code and captures the result.
private def run_deferred(result)
result.elapsed += Time.measure do
begin
Harness.current.run_deferred
rescue ex # Catch all errors and handle them later.
result.error = ex
end
end
end
# Creates a result instance from captured result information.
private def translate_result(result, expectations)
case (error = result.error)
when Nil
# If no errors occurred, then the example ran successfully.
SuccessfulResult.new(self, result.elapsed, expectations)
when ExpectationFailed
# If a required expectation fails, then a `ExpectationRailed` exception will be raised.
FailedResult.new(self, result.elapsed, expectations, error)
else
# Any other exception that is raised is unexpected and is an errored result.
ErroredResult.new(self, result.elapsed, expectations, error)
end
end
# Utility class for storing parts of the result while the example is running.
private class ResultCapture
# Length of time that it took to run the test code.
# This does not include hooks.
property elapsed = Time::Span.zero
# The error that occurred while running the test code.
# If no error occurred, this will be nil.
property error : Exception?
end
end
end

View file

@ -1,64 +0,0 @@
require "./typed_value_wrapper"
require "./value_wrapper"
module Spectator
# Collection of test values supplied to examples.
# Each value is labeled by a symbol that the example knows.
# The values also come with a name that can be given to humans.
struct TestValues
# Creates an empty set of sample values.
def self.empty
new({} of Symbol => Entry)
end
# Creates a collection of sample values.
protected def initialize(@values = {} of Symbol => Entry)
end
# Adds a new value by duplicating the current set and adding to it.
# The new sample values with the additional value is returned.
# The original set of sample values is not modified.
def add(id : Symbol, name : String, value) : TestValues
wrapper = TypedValueWrapper.new(value)
TestValues.new(@values.merge({
id => Entry.new(name, wrapper),
}))
end
# Retrieves the wrapper for a value.
# The symbol for the value is used for retrieval.
def get_wrapper(id : Symbol)
@values[id].wrapper
end
# Retrieves a value.
# The symbol for the value is used for retrieval.
# The value's type must be provided so that the wrapper can be cast.
def get_value(id : Symbol, value_type : T.class) : T forall T
get_wrapper(id).as(TypedValueWrapper(T)).value
end
# Iterates over all values and yields them.
def each
@values.each_value do |entry|
yield entry
end
end
# Represents a single value in the set.
private struct Entry
# Human-friendly name for the value.
getter name : String
# Wrapper for the value.
getter wrapper : ValueWrapper
# Creates a new value entry.
def initialize(@name, @wrapper)
end
end
# This must be after `Entry` is defined.
include Enumerable(Entry)
end
end