Fix specs to work with new Expectation type

This commit is contained in:
Michael Miller 2018-11-14 02:15:55 -07:00
parent 35b59854ec
commit f0204a32ea
9 changed files with 379 additions and 395 deletions

View file

@ -19,46 +19,35 @@ end
def new_expectation(expected : ExpectedType = 123, actual : ActualType = 123) forall ExpectedType, ActualType
partial = new_partial("foo", actual)
matcher = new_matcher("bar", expected)
Spectator::Expectations::ValueExpectation.new(partial, matcher)
matched = matcher.match?(partial)
Spectator::Expectations::ValueExpectation.new(matched, false, partial, matcher)
end
def new_met_expectation(value : T = 123) forall T
def new_satisfied_expectation(value : T = 123) forall T
new_expectation(value, value).tap do |expectation|
expectation.satisfied?.should be_true # Sanity check.
end
end
def new_unmet_expectation(expected : ExpectedType = 123, actual : ActualType = 456) forall ExpectedType, ActualType
def new_unsatisfied_expectation(expected : ExpectedType = 123, actual : ActualType = 456) forall ExpectedType, ActualType
new_expectation(expected, actual).tap do |expectation|
expectation.satisfied?.should be_false # Sanity check.
end
end
def new_successful_result
new_met_expectation.eval.tap do |result|
result.successful?.should be_true # Sanity check.
end
end
def new_failure_result
new_unmet_expectation.eval.tap do |result|
result.successful?.should be_false # Sanity check.
end
end
def generate_results(success_count = 1, failure_count = 0)
successful = Array.new(success_count) { new_successful_result }
failures = Array.new(failure_count) { new_failure_result }
results = (successful + failures).shuffle
def generate_expectations(success_count = 1, failure_count = 0)
satisfied = Array.new(success_count) { new_satisfied_expectation }
unsatisfied = Array.new(failure_count) { new_unsatisfied_expectation }
expectations = (satisfied + unsatisfied).shuffle
reporter = Spectator::Expectations::ExpectationReporter.new(false)
results.each do |result|
reporter.report(result)
expectations.each do |expectation|
reporter.report(expectation)
end
{successful: successful, failures: failures, results: results, reporter: reporter}
{satisfied: satisfied, unsatisfied: unsatisfied, expectations: expectations, reporter: reporter}
end
def report_results(success_count = 1, failure_count = 0)
def report_expectations(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) }
success_count.times { harness.report_expectation(new_satisfied_expectation) }
failure_count.times { harness.report_expectation(new_unsatisfied_expectation) }
end