diff --git a/spec/expectations_helper.cr b/spec/expectations_helper.cr index a88abfa..955db42 100644 --- a/spec/expectations_helper.cr +++ b/spec/expectations_helper.cr @@ -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 diff --git a/spec/internals/harness_spec.cr b/spec/internals/harness_spec.cr index a7adbb3..6900a71 100644 --- a/spec/internals/harness_spec.cr +++ b/spec/internals/harness_spec.cr @@ -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 diff --git a/spec/spec_helper.cr b/spec/spec_helper.cr index 674e775..8e9164d 100644 --- a/spec/spec_helper.cr +++ b/spec/spec_helper.cr @@ -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