More tests for the harness

This commit is contained in:
Michael Miller 2018-10-21 08:10:59 -06:00
parent 4ab97bd215
commit 5a4b4817b4
3 changed files with 72 additions and 5 deletions

View file

@ -56,3 +56,9 @@ def generate_results(success_count = 1, failure_count = 0)
end end
{successful: successful, failures: failures, results: results, reporter: reporter} {successful: successful, failures: failures, results: results, reporter: reporter}
end 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

View file

@ -12,14 +12,18 @@ describe Spectator::Internals::Harness do
end end
context "with a passing exmaple" do 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
end end
context "with a failing example" do 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 end
end end
@ -55,7 +59,17 @@ describe Spectator::Internals::Harness do
context "with a failed result" do context "with a failed result" do
it "raises an error" 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 end
end end

View file

@ -18,6 +18,53 @@ class SpySUT
end end
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. # Example that invokes a closure when it is run.
# This is useful for capturing what's going on when an event is running. # This is useful for capturing what's going on when an event is running.
class SpyExample < Spectator::RunnableExample class SpyExample < Spectator::RunnableExample