mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
More tests for the harness
This commit is contained in:
parent
4ab97bd215
commit
5a4b4817b4
3 changed files with 72 additions and 5 deletions
|
@ -56,3 +56,9 @@ def generate_results(success_count = 1, failure_count = 0)
|
|||
end
|
||||
{successful: successful, failures: failures, results: results, reporter: reporter}
|
||||
end
|
||||
|
||||
def report_results(success_count = 1, failure_count = 0)
|
||||
harness = Spectator::Internals::Harness.current
|
||||
success_count.times { harness.report_expectation(new_successful_result) }
|
||||
failure_count.times { harness.report_expectation(new_failure_result) }
|
||||
end
|
||||
|
|
|
@ -12,14 +12,18 @@ describe Spectator::Internals::Harness do
|
|||
end
|
||||
|
||||
context "with a passing exmaple" do
|
||||
it "returns a successful result" do
|
||||
|
||||
it "returns a passing result" do
|
||||
example = PassingExample.create
|
||||
result = Spectator::Internals::Harness.run(example)
|
||||
result.passed?.should be_true
|
||||
end
|
||||
end
|
||||
|
||||
context "with a failing example" do
|
||||
it "returns a failed result" do
|
||||
|
||||
it "returns a failing result" do
|
||||
example = FailingExample.create
|
||||
result = Spectator::Internals::Harness.run(example)
|
||||
result.passed?.should be_false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -55,7 +59,17 @@ describe Spectator::Internals::Harness do
|
|||
|
||||
context "with a failed result" do
|
||||
it "raises an error" do
|
||||
|
||||
error = nil.as(Exception?)
|
||||
spy = SpyExample.create do
|
||||
harness = Spectator::Internals::Harness.current
|
||||
begin
|
||||
harness.report_expectation(new_failure_result)
|
||||
rescue ex
|
||||
error = ex
|
||||
end
|
||||
end
|
||||
Spectator::Internals::Harness.run(spy)
|
||||
error.should be_a(Spectator::ExampleFailed)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -18,6 +18,53 @@ class SpySUT
|
|||
end
|
||||
end
|
||||
|
||||
# Example that always succeeds.
|
||||
class PassingExample < Spectator::RunnableExample
|
||||
# Dummy description.
|
||||
def what
|
||||
"PASS"
|
||||
end
|
||||
|
||||
# Run the example that always passes.
|
||||
# If this doesn't something broke.
|
||||
private def run_instance
|
||||
report_results(1, 0)
|
||||
end
|
||||
|
||||
# Creates a passing example.
|
||||
def self.create
|
||||
hooks = Spectator::ExampleHooks.empty
|
||||
group = Spectator::RootExampleGroup.new(hooks)
|
||||
values = Spectator::Internals::SampleValues.empty
|
||||
new(group, values).tap do |example|
|
||||
group.children = [example.as(Spectator::ExampleComponent)]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Example that always fails.
|
||||
class FailingExample < Spectator::RunnableExample
|
||||
# Dummy description.
|
||||
def what
|
||||
"FAIL"
|
||||
end
|
||||
|
||||
# Run the example that always fails.
|
||||
private def run_instance
|
||||
report_results(0, 1)
|
||||
end
|
||||
|
||||
# Creates a passing example.
|
||||
def self.create
|
||||
hooks = Spectator::ExampleHooks.empty
|
||||
group = Spectator::RootExampleGroup.new(hooks)
|
||||
values = Spectator::Internals::SampleValues.empty
|
||||
new(group, values).tap do |example|
|
||||
group.children = [example.as(Spectator::ExampleComponent)]
|
||||
end
|
||||
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
|
||||
|
|
Loading…
Reference in a new issue