Implement dry-run mode

This commit is contained in:
Michael Miller 2019-03-22 14:18:03 -06:00
parent 435f971c87
commit ba0453c5ea
2 changed files with 15 additions and 4 deletions

View File

@ -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

View File

@ -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)
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