mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Add specs for value expectation
Fix bug in expectation result actual message.
This commit is contained in:
parent
bc66016c42
commit
9a77f8b7fd
2 changed files with 153 additions and 1 deletions
152
spec/expectations/value_expectation_spec.cr
Normal file
152
spec/expectations/value_expectation_spec.cr
Normal file
|
@ -0,0 +1,152 @@
|
|||
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.to_s, value)
|
||||
matcher = Spectator::Matchers::EqualityMatcher.new(value.to_s, 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.to_s, value)
|
||||
matcher = Spectator::Matchers::EqualityMatcher.new(value.to_s, 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.to_s, value1)
|
||||
matcher = Spectator::Matchers::EqualityMatcher.new(value2.to_s, 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.to_s, value1)
|
||||
matcher = Spectator::Matchers::EqualityMatcher.new(value2.to_s, 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.to_s, value)
|
||||
matcher = Spectator::Matchers::EqualityMatcher.new(value.to_s, 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.to_s, value)
|
||||
matcher = Spectator::Matchers::EqualityMatcher.new(value.to_s, 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.to_s, value)
|
||||
matcher = Spectator::Matchers::EqualityMatcher.new(value.to_s, 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.to_s, value1)
|
||||
matcher = Spectator::Matchers::EqualityMatcher.new(value2.to_s, 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.to_s, value1)
|
||||
matcher = Spectator::Matchers::EqualityMatcher.new(value2.to_s, 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.to_s, value)
|
||||
matcher = Spectator::Matchers::EqualityMatcher.new(value.to_s, 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)
|
||||
matcher.match?(partial).should be_true # Sanity check.
|
||||
expectation.satisfied?.should be_true
|
||||
end
|
||||
end
|
||||
|
||||
context "with an unsuccessful match" do
|
||||
it "is false" 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(partial, matcher)
|
||||
matcher.match?(partial).should be_false # Sanity check.
|
||||
expectation.satisfied?.should be_false
|
||||
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))
|
||||
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))
|
||||
end
|
||||
end
|
||||
end
|
|
@ -43,7 +43,7 @@ module Spectator::Expectations
|
|||
|
||||
# Description of what actually happened when the expectation was evaluated.
|
||||
def actual_message
|
||||
message(@successful)
|
||||
message(!@successful)
|
||||
end
|
||||
|
||||
# Retrieves the message or negated message from an expectation.
|
||||
|
|
Loading…
Reference in a new issue