Some initial work on spec runner

This commit is contained in:
Michael Miller 2018-08-30 21:07:14 -06:00
parent cf789f54be
commit 3aa6ab7a10
6 changed files with 59 additions and 1 deletions

View file

@ -4,6 +4,8 @@ require "./spectator/*"
module Spectator
VERSION = "0.1.0"
ALL_EXAMPLES = [] of Example
macro describe(what, source_file = __FILE__, source_line = __LINE__, &block)
module Spectator
module Examples
@ -14,6 +16,6 @@ module Spectator
end
at_exit do
# TODO
Runner.new(ALL_EXAMPLES).run
end
end

View file

@ -33,6 +33,8 @@ module Spectator
{{block.body}}
end
end
::Spectator::ALL_EXAMPLES << {{class_name.id}}.new
end
def it_behaves_like

View file

@ -0,0 +1,10 @@
module Spectator
abstract class ExampleResult
getter example : Example
abstract def passed? : Bool
protected def initialize(@example)
end
end
end

View file

@ -0,0 +1,9 @@
require "./example_result"
module Spectator
class FailedExampleResult < ExampleResult
def passed? : Bool
false
end
end
end

26
src/spectator/runner.cr Normal file
View file

@ -0,0 +1,26 @@
require "./failed_example_result"
require "./successful_example_result"
module Spectator
class Runner
getter results : Enumerable(ExampleResult)
def initialize(@examples : Enumerable(Example))
@results = Array(ExampleResult).new(@examples.size)
end
def run : Nil
@examples.each do |example|
result = run_example(example)
pp result
end
end
private def run_example(example)
example.run
SuccessfulExampleResult.new(example)
rescue
FailedExampleResult.new(example)
end
end
end

View file

@ -0,0 +1,9 @@
require "./example_result"
module Spectator
class SuccessfulExampleResult < ExampleResult
def passed? : Bool
true
end
end
end