Implement ExpectationResults specs and fix typo

This commit is contained in:
Michael Miller 2018-10-19 16:27:59 -06:00
parent 703a791f78
commit 67e192edc6
3 changed files with 109 additions and 24 deletions

View file

@ -3,78 +3,136 @@ require "../spec_helper"
describe Spectator::Expectations::ExpectationResults do describe Spectator::Expectations::ExpectationResults do
describe "#each" do describe "#each" do
it "yields all results" do it "yields all results" do
fail "Test not implemented" tuple = report_results(5, 5)
results = [] of Spectator::Expectations::Expectation::Result
tuple[:reporter].results.each { |result| results << result }
# Results might not be in the same order.
# Just check if if the arrays contain the same items.
results.size.should eq(tuple[:results].size)
(results - tuple[:results]).empty?.should be_true
end end
end end
describe "#successes" do describe "#successes" do
it "returns only successful results" do it "returns only successful results" do
fail "Test not implemented" tuple = report_results(5, 5)
results = tuple[:reporter].results
results.successes.all?(&.successful?).should be_true
end
it "returns the correct results" do
tuple = report_results(5, 5)
results = tuple[:reporter].results
successful = results.successes.to_a
successful.size.should eq(5)
(successful - tuple[:successful]).empty?.should be_true
end end
context "with all successful results" do context "with all successful results" do
it "returns all results" do it "returns all results" do
fail "Test not implemented" tuple = report_results(5, 0)
results = tuple[:reporter].results
results.successes.size.should eq(tuple[:successful].size)
end end
end end
context "with all failure results" do context "with all failure results" do
it "returns an empty collection" do it "returns an empty collection" do
fail "Test not implemented" tuple = report_results(0, 5)
results = tuple[:reporter].results
results.successes.size.should eq(0)
end end
end end
end end
describe "#each_success" do describe "#each_success" do
it "yields only successful results" do it "yields only successful results" do
fail "Test not implemented" tuple = report_results(5, 5)
results = [] of Spectator::Expectations::Expectation::Result
tuple[:reporter].results.each_success { |result| results << result }
# Results might not be in the same order.
# Just check if if the arrays contain the same items.
results.size.should eq(tuple[:successful].size)
(results - tuple[:successful]).empty?.should be_true
end end
context "with all successful results" do context "with all successful results" do
it "yields all results" do it "yields all results" do
fail "Test not implemented" tuple = report_results(0, 5)
results = [] of Spectator::Expectations::Expectation::Result
tuple[:reporter].results.each_success { |result| results << result }
results.size.should eq(tuple[:successful].size)
end end
end end
context "with all failure results" do context "with all failure results" do
it "yields nothing" do it "yields nothing" do
fail "Test not implemented" tuple = report_results(0, 5)
results = [] of Spectator::Expectations::Expectation::Result
tuple[:reporter].results.each_success { |result| results << result }
results.empty?.should be_true
end end
end end
end end
describe "#failures" do describe "#failures" do
it "returns only failed results" do it "returns only failed results" do
fail "Test not implemented" tuple = report_results(5, 5)
results = tuple[:reporter].results
results.failures.all?(&.failure?).should be_true
end
it "returns the correct results" do
tuple = report_results(5, 5)
results = tuple[:reporter].results
failures = results.failures.to_a
failures.size.should eq(5)
(failures - tuple[:failures]).empty?.should be_true
end end
context "with all successful results" do context "with all successful results" do
it "returns an empty collection" do it "returns an empty collection" do
fail "Test not implemented" tuple = report_results(5, 0)
results = tuple[:reporter].results
results.failures.size.should eq(0)
end end
end end
context "with all failure results" do context "with all failure results" do
it "returns all results" do it "returns all results" do
fail "Test not implemented" tuple = report_results(0, 5)
results = tuple[:reporter].results
results.failures.size.should eq(tuple[:failures].size)
end end
end end
end end
describe "#each_failure" do describe "#each_failure" do
it "yields only failed results" do it "yields only failed results" do
fail "Test not implemented" tuple = report_results(5, 5)
results = [] of Spectator::Expectations::Expectation::Result
tuple[:reporter].results.each_failure { |result| results << result }
# Results might not be in the same order.
# Just check if if the arrays contain the same items.
results.size.should eq(tuple[:failures].size)
(results - tuple[:failures]).empty?.should be_true
end end
context "with all successful results" do context "with all successful results" do
it "yields nothing" do it "yields nothing" do
fail "Test not implemented" tuple = report_results(5, 0)
results = [] of Spectator::Expectations::Expectation::Result
tuple[:reporter].results.each_failure { |result| results << result }
results.empty?.should be_true
end end
end end
context "with one failure result" do context "with all failure results" do
it "yields the one failed result" do it "yields all results" do
fail "Test not implemented" tuple = report_results(0, 5)
results = [] of Spectator::Expectations::Expectation::Result
tuple[:reporter].results.each_failure { |result| results << result }
results.size.should eq(tuple[:failures].size)
end end
end end
end end
@ -82,25 +140,33 @@ describe Spectator::Expectations::ExpectationResults do
describe "#successful?" do describe "#successful?" do
context "with all successful results" do context "with all successful results" do
it "is true" do it "is true" do
fail "Test not implemented" tuple = report_results(5, 0)
results = tuple[:reporter].results
results.successful?.should be_true
end end
end end
context "with one failure result" do context "with one failure result" do
it "is false" do it "is false" do
fail "Test not implemented" tuple = report_results(5, 1)
results = tuple[:reporter].results
results.successful?.should be_false
end end
end end
context "with one successful result" do context "with one successful result" do
it "is false" do it "is false" do
fail "Test not implemented" tuple = report_results(1, 5)
results = tuple[:reporter].results
results.successful?.should be_false
end end
end end
context "with all failure results" do context "with all failure results" do
it "is false" do it "is false" do
fail "Test not implemented" tuple = report_results(0, 5)
results = tuple[:reporter].results
results.successful?.should be_false
end end
end end
end end
@ -108,25 +174,33 @@ describe Spectator::Expectations::ExpectationResults do
describe "#failed?" do describe "#failed?" do
context "with all successful results" do context "with all successful results" do
it "is false" do it "is false" do
fail "Test not implemented" tuple = report_results(5, 0)
results = tuple[:reporter].results
results.failed?.should be_false
end end
end end
context "with one failure result" do context "with one failure result" do
it "is true" do it "is true" do
fail "Test not implemented" tuple = report_results(5, 1)
results = tuple[:reporter].results
results.failed?.should be_true
end end
end end
context "with one successful result" do context "with one successful result" do
it "is true" do it "is true" do
fail "Test not implemented" tuple = report_results(1, 5)
results = tuple[:reporter].results
results.failed?.should be_true
end end
end end
context "with all failure results" do context "with all failure results" do
it "is true" do it "is true" do
fail "Test not implemented" tuple = report_results(0, 5)
results = tuple[:reporter].results
results.failed?.should be_true
end end
end end
end end

View file

@ -41,3 +41,14 @@ def new_failure_result
result.successful?.should be_false # Sanity check. result.successful?.should be_false # Sanity check.
end end
end end
def report_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
reporter = Spectator::Expectations::ExpectationReporter.new(false)
results.each do |result|
reporter.report(result)
end
{successful: successful, failures: failures, results: results, reporter: reporter}
end

View file

@ -27,7 +27,7 @@ module Spectator::Expectations
end end
# Returns a collection of only the failed expectation results. # Returns a collection of only the failed expectation results.
def failures : Enumerables(Expectation::Result) def failures : Enumerable(Expectation::Result)
@results.select(&.failure?) @results.select(&.failure?)
end end