mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Fix specs to work with new Expectation type
This commit is contained in:
parent
35b59854ec
commit
f0204a32ea
9 changed files with 379 additions and 395 deletions
207
spec/expectations/example_expectations_spec.cr
Normal file
207
spec/expectations/example_expectations_spec.cr
Normal file
|
@ -0,0 +1,207 @@
|
|||
require "../spec_helper"
|
||||
|
||||
describe Spectator::Expectations::ExampleExpectations do
|
||||
describe "#each" do
|
||||
it "yields all expectations" do
|
||||
tuple = generate_expectations(5, 5)
|
||||
expectations = [] of Spectator::Expectations::Expectation
|
||||
tuple[:reporter].expectations.each { |expectation| expectations << expectation }
|
||||
# Expectations might not be in the same order.
|
||||
# Just check if if the arrays contain the same items.
|
||||
expectations.size.should eq(tuple[:expectations].size)
|
||||
(expectations - tuple[:expectations]).empty?.should be_true
|
||||
end
|
||||
end
|
||||
|
||||
describe "#satisfied" do
|
||||
it "returns only satisfied expectations" do
|
||||
tuple = generate_expectations(5, 5)
|
||||
expectations = tuple[:reporter].expectations
|
||||
expectations.satisfied.all?(&.satisfied?).should be_true
|
||||
end
|
||||
|
||||
it "returns the correct expectations" do
|
||||
tuple = generate_expectations(5, 5)
|
||||
expectations = tuple[:reporter].expectations
|
||||
satisfied = expectations.satisfied.to_a
|
||||
satisfied.size.should eq(5)
|
||||
(satisfied - tuple[:satisfied]).empty?.should be_true
|
||||
end
|
||||
|
||||
context "with all satisfied expectations" do
|
||||
it "returns all expectations" do
|
||||
tuple = generate_expectations(5, 0)
|
||||
expectations = tuple[:reporter].expectations
|
||||
expectations.satisfied.size.should eq(tuple[:satisfied].size)
|
||||
end
|
||||
end
|
||||
|
||||
context "with all unsatisfied expectations" do
|
||||
it "returns an empty collection" do
|
||||
tuple = generate_expectations(0, 5)
|
||||
expectations = tuple[:reporter].expectations
|
||||
expectations.satisfied.size.should eq(0)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "#each_satisfied" do
|
||||
it "yields only satisfied expectations" do
|
||||
tuple = generate_expectations(5, 5)
|
||||
expectations = [] of Spectator::Expectations::Expectation
|
||||
tuple[:reporter].expectations.each_satisfied { |expectation| expectations << expectation }
|
||||
# Expectations might not be in the same order.
|
||||
# Just check if if the arrays contain the same items.
|
||||
expectations.size.should eq(tuple[:satisfied].size)
|
||||
(expectations - tuple[:satisfied]).empty?.should be_true
|
||||
end
|
||||
|
||||
context "with all satisfied expectations" do
|
||||
it "yields all expectations" do
|
||||
tuple = generate_expectations(0, 5)
|
||||
expectations = [] of Spectator::Expectations::Expectation
|
||||
tuple[:reporter].expectations.each_satisfied { |expectation| expectations << expectation }
|
||||
expectations.size.should eq(tuple[:satisfied].size)
|
||||
end
|
||||
end
|
||||
|
||||
context "with all unsatisfied expectations" do
|
||||
it "yields nothing" do
|
||||
tuple = generate_expectations(0, 5)
|
||||
expectations = [] of Spectator::Expectations::Expectation
|
||||
tuple[:reporter].expectations.each_satisfied { |expectation| expectations << expectation }
|
||||
expectations.empty?.should be_true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "#unsatisfied" do
|
||||
it "returns only unsatisfied expectations" do
|
||||
tuple = generate_expectations(5, 5)
|
||||
expectations = tuple[:reporter].expectations
|
||||
expectations.unsatisfied.all?(&.satisfied?).should be_false
|
||||
end
|
||||
|
||||
it "returns the correct expectations" do
|
||||
tuple = generate_expectations(5, 5)
|
||||
expectations = tuple[:reporter].expectations
|
||||
unsatisfied = expectations.unsatisfied.to_a
|
||||
unsatisfied.size.should eq(5)
|
||||
(unsatisfied - tuple[:unsatisfied]).empty?.should be_true
|
||||
end
|
||||
|
||||
context "with all satisfied expectations" do
|
||||
it "returns an empty collection" do
|
||||
tuple = generate_expectations(5, 0)
|
||||
expectations = tuple[:reporter].expectations
|
||||
expectations.unsatisfied.size.should eq(0)
|
||||
end
|
||||
end
|
||||
|
||||
context "with all unsatisfied expectations" do
|
||||
it "returns all expectations" do
|
||||
tuple = generate_expectations(0, 5)
|
||||
expectations = tuple[:reporter].expectations
|
||||
expectations.unsatisfied.size.should eq(tuple[:unsatisfied].size)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "#each_unsatisfied" do
|
||||
it "yields only unsatisfied expectations" do
|
||||
tuple = generate_expectations(5, 5)
|
||||
expectations = [] of Spectator::Expectations::Expectation
|
||||
tuple[:reporter].expectations.each_unsatisfied { |expectation| expectations << expectation }
|
||||
# Expectations might not be in the same order.
|
||||
# Just check if if the arrays contain the same items.
|
||||
expectations.size.should eq(tuple[:unsatisfied].size)
|
||||
(expectations - tuple[:unsatisfied]).empty?.should be_true
|
||||
end
|
||||
|
||||
context "with all satisfied expectations" do
|
||||
it "yields nothing" do
|
||||
tuple = generate_expectations(5, 0)
|
||||
expectations = [] of Spectator::Expectations::Expectation
|
||||
tuple[:reporter].expectations.each_unsatisfied { |expectation| expectations << expectation }
|
||||
expectations.empty?.should be_true
|
||||
end
|
||||
end
|
||||
|
||||
context "with all unsatisfied expectations" do
|
||||
it "yields all expectations" do
|
||||
tuple = generate_expectations(0, 5)
|
||||
expectations = [] of Spectator::Expectations::Expectation
|
||||
tuple[:reporter].expectations.each_unsatisfied { |expectation| expectations << expectation }
|
||||
expectations.size.should eq(tuple[:unsatisfied].size)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "#successful?" do
|
||||
context "with all satisfied expectations" do
|
||||
it "is true" do
|
||||
tuple = generate_expectations(5, 0)
|
||||
expectations = tuple[:reporter].expectations
|
||||
expectations.successful?.should be_true
|
||||
end
|
||||
end
|
||||
|
||||
context "with one unsatisfied expectation" do
|
||||
it "is false" do
|
||||
tuple = generate_expectations(5, 1)
|
||||
expectations = tuple[:reporter].expectations
|
||||
expectations.successful?.should be_false
|
||||
end
|
||||
end
|
||||
|
||||
context "with one satisfied expectation" do
|
||||
it "is false" do
|
||||
tuple = generate_expectations(1, 5)
|
||||
expectations = tuple[:reporter].expectations
|
||||
expectations.successful?.should be_false
|
||||
end
|
||||
end
|
||||
|
||||
context "with all unsatisfied expectations" do
|
||||
it "is false" do
|
||||
tuple = generate_expectations(0, 5)
|
||||
expectations = tuple[:reporter].expectations
|
||||
expectations.successful?.should be_false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "#failed?" do
|
||||
context "with all satisfied expectations" do
|
||||
it "is false" do
|
||||
tuple = generate_expectations(5, 0)
|
||||
expectations = tuple[:reporter].expectations
|
||||
expectations.failed?.should be_false
|
||||
end
|
||||
end
|
||||
|
||||
context "with one unsatisfied expectation" do
|
||||
it "is true" do
|
||||
tuple = generate_expectations(5, 1)
|
||||
expectations = tuple[:reporter].expectations
|
||||
expectations.failed?.should be_true
|
||||
end
|
||||
end
|
||||
|
||||
context "with one satisfied expectation" do
|
||||
it "is true" do
|
||||
tuple = generate_expectations(1, 5)
|
||||
expectations = tuple[:reporter].expectations
|
||||
expectations.failed?.should be_true
|
||||
end
|
||||
end
|
||||
|
||||
context "with all unsatisfied expectations" do
|
||||
it "is true" do
|
||||
tuple = generate_expectations(0, 5)
|
||||
expectations = tuple[:reporter].expectations
|
||||
expectations.failed?.should be_true
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -3,77 +3,77 @@ require "../spec_helper"
|
|||
describe Spectator::Expectations::ExpectationReporter do
|
||||
describe "#report" do
|
||||
context "with raise flag set" do
|
||||
context "given a successful result" do
|
||||
context "given a satisfied expectation" do
|
||||
it "stores the result" do
|
||||
result = new_successful_result
|
||||
expectation = new_satisfied_expectation
|
||||
reporter = Spectator::Expectations::ExpectationReporter.new(true)
|
||||
reporter.report(result)
|
||||
reporter.results.should contain(result)
|
||||
reporter.report(expectation)
|
||||
reporter.expectations.should contain(expectation)
|
||||
end
|
||||
end
|
||||
|
||||
context "given a failed result" do
|
||||
context "given a unsatisfied expectation" do
|
||||
it "raises and error" do
|
||||
result = new_failure_result
|
||||
expectation = new_unsatisfied_expectation
|
||||
reporter = Spectator::Expectations::ExpectationReporter.new(true)
|
||||
expect_raises(Spectator::ExpectationFailed) { reporter.report(result) }
|
||||
expect_raises(Spectator::ExpectationFailed) { reporter.report(expectation) }
|
||||
end
|
||||
|
||||
it "stores the result" do
|
||||
result = new_failure_result
|
||||
it "stores the expectation" do
|
||||
expectation = new_unsatisfied_expectation
|
||||
reporter = Spectator::Expectations::ExpectationReporter.new(true)
|
||||
begin
|
||||
reporter.report(result)
|
||||
reporter.report(expectation)
|
||||
rescue
|
||||
# Ignore error, not testing that in this example.
|
||||
end
|
||||
reporter.results.should contain(result)
|
||||
reporter.expectations.should contain(expectation)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "with raise flag not set" do
|
||||
context "given a successful result" do
|
||||
it "stores the result" do
|
||||
result = new_successful_result
|
||||
context "given a satisfied expectation" do
|
||||
it "stores the expectation" do
|
||||
expectation = new_satisfied_expectation
|
||||
reporter = Spectator::Expectations::ExpectationReporter.new(false)
|
||||
reporter.report(result)
|
||||
reporter.results.should contain(result)
|
||||
reporter.report(expectation)
|
||||
reporter.expectations.should contain(expectation)
|
||||
end
|
||||
end
|
||||
|
||||
context "given a failed result" do
|
||||
it "stores the result" do
|
||||
result = new_failure_result
|
||||
context "given a unsatisfied expectation" do
|
||||
it "stores the expectation" do
|
||||
expectation = new_unsatisfied_expectation
|
||||
reporter = Spectator::Expectations::ExpectationReporter.new(false)
|
||||
reporter.report(result)
|
||||
reporter.results.should contain(result)
|
||||
reporter.report(expectation)
|
||||
reporter.expectations.should contain(expectation)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "#results" do
|
||||
describe "#expectations" do
|
||||
context "with no expectations" do
|
||||
it "is empty" do
|
||||
reporter = Spectator::Expectations::ExpectationReporter.new
|
||||
reporter.results.size.should eq(0)
|
||||
reporter.expectations.size.should eq(0)
|
||||
end
|
||||
end
|
||||
|
||||
context "with multiple expectations" do
|
||||
it "contains all expectations" do
|
||||
result1 = new_successful_result
|
||||
result2 = new_failure_result
|
||||
expectation1 = new_satisfied_expectation
|
||||
expectation2 = new_unsatisfied_expectation
|
||||
reporter = Spectator::Expectations::ExpectationReporter.new(false)
|
||||
begin
|
||||
reporter.report(result1)
|
||||
reporter.report(result2)
|
||||
reporter.report(expectation1)
|
||||
reporter.report(expectation2)
|
||||
rescue
|
||||
# Ignore errors for this test.
|
||||
end
|
||||
reporter.results.should contain(result1)
|
||||
reporter.results.should contain(result2)
|
||||
reporter.expectations.should contain(expectation1)
|
||||
reporter.expectations.should contain(expectation2)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,207 +0,0 @@
|
|||
require "../spec_helper"
|
||||
|
||||
describe Spectator::Expectations::ExpectationResults do
|
||||
describe "#each" do
|
||||
it "yields all results" do
|
||||
tuple = generate_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
|
||||
|
||||
describe "#successes" do
|
||||
it "returns only successful results" do
|
||||
tuple = generate_results(5, 5)
|
||||
results = tuple[:reporter].results
|
||||
results.successes.all?(&.successful?).should be_true
|
||||
end
|
||||
|
||||
it "returns the correct results" do
|
||||
tuple = generate_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
|
||||
|
||||
context "with all successful results" do
|
||||
it "returns all results" do
|
||||
tuple = generate_results(5, 0)
|
||||
results = tuple[:reporter].results
|
||||
results.successes.size.should eq(tuple[:successful].size)
|
||||
end
|
||||
end
|
||||
|
||||
context "with all failure results" do
|
||||
it "returns an empty collection" do
|
||||
tuple = generate_results(0, 5)
|
||||
results = tuple[:reporter].results
|
||||
results.successes.size.should eq(0)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "#each_success" do
|
||||
it "yields only successful results" do
|
||||
tuple = generate_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
|
||||
|
||||
context "with all successful results" do
|
||||
it "yields all results" do
|
||||
tuple = generate_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
|
||||
|
||||
context "with all failure results" do
|
||||
it "yields nothing" do
|
||||
tuple = generate_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
|
||||
|
||||
describe "#failures" do
|
||||
it "returns only failed results" do
|
||||
tuple = generate_results(5, 5)
|
||||
results = tuple[:reporter].results
|
||||
results.failures.all?(&.failure?).should be_true
|
||||
end
|
||||
|
||||
it "returns the correct results" do
|
||||
tuple = generate_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
|
||||
|
||||
context "with all successful results" do
|
||||
it "returns an empty collection" do
|
||||
tuple = generate_results(5, 0)
|
||||
results = tuple[:reporter].results
|
||||
results.failures.size.should eq(0)
|
||||
end
|
||||
end
|
||||
|
||||
context "with all failure results" do
|
||||
it "returns all results" do
|
||||
tuple = generate_results(0, 5)
|
||||
results = tuple[:reporter].results
|
||||
results.failures.size.should eq(tuple[:failures].size)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "#each_failure" do
|
||||
it "yields only failed results" do
|
||||
tuple = generate_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
|
||||
|
||||
context "with all successful results" do
|
||||
it "yields nothing" do
|
||||
tuple = generate_results(5, 0)
|
||||
results = [] of Spectator::Expectations::Expectation::Result
|
||||
tuple[:reporter].results.each_failure { |result| results << result }
|
||||
results.empty?.should be_true
|
||||
end
|
||||
end
|
||||
|
||||
context "with all failure results" do
|
||||
it "yields all results" do
|
||||
tuple = generate_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
|
||||
|
||||
describe "#successful?" do
|
||||
context "with all successful results" do
|
||||
it "is true" do
|
||||
tuple = generate_results(5, 0)
|
||||
results = tuple[:reporter].results
|
||||
results.successful?.should be_true
|
||||
end
|
||||
end
|
||||
|
||||
context "with one failure result" do
|
||||
it "is false" do
|
||||
tuple = generate_results(5, 1)
|
||||
results = tuple[:reporter].results
|
||||
results.successful?.should be_false
|
||||
end
|
||||
end
|
||||
|
||||
context "with one successful result" do
|
||||
it "is false" do
|
||||
tuple = generate_results(1, 5)
|
||||
results = tuple[:reporter].results
|
||||
results.successful?.should be_false
|
||||
end
|
||||
end
|
||||
|
||||
context "with all failure results" do
|
||||
it "is false" do
|
||||
tuple = generate_results(0, 5)
|
||||
results = tuple[:reporter].results
|
||||
results.successful?.should be_false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "#failed?" do
|
||||
context "with all successful results" do
|
||||
it "is false" do
|
||||
tuple = generate_results(5, 0)
|
||||
results = tuple[:reporter].results
|
||||
results.failed?.should be_false
|
||||
end
|
||||
end
|
||||
|
||||
context "with one failure result" do
|
||||
it "is true" do
|
||||
tuple = generate_results(5, 1)
|
||||
results = tuple[:reporter].results
|
||||
results.failed?.should be_true
|
||||
end
|
||||
end
|
||||
|
||||
context "with one successful result" do
|
||||
it "is true" do
|
||||
tuple = generate_results(1, 5)
|
||||
results = tuple[:reporter].results
|
||||
results.failed?.should be_true
|
||||
end
|
||||
end
|
||||
|
||||
context "with all failure results" do
|
||||
it "is true" do
|
||||
tuple = generate_results(0, 5)
|
||||
results = tuple[:reporter].results
|
||||
results.failed?.should be_true
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,120 +1,27 @@
|
|||
require "../spec_helper"
|
||||
|
||||
describe Spectator::Expectations::ValueExpectation do
|
||||
describe "#eval" do
|
||||
context "with a successful match" do
|
||||
it "returns a successful result" do
|
||||
value = 42
|
||||
partial = Spectator::Expectations::ValueExpectationPartial.new(value)
|
||||
matcher = Spectator::Matchers::EqualityMatcher.new(value)
|
||||
expectation = Spectator::Expectations::ValueExpectation.new(partial, matcher)
|
||||
matcher.match?(partial).should be_true # Sanity check.
|
||||
expectation.eval.successful?.should be_true
|
||||
end
|
||||
|
||||
it "reports a successful actual message" do
|
||||
value = 42
|
||||
partial = Spectator::Expectations::ValueExpectationPartial.new(value)
|
||||
matcher = Spectator::Matchers::EqualityMatcher.new(value)
|
||||
expectation = Spectator::Expectations::ValueExpectation.new(partial, matcher)
|
||||
matcher.match?(partial).should be_true # Sanity check.
|
||||
expectation.eval.actual_message.should eq(expectation.message)
|
||||
end
|
||||
end
|
||||
|
||||
context "with an unsuccessful match" do
|
||||
it "returns an unsuccessful result" do
|
||||
value1 = 42
|
||||
value2 = 777
|
||||
partial = Spectator::Expectations::ValueExpectationPartial.new(value1)
|
||||
matcher = Spectator::Matchers::EqualityMatcher.new(value2)
|
||||
expectation = Spectator::Expectations::ValueExpectation.new(partial, matcher)
|
||||
matcher.match?(partial).should be_false # Sanity check.
|
||||
expectation.eval.successful?.should be_false
|
||||
end
|
||||
|
||||
it "reports an unsuccessful actual message" do
|
||||
value1 = 42
|
||||
value2 = 777
|
||||
partial = Spectator::Expectations::ValueExpectationPartial.new(value1)
|
||||
matcher = Spectator::Matchers::EqualityMatcher.new(value2)
|
||||
expectation = Spectator::Expectations::ValueExpectation.new(partial, matcher)
|
||||
matcher.match?(partial).should be_false # Sanity check.
|
||||
expectation.eval.actual_message.should eq(expectation.negated_message)
|
||||
end
|
||||
end
|
||||
|
||||
it "reports a non-negated expected message" do
|
||||
value = 42
|
||||
partial = Spectator::Expectations::ValueExpectationPartial.new(value)
|
||||
matcher = Spectator::Matchers::EqualityMatcher.new(value)
|
||||
expectation = Spectator::Expectations::ValueExpectation.new(partial, matcher)
|
||||
expectation.eval.expected_message.should eq(expectation.message)
|
||||
end
|
||||
|
||||
context "negated" do
|
||||
context "with a successful match" do
|
||||
it "returns an unsuccessful result" do
|
||||
value = 42
|
||||
partial = Spectator::Expectations::ValueExpectationPartial.new(value)
|
||||
matcher = Spectator::Matchers::EqualityMatcher.new(value)
|
||||
expectation = Spectator::Expectations::ValueExpectation.new(partial, matcher)
|
||||
matcher.match?(partial).should be_true # Sanity check.
|
||||
expectation.eval(true).successful?.should be_false
|
||||
end
|
||||
|
||||
it "reports an unsuccessful actual message" do
|
||||
value = 42
|
||||
partial = Spectator::Expectations::ValueExpectationPartial.new(value)
|
||||
matcher = Spectator::Matchers::EqualityMatcher.new(value)
|
||||
expectation = Spectator::Expectations::ValueExpectation.new(partial, matcher)
|
||||
matcher.match?(partial).should be_true # Sanity check.
|
||||
expectation.eval(true).actual_message.should eq(expectation.negated_message)
|
||||
end
|
||||
end
|
||||
|
||||
context "with an unsuccessful match" do
|
||||
it "returns a successful result" do
|
||||
value1 = 42
|
||||
value2 = 777
|
||||
partial = Spectator::Expectations::ValueExpectationPartial.new(value1)
|
||||
matcher = Spectator::Matchers::EqualityMatcher.new(value2)
|
||||
expectation = Spectator::Expectations::ValueExpectation.new(partial, matcher)
|
||||
matcher.match?(partial).should be_false # Sanity check.
|
||||
expectation.eval(true).successful?.should be_true
|
||||
end
|
||||
|
||||
it "reports a successful actual message" do
|
||||
value1 = 42
|
||||
value2 = 777
|
||||
partial = Spectator::Expectations::ValueExpectationPartial.new(value1)
|
||||
matcher = Spectator::Matchers::EqualityMatcher.new(value2)
|
||||
expectation = Spectator::Expectations::ValueExpectation.new(partial, matcher)
|
||||
matcher.match?(partial).should be_false # Sanity check.
|
||||
expectation.eval(true).actual_message.should eq(expectation.message)
|
||||
end
|
||||
end
|
||||
|
||||
it "reports a negated expected message" do
|
||||
value = 42
|
||||
partial = Spectator::Expectations::ValueExpectationPartial.new(value)
|
||||
matcher = Spectator::Matchers::EqualityMatcher.new(value)
|
||||
expectation = Spectator::Expectations::ValueExpectation.new(partial, matcher)
|
||||
expectation.eval(true).expected_message.should eq(expectation.negated_message)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "#satisifed?" do
|
||||
context "with a successful match" do
|
||||
it "is true" do
|
||||
value = 42
|
||||
partial = Spectator::Expectations::ValueExpectationPartial.new(value.to_s, value)
|
||||
matcher = Spectator::Matchers::EqualityMatcher.new(value.to_s, value)
|
||||
expectation = Spectator::Expectations::ValueExpectation.new(partial, matcher)
|
||||
expectation = Spectator::Expectations::ValueExpectation.new(true, false, partial, matcher)
|
||||
matcher.match?(partial).should be_true # Sanity check.
|
||||
expectation.satisfied?.should be_true
|
||||
end
|
||||
|
||||
context "when negated" do
|
||||
it "is false" do
|
||||
value = 42
|
||||
partial = Spectator::Expectations::ValueExpectationPartial.new(value.to_s, value)
|
||||
matcher = Spectator::Matchers::EqualityMatcher.new(value.to_s, value)
|
||||
expectation = Spectator::Expectations::ValueExpectation.new(true, true, partial, matcher)
|
||||
matcher.match?(partial).should be_true # Sanity check.
|
||||
expectation.satisfied?.should be_false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "with an unsuccessful match" do
|
||||
|
@ -123,30 +30,118 @@ describe Spectator::Expectations::ValueExpectation do
|
|||
value2 = 777
|
||||
partial = Spectator::Expectations::ValueExpectationPartial.new(value1.to_s, value1)
|
||||
matcher = Spectator::Matchers::EqualityMatcher.new(value2.to_s, value2)
|
||||
expectation = Spectator::Expectations::ValueExpectation.new(partial, matcher)
|
||||
expectation = Spectator::Expectations::ValueExpectation.new(false, false, partial, matcher)
|
||||
matcher.match?(partial).should be_false # Sanity check.
|
||||
expectation.satisfied?.should be_false
|
||||
end
|
||||
|
||||
context "when negated" do
|
||||
it "is true" do
|
||||
value1 = 42
|
||||
value2 = 777
|
||||
partial = Spectator::Expectations::ValueExpectationPartial.new(value1.to_s, value1)
|
||||
matcher = Spectator::Matchers::EqualityMatcher.new(value2.to_s, value2)
|
||||
expectation = Spectator::Expectations::ValueExpectation.new(false, true, partial, matcher)
|
||||
matcher.match?(partial).should be_false # Sanity check.
|
||||
expectation.satisfied?.should be_true
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "#message" do
|
||||
it "equals the matcher's #message" do
|
||||
value = 42
|
||||
partial = Spectator::Expectations::ValueExpectationPartial.new(value.to_s, value)
|
||||
matcher = Spectator::Matchers::EqualityMatcher.new(value.to_s, value)
|
||||
expectation = Spectator::Expectations::ValueExpectation.new(partial, matcher)
|
||||
expectation.message.should eq(matcher.message(partial))
|
||||
describe "#actual_message" do
|
||||
context "with a successful match" do
|
||||
it "equals the matcher's #message" do
|
||||
value = 42
|
||||
partial = Spectator::Expectations::ValueExpectationPartial.new(value.to_s, value)
|
||||
matcher = Spectator::Matchers::EqualityMatcher.new(value.to_s, value)
|
||||
expectation = Spectator::Expectations::ValueExpectation.new(true, false, partial, matcher)
|
||||
matcher.match?(partial).should be_true # Sanity check.
|
||||
expectation.actual_message.should eq(matcher.message(partial))
|
||||
end
|
||||
|
||||
context "when negated" do
|
||||
it "equals the matcher's #negated_message" do
|
||||
value = 42
|
||||
partial = Spectator::Expectations::ValueExpectationPartial.new(value.to_s, value)
|
||||
matcher = Spectator::Matchers::EqualityMatcher.new(value.to_s, value)
|
||||
expectation = Spectator::Expectations::ValueExpectation.new(true, true, partial, matcher)
|
||||
matcher.match?(partial).should be_true # Sanity check.
|
||||
expectation.actual_message.should eq(matcher.negated_message(partial))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "with an unsuccessful match" do
|
||||
it "equals the matcher's #negated_message" do
|
||||
value1 = 42
|
||||
value2 = 777
|
||||
partial = Spectator::Expectations::ValueExpectationPartial.new(value1.to_s, value1)
|
||||
matcher = Spectator::Matchers::EqualityMatcher.new(value2.to_s, value2)
|
||||
expectation = Spectator::Expectations::ValueExpectation.new(false, false, partial, matcher)
|
||||
matcher.match?(partial).should be_false # Sanity check.
|
||||
expectation.actual_message.should eq(matcher.negated_message(partial))
|
||||
end
|
||||
|
||||
context "when negated" do
|
||||
it "equals the matcher's #message" do
|
||||
value1 = 42
|
||||
value2 = 777
|
||||
partial = Spectator::Expectations::ValueExpectationPartial.new(value1.to_s, value1)
|
||||
matcher = Spectator::Matchers::EqualityMatcher.new(value2.to_s, value2)
|
||||
expectation = Spectator::Expectations::ValueExpectation.new(false, true, partial, matcher)
|
||||
matcher.match?(partial).should be_false # Sanity check.
|
||||
expectation.actual_message.should eq(matcher.message(partial))
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "#negated_message" do
|
||||
it "equals the matcher's #negated_message" do
|
||||
value = 42
|
||||
partial = Spectator::Expectations::ValueExpectationPartial.new(value.to_s, value)
|
||||
matcher = Spectator::Matchers::EqualityMatcher.new(value.to_s, value)
|
||||
expectation = Spectator::Expectations::ValueExpectation.new(partial, matcher)
|
||||
expectation.negated_message.should eq(matcher.negated_message(partial))
|
||||
describe "#expected_message" do
|
||||
context "with a successful match" do
|
||||
it "equals the matcher's #message" do
|
||||
value = 42
|
||||
partial = Spectator::Expectations::ValueExpectationPartial.new(value.to_s, value)
|
||||
matcher = Spectator::Matchers::EqualityMatcher.new(value.to_s, value)
|
||||
expectation = Spectator::Expectations::ValueExpectation.new(true, false, partial, matcher)
|
||||
matcher.match?(partial).should be_true # Sanity check.
|
||||
expectation.expected_message.should eq(matcher.message(partial))
|
||||
end
|
||||
|
||||
context "when negated" do
|
||||
it "equals the matcher's #negated_message" do
|
||||
value = 42
|
||||
partial = Spectator::Expectations::ValueExpectationPartial.new(value.to_s, value)
|
||||
matcher = Spectator::Matchers::EqualityMatcher.new(value.to_s, value)
|
||||
expectation = Spectator::Expectations::ValueExpectation.new(true, true, partial, matcher)
|
||||
matcher.match?(partial).should be_true # Sanity check.
|
||||
expectation.expected_message.should eq(matcher.negated_message(partial))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "with an unsuccessful match" do
|
||||
it "equals the matcher's #message" do
|
||||
value1 = 42
|
||||
value2 = 777
|
||||
partial = Spectator::Expectations::ValueExpectationPartial.new(value1.to_s, value1)
|
||||
matcher = Spectator::Matchers::EqualityMatcher.new(value2.to_s, value2)
|
||||
expectation = Spectator::Expectations::ValueExpectation.new(false, false, partial, matcher)
|
||||
matcher.match?(partial).should be_false # Sanity check.
|
||||
expectation.expected_message.should eq(matcher.message(partial))
|
||||
end
|
||||
|
||||
context "when negated" do
|
||||
it "equals the matcher's #negated_message" do
|
||||
value1 = 42
|
||||
value2 = 777
|
||||
partial = Spectator::Expectations::ValueExpectationPartial.new(value1.to_s, value1)
|
||||
matcher = Spectator::Matchers::EqualityMatcher.new(value2.to_s, value2)
|
||||
expectation = Spectator::Expectations::ValueExpectation.new(false, true, partial, matcher)
|
||||
matcher.match?(partial).should be_false # Sanity check.
|
||||
expectation.expected_message.should eq(matcher.negated_message(partial))
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -7,7 +7,7 @@ class FailingExample < Spectator::RunnableExample
|
|||
|
||||
# Run the example that always fails.
|
||||
private def run_instance
|
||||
report_results(0, 1)
|
||||
report_expectations(0, 1)
|
||||
end
|
||||
|
||||
# Creates a failing example.
|
||||
|
|
|
@ -21,7 +21,7 @@ class PassingExample < Spectator::RunnableExample
|
|||
# Run the example that always passes.
|
||||
# If this doesn't something broke.
|
||||
private def run_instance
|
||||
report_results(1, 0)
|
||||
report_expectations(1, 0)
|
||||
end
|
||||
|
||||
# Creates a passing example.
|
||||
|
|
|
@ -54,14 +54,14 @@ describe Spectator::Internals::Harness do
|
|||
context "with a successful result" do
|
||||
it "stores the result" do
|
||||
error = nil.as(Exception?)
|
||||
success = new_successful_result
|
||||
expectation = new_satisfied_expectation
|
||||
spy = SpyExample.create do
|
||||
harness = Spectator::Internals::Harness.current
|
||||
harness.report_expectation(success)
|
||||
harness.report_expectation(expectation)
|
||||
end
|
||||
result = Spectator::Internals::Harness.run(spy)
|
||||
result.should be_a(Spectator::SuccessfulResult)
|
||||
result.as(Spectator::SuccessfulResult).expectations.should contain(success)
|
||||
result.as(Spectator::SuccessfulResult).expectations.should contain(expectation)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -71,7 +71,7 @@ describe Spectator::Internals::Harness do
|
|||
spy = SpyExample.create do
|
||||
harness = Spectator::Internals::Harness.current
|
||||
begin
|
||||
harness.report_expectation(new_failure_result)
|
||||
harness.report_expectation(new_unsatisfied_expectation)
|
||||
rescue ex
|
||||
error = ex
|
||||
end
|
||||
|
@ -82,30 +82,30 @@ describe Spectator::Internals::Harness do
|
|||
|
||||
it "stores the result" do
|
||||
error = nil.as(Exception?)
|
||||
failure = new_failure_result
|
||||
expectation = new_unsatisfied_expectation
|
||||
spy = SpyExample.create do
|
||||
harness = Spectator::Internals::Harness.current
|
||||
harness.report_expectation(failure)
|
||||
harness.report_expectation(expectation)
|
||||
end
|
||||
result = Spectator::Internals::Harness.run(spy)
|
||||
result.should be_a(Spectator::FailedResult)
|
||||
result.as(Spectator::FailedResult).expectations.should contain(failure)
|
||||
result.as(Spectator::FailedResult).expectations.should contain(expectation)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "#expectation_results" do
|
||||
it "contains the reported results" do
|
||||
results = [new_successful_result, new_failure_result]
|
||||
expectations = [new_satisfied_expectation, new_unsatisfied_expectation]
|
||||
spy = SpyExample.create do
|
||||
harness = Spectator::Internals::Harness.current
|
||||
results.each do |result|
|
||||
harness.report_expectation(result)
|
||||
expectations.each do |expectation|
|
||||
harness.report_expectation(expectation)
|
||||
end
|
||||
end
|
||||
result = Spectator::Internals::Harness.run(spy)
|
||||
reported_results = result.as(Spectator::FailedResult).expectations.to_a
|
||||
(results - reported_results).size.should eq(0)
|
||||
(expectations - reported_results).size.should eq(0)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -23,7 +23,7 @@ module Spectator::Expectations
|
|||
|
||||
# Text that indicates what the outcome was.
|
||||
def actual_message
|
||||
@matched ? message : negated_message
|
||||
satisfied? ? message : negated_message
|
||||
end
|
||||
|
||||
# Describes the condition that must be met for the matcher to be satisifed.
|
||||
|
|
Loading…
Reference in a new issue