2018-10-18 23:54:43 +00:00
|
|
|
require "../spec_helper"
|
|
|
|
|
2019-01-31 20:30:09 +00:00
|
|
|
describe Spectator::Expectations::Expectation do
|
2018-11-14 09:15:55 +00:00
|
|
|
describe "#satisifed?" do
|
2018-10-18 23:54:43 +00:00
|
|
|
context "with a successful match" do
|
2018-11-14 09:15:55 +00:00
|
|
|
it "is true" do
|
2018-10-18 23:54:43 +00:00
|
|
|
value = 42
|
2019-02-15 00:04:59 +00:00
|
|
|
partial = new_partial(value)
|
2018-11-14 09:15:55 +00:00
|
|
|
matcher = Spectator::Matchers::EqualityMatcher.new(value.to_s, value)
|
2019-01-31 20:30:09 +00:00
|
|
|
expectation = Spectator::Expectations::Expectation.new(true, false, partial, matcher)
|
2018-10-18 23:54:43 +00:00
|
|
|
matcher.match?(partial).should be_true # Sanity check.
|
2018-11-14 09:15:55 +00:00
|
|
|
expectation.satisfied?.should be_true
|
2018-10-18 23:54:43 +00:00
|
|
|
end
|
|
|
|
|
2018-11-14 09:15:55 +00:00
|
|
|
context "when negated" do
|
|
|
|
it "is false" do
|
|
|
|
value = 42
|
2019-02-15 00:04:59 +00:00
|
|
|
partial = new_partial(value)
|
2018-11-14 09:15:55 +00:00
|
|
|
matcher = Spectator::Matchers::EqualityMatcher.new(value.to_s, value)
|
2019-01-31 20:30:09 +00:00
|
|
|
expectation = Spectator::Expectations::Expectation.new(true, true, partial, matcher)
|
2018-11-14 09:15:55 +00:00
|
|
|
matcher.match?(partial).should be_true # Sanity check.
|
|
|
|
expectation.satisfied?.should be_false
|
|
|
|
end
|
2018-10-18 23:54:43 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "with an unsuccessful match" do
|
2018-11-14 09:15:55 +00:00
|
|
|
it "is false" do
|
2018-10-18 23:54:43 +00:00
|
|
|
value1 = 42
|
|
|
|
value2 = 777
|
2019-02-15 00:04:59 +00:00
|
|
|
partial = new_partial(value1)
|
2018-11-14 09:15:55 +00:00
|
|
|
matcher = Spectator::Matchers::EqualityMatcher.new(value2.to_s, value2)
|
2019-01-31 20:30:09 +00:00
|
|
|
expectation = Spectator::Expectations::Expectation.new(false, false, partial, matcher)
|
2018-10-18 23:54:43 +00:00
|
|
|
matcher.match?(partial).should be_false # Sanity check.
|
2018-11-14 09:15:55 +00:00
|
|
|
expectation.satisfied?.should be_false
|
2018-10-18 23:54:43 +00:00
|
|
|
end
|
|
|
|
|
2018-11-14 09:15:55 +00:00
|
|
|
context "when negated" do
|
|
|
|
it "is true" do
|
|
|
|
value1 = 42
|
|
|
|
value2 = 777
|
2019-02-15 00:04:59 +00:00
|
|
|
partial = new_partial(value1)
|
2018-11-14 09:15:55 +00:00
|
|
|
matcher = Spectator::Matchers::EqualityMatcher.new(value2.to_s, value2)
|
2019-01-31 20:30:09 +00:00
|
|
|
expectation = Spectator::Expectations::Expectation.new(false, true, partial, matcher)
|
2018-11-14 09:15:55 +00:00
|
|
|
matcher.match?(partial).should be_false # Sanity check.
|
|
|
|
expectation.satisfied?.should be_true
|
|
|
|
end
|
2018-10-18 23:54:43 +00:00
|
|
|
end
|
|
|
|
end
|
2018-11-14 09:15:55 +00:00
|
|
|
end
|
2018-10-18 23:54:43 +00:00
|
|
|
|
2018-11-14 09:15:55 +00:00
|
|
|
describe "#actual_message" do
|
|
|
|
context "with a successful match" do
|
|
|
|
it "equals the matcher's #message" do
|
|
|
|
value = 42
|
2019-02-15 00:04:59 +00:00
|
|
|
partial = new_partial(value)
|
2018-11-14 09:15:55 +00:00
|
|
|
matcher = Spectator::Matchers::EqualityMatcher.new(value.to_s, value)
|
2019-01-31 20:30:09 +00:00
|
|
|
expectation = Spectator::Expectations::Expectation.new(true, false, partial, matcher)
|
2018-11-14 09:15:55 +00:00
|
|
|
matcher.match?(partial).should be_true # Sanity check.
|
|
|
|
expectation.actual_message.should eq(matcher.message(partial))
|
|
|
|
end
|
2018-10-18 23:54:43 +00:00
|
|
|
|
2018-11-14 09:15:55 +00:00
|
|
|
context "when negated" do
|
|
|
|
it "equals the matcher's #negated_message" do
|
2018-10-18 23:54:43 +00:00
|
|
|
value = 42
|
2019-02-15 00:04:59 +00:00
|
|
|
partial = new_partial(value)
|
2018-11-14 09:15:55 +00:00
|
|
|
matcher = Spectator::Matchers::EqualityMatcher.new(value.to_s, value)
|
2019-01-31 20:30:09 +00:00
|
|
|
expectation = Spectator::Expectations::Expectation.new(true, true, partial, matcher)
|
2018-10-18 23:54:43 +00:00
|
|
|
matcher.match?(partial).should be_true # Sanity check.
|
2018-11-14 09:15:55 +00:00
|
|
|
expectation.actual_message.should eq(matcher.negated_message(partial))
|
2018-10-18 23:54:43 +00:00
|
|
|
end
|
|
|
|
end
|
2018-11-14 09:15:55 +00:00
|
|
|
end
|
2018-10-18 23:54:43 +00:00
|
|
|
|
2018-11-14 09:15:55 +00:00
|
|
|
context "with an unsuccessful match" do
|
|
|
|
it "equals the matcher's #negated_message" do
|
|
|
|
value1 = 42
|
|
|
|
value2 = 777
|
2019-02-15 00:04:59 +00:00
|
|
|
partial = new_partial(value1)
|
2018-11-14 09:15:55 +00:00
|
|
|
matcher = Spectator::Matchers::EqualityMatcher.new(value2.to_s, value2)
|
2019-01-31 20:30:09 +00:00
|
|
|
expectation = Spectator::Expectations::Expectation.new(false, false, partial, matcher)
|
2018-11-14 09:15:55 +00:00
|
|
|
matcher.match?(partial).should be_false # Sanity check.
|
|
|
|
expectation.actual_message.should eq(matcher.negated_message(partial))
|
|
|
|
end
|
2018-10-18 23:54:43 +00:00
|
|
|
|
2018-11-14 09:15:55 +00:00
|
|
|
context "when negated" do
|
|
|
|
it "equals the matcher's #message" do
|
2018-10-18 23:54:43 +00:00
|
|
|
value1 = 42
|
|
|
|
value2 = 777
|
2019-02-15 00:04:59 +00:00
|
|
|
partial = new_partial(value1)
|
2018-11-14 09:15:55 +00:00
|
|
|
matcher = Spectator::Matchers::EqualityMatcher.new(value2.to_s, value2)
|
2019-01-31 20:30:09 +00:00
|
|
|
expectation = Spectator::Expectations::Expectation.new(false, true, partial, matcher)
|
2018-10-18 23:54:43 +00:00
|
|
|
matcher.match?(partial).should be_false # Sanity check.
|
2018-11-14 09:15:55 +00:00
|
|
|
expectation.actual_message.should eq(matcher.message(partial))
|
2018-10-18 23:54:43 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-11-14 09:15:55 +00:00
|
|
|
describe "#expected_message" do
|
2018-10-18 23:54:43 +00:00
|
|
|
context "with a successful match" do
|
2018-11-14 09:15:55 +00:00
|
|
|
it "equals the matcher's #message" do
|
2018-10-18 23:54:43 +00:00
|
|
|
value = 42
|
2019-02-15 00:04:59 +00:00
|
|
|
partial = new_partial(value)
|
2018-10-18 23:54:43 +00:00
|
|
|
matcher = Spectator::Matchers::EqualityMatcher.new(value.to_s, value)
|
2019-01-31 20:30:09 +00:00
|
|
|
expectation = Spectator::Expectations::Expectation.new(true, false, partial, matcher)
|
2018-10-18 23:54:43 +00:00
|
|
|
matcher.match?(partial).should be_true # Sanity check.
|
2018-11-14 09:15:55 +00:00
|
|
|
expectation.expected_message.should eq(matcher.message(partial))
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when negated" do
|
|
|
|
it "equals the matcher's #negated_message" do
|
|
|
|
value = 42
|
2019-02-15 00:04:59 +00:00
|
|
|
partial = new_partial(value)
|
2018-11-14 09:15:55 +00:00
|
|
|
matcher = Spectator::Matchers::EqualityMatcher.new(value.to_s, value)
|
2019-01-31 20:30:09 +00:00
|
|
|
expectation = Spectator::Expectations::Expectation.new(true, true, partial, matcher)
|
2018-11-14 09:15:55 +00:00
|
|
|
matcher.match?(partial).should be_true # Sanity check.
|
|
|
|
expectation.expected_message.should eq(matcher.negated_message(partial))
|
|
|
|
end
|
2018-10-18 23:54:43 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "with an unsuccessful match" do
|
2018-11-14 09:15:55 +00:00
|
|
|
it "equals the matcher's #message" do
|
2018-10-18 23:54:43 +00:00
|
|
|
value1 = 42
|
|
|
|
value2 = 777
|
2019-02-15 00:04:59 +00:00
|
|
|
partial = new_partial(value1)
|
2018-10-18 23:54:43 +00:00
|
|
|
matcher = Spectator::Matchers::EqualityMatcher.new(value2.to_s, value2)
|
2019-01-31 20:30:09 +00:00
|
|
|
expectation = Spectator::Expectations::Expectation.new(false, false, partial, matcher)
|
2018-10-18 23:54:43 +00:00
|
|
|
matcher.match?(partial).should be_false # Sanity check.
|
2018-11-14 09:15:55 +00:00
|
|
|
expectation.expected_message.should eq(matcher.message(partial))
|
2018-10-18 23:54:43 +00:00
|
|
|
end
|
|
|
|
|
2018-11-14 09:15:55 +00:00
|
|
|
context "when negated" do
|
|
|
|
it "equals the matcher's #negated_message" do
|
|
|
|
value1 = 42
|
|
|
|
value2 = 777
|
2019-02-15 00:04:59 +00:00
|
|
|
partial = new_partial(value1)
|
2018-11-14 09:15:55 +00:00
|
|
|
matcher = Spectator::Matchers::EqualityMatcher.new(value2.to_s, value2)
|
2019-01-31 20:30:09 +00:00
|
|
|
expectation = Spectator::Expectations::Expectation.new(false, true, partial, matcher)
|
2018-11-14 09:15:55 +00:00
|
|
|
matcher.match?(partial).should be_false # Sanity check.
|
|
|
|
expectation.expected_message.should eq(matcher.negated_message(partial))
|
|
|
|
end
|
|
|
|
end
|
2018-10-18 23:54:43 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|