mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Some initial specs for the harness
This commit is contained in:
parent
9cf82928b7
commit
2992a18992
2 changed files with 97 additions and 0 deletions
68
spec/internals/harness_spec.cr
Normal file
68
spec/internals/harness_spec.cr
Normal file
|
@ -0,0 +1,68 @@
|
|||
require "../spec_helper"
|
||||
|
||||
describe Spectator::Internals::Harness do
|
||||
describe "#run" do
|
||||
it "runs an example" do
|
||||
run_count = 0
|
||||
spy = SpyExample.create do
|
||||
run_count += 1
|
||||
end
|
||||
Spectator::Internals::Harness.run(spy)
|
||||
run_count.should eq(1)
|
||||
end
|
||||
|
||||
context "with a passing exmaple" do
|
||||
it "returns a successful result" do
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
context "with a failing example" do
|
||||
it "returns a failed result" do
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "#current" do
|
||||
it "references the current harness" do
|
||||
harness = nil.as(Spectator::Internals::Harness?)
|
||||
spy = SpyExample.create do
|
||||
harness = Spectator::Internals::Harness.current
|
||||
end
|
||||
Spectator::Internals::Harness.run(spy)
|
||||
harness.should be_a(Spectator::Internals::Harness)
|
||||
end
|
||||
end
|
||||
|
||||
describe "#example" do
|
||||
it "references the current example" do
|
||||
example = nil.as(Spectator::Example?)
|
||||
spy = SpyExample.create do
|
||||
example = Spectator::Internals::Harness.current.example
|
||||
end
|
||||
Spectator::Internals::Harness.run(spy)
|
||||
example.should be(spy)
|
||||
end
|
||||
end
|
||||
|
||||
describe "#report_expectation" do
|
||||
context "with a successful result" do
|
||||
it "stores the result" do
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
context "with a failed result" do
|
||||
it "raises an error" do
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "#expectation_results" do
|
||||
it "contains the reported results" do
|
||||
|
||||
end
|
||||
end
|
||||
end
|
|
@ -17,3 +17,32 @@ class SpySUT
|
|||
true
|
||||
end
|
||||
end
|
||||
|
||||
# Example that invokes a closure when it is run.
|
||||
# This is useful for capturing what's going on when an event is running.
|
||||
class SpyExample < Spectator::RunnableExample
|
||||
# Dummy description.
|
||||
def what
|
||||
"SPY"
|
||||
end
|
||||
|
||||
setter block : Proc(Nil)? = nil
|
||||
|
||||
# Method called by the framework to run the example code.
|
||||
private def run_instance
|
||||
if block = @block
|
||||
block.call
|
||||
end
|
||||
end
|
||||
|
||||
# Creates the spy example.
|
||||
# The block passed to this method will be executed when the example runs.
|
||||
def self.create(&block)
|
||||
hooks = Spectator::ExampleHooks.empty
|
||||
group = Spectator::RootExampleGroup.new(hooks)
|
||||
values = Spectator::Internals::SampleValues.empty
|
||||
new(group, values).tap do |example|
|
||||
example.block = block
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue