mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Minimal handling of expectations and failures
This commit is contained in:
parent
7ec33943a4
commit
74905b82bd
3 changed files with 14 additions and 0 deletions
|
@ -5,6 +5,8 @@ module Spectator
|
||||||
|
|
||||||
def run
|
def run
|
||||||
@block.call
|
@block.call
|
||||||
|
rescue ex : ExpectationFailedError
|
||||||
|
puts ex
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
require "./matchers/matcher"
|
||||||
|
|
||||||
def expect(actual : T) forall T
|
def expect(actual : T) forall T
|
||||||
Spectator::Expectation.new(actual)
|
Spectator::Expectation.new(actual)
|
||||||
end
|
end
|
||||||
|
@ -8,5 +10,11 @@ module Spectator
|
||||||
|
|
||||||
protected def initialize(@actual : T)
|
protected def initialize(@actual : T)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def to(matcher : Matchers::Matcher)
|
||||||
|
unless matcher.match?(self)
|
||||||
|
raise ExpectationFailedError.new
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
4
src/spectator/expectation_failed_error.cr
Normal file
4
src/spectator/expectation_failed_error.cr
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
module Spectator
|
||||||
|
class ExpectationFailedError < Exception
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in a new issue