mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Some initial work on spec runner
This commit is contained in:
parent
cf789f54be
commit
3aa6ab7a10
6 changed files with 59 additions and 1 deletions
|
@ -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
|
||||
|
|
|
@ -33,6 +33,8 @@ module Spectator
|
|||
{{block.body}}
|
||||
end
|
||||
end
|
||||
|
||||
::Spectator::ALL_EXAMPLES << {{class_name.id}}.new
|
||||
end
|
||||
|
||||
def it_behaves_like
|
||||
|
|
10
src/spectator/example_result.cr
Normal file
10
src/spectator/example_result.cr
Normal file
|
@ -0,0 +1,10 @@
|
|||
module Spectator
|
||||
abstract class ExampleResult
|
||||
getter example : Example
|
||||
|
||||
abstract def passed? : Bool
|
||||
|
||||
protected def initialize(@example)
|
||||
end
|
||||
end
|
||||
end
|
9
src/spectator/failed_example_result.cr
Normal file
9
src/spectator/failed_example_result.cr
Normal 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
26
src/spectator/runner.cr
Normal 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
|
9
src/spectator/successful_example_result.cr
Normal file
9
src/spectator/successful_example_result.cr
Normal file
|
@ -0,0 +1,9 @@
|
|||
require "./example_result"
|
||||
|
||||
module Spectator
|
||||
class SuccessfulExampleResult < ExampleResult
|
||||
def passed? : Bool
|
||||
true
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue