diff --git a/README.md b/README.md index f94fbdd..c8635be 100644 --- a/README.md +++ b/README.md @@ -126,7 +126,7 @@ In no particular order, features that have been implemented and are planned: - [ ] Test filtering - by name, context, and tags - [X] Fail on no tests - [ ] Randomize test order - - [ ] Dry run - for validation and checking formatted output + - [X] Dry run - for validation and checking formatted output - [X] Config block in `spec_helper.cr` - [X] Config file - `.spectator` - [ ] Reporter and formatting diff --git a/src/spectator/runner.cr b/src/spectator/runner.cr index 27558e9..998046c 100644 --- a/src/spectator/runner.cr +++ b/src/spectator/runner.cr @@ -42,9 +42,20 @@ module Spectator # The formatter is given the example and result information. private def run_example(example) @config.formatter.start_example(example) - Internals::Harness.run(example).tap do |result| - @config.formatter.end_example(result) - end + result = if @config.dry_run? && example.is_a?(RunnableExample) + dry_run_result(example) + else + Internals::Harness.run(example) + end + @config.formatter.end_example(result) + result + end + + # Creates a fake result for an example. + private def dry_run_result(example) + expectations = [] of Expectations::Expectation + example_expectations = Expectations::ExampleExpectations.new(expectations) + SuccessfulResult.new(example, Time::Span.zero, example_expectations) end end end