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-28 22:17:12 +00:00
|
|
|
match_data = new_matcher(value).match(new_partial(value))
|
|
|
|
match_data.matched?.should be_true # Sanity check.
|
2019-02-28 18:07:16 +00:00
|
|
|
expectation = Spectator::Expectations::Expectation.new(match_data, false)
|
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-28 22:17:12 +00:00
|
|
|
match_data = new_matcher(value).match(new_partial(value))
|
|
|
|
match_data.matched?.should be_true # Sanity check.
|
2019-02-28 18:07:16 +00:00
|
|
|
expectation = Spectator::Expectations::Expectation.new(match_data, true)
|
2018-11-14 09:15:55 +00:00
|
|
|
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
|
2019-02-28 22:17:12 +00:00
|
|
|
match_data = new_matcher(42).match(new_partial(777))
|
|
|
|
match_data.matched?.should be_false # Sanity check.
|
2019-02-28 18:07:16 +00:00
|
|
|
expectation = Spectator::Expectations::Expectation.new(match_data, false)
|
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
|
2019-02-28 22:17:12 +00:00
|
|
|
match_data = new_matcher(42).match(new_partial(777))
|
|
|
|
match_data.matched?.should be_false # Sanity check.
|
2019-02-28 18:07:16 +00:00
|
|
|
expectation = Spectator::Expectations::Expectation.new(match_data, true)
|
2018-11-14 09:15:55 +00:00
|
|
|
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
|
|
|
|
2019-02-28 23:35:50 +00:00
|
|
|
describe "#values" do
|
|
|
|
it "is the same as the match data values" do
|
|
|
|
value = 42
|
|
|
|
match_data = new_matcher(value).match(new_partial(value))
|
|
|
|
expectation = Spectator::Expectations::Expectation.new(match_data, false)
|
2019-03-07 23:12:23 +00:00
|
|
|
expectation_values = expectation.values
|
2019-03-22 17:07:56 +00:00
|
|
|
match_data.values.zip(expectation_values).each do |m, e|
|
|
|
|
m.label.should eq(e.label)
|
2019-03-22 17:55:04 +00:00
|
|
|
m.value.value.should eq(e.value.value)
|
2019-03-07 23:12:23 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when negated" do
|
|
|
|
it "negates all negatable values" do
|
|
|
|
value = 42
|
|
|
|
match_data = new_matcher(value).match(new_partial(value))
|
|
|
|
expectation = Spectator::Expectations::Expectation.new(match_data, true)
|
2019-03-22 17:07:56 +00:00
|
|
|
expectation.values.each do |labeled_value|
|
2019-04-06 18:48:41 +00:00
|
|
|
label = labeled_value.label
|
2019-03-22 17:07:56 +00:00
|
|
|
value = labeled_value.value
|
2019-04-06 18:48:41 +00:00
|
|
|
value.to_s.should start_with(/not/i) if label == :expected
|
2019-03-07 23:12:23 +00:00
|
|
|
end
|
|
|
|
end
|
2019-02-28 23:35:50 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
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-28 22:17:12 +00:00
|
|
|
match_data = new_matcher(value).match(new_partial(value))
|
2019-02-28 20:52:01 +00:00
|
|
|
match_data.matched?.should be_true # Sanity check.
|
2019-02-28 18:07:16 +00:00
|
|
|
expectation = Spectator::Expectations::Expectation.new(match_data, false)
|
2019-02-28 20:52:01 +00:00
|
|
|
expectation.actual_message.should eq(match_data.message)
|
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 "when negated" do
|
2019-03-06 19:01:32 +00:00
|
|
|
it "equals the matcher's #message" do
|
2018-10-18 23:54:43 +00:00
|
|
|
value = 42
|
2019-02-28 22:17:12 +00:00
|
|
|
match_data = new_matcher(value).match(new_partial(value))
|
|
|
|
match_data.matched?.should be_true # Sanity check.
|
2019-02-28 18:07:16 +00:00
|
|
|
expectation = Spectator::Expectations::Expectation.new(match_data, true)
|
2019-03-06 19:01:32 +00:00
|
|
|
expectation.actual_message.should eq(match_data.message)
|
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
|
2019-02-28 22:17:12 +00:00
|
|
|
match_data = new_matcher(42).match(new_partial(777))
|
|
|
|
match_data.matched?.should be_false # Sanity check.
|
2019-02-28 18:07:16 +00:00
|
|
|
expectation = Spectator::Expectations::Expectation.new(match_data, false)
|
2019-02-28 20:52:01 +00:00
|
|
|
expectation.actual_message.should eq(match_data.negated_message)
|
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 "when negated" do
|
2019-03-06 19:01:32 +00:00
|
|
|
it "equals the matcher's #negated_message" do
|
2019-02-28 22:17:12 +00:00
|
|
|
match_data = new_matcher(42).match(new_partial(777))
|
|
|
|
match_data.matched?.should be_false # Sanity check.
|
2019-02-28 18:07:16 +00:00
|
|
|
expectation = Spectator::Expectations::Expectation.new(match_data, true)
|
2019-03-06 19:01:32 +00:00
|
|
|
expectation.actual_message.should eq(match_data.negated_message)
|
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-28 22:17:12 +00:00
|
|
|
match_data = new_matcher(value).match(new_partial(value))
|
|
|
|
match_data.matched?.should be_true # Sanity check.
|
2019-02-28 18:07:16 +00:00
|
|
|
expectation = Spectator::Expectations::Expectation.new(match_data, false)
|
2019-02-28 20:52:01 +00:00
|
|
|
expectation.expected_message.should eq(match_data.message)
|
2018-11-14 09:15:55 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
context "when negated" do
|
|
|
|
it "equals the matcher's #negated_message" do
|
|
|
|
value = 42
|
2019-02-28 22:17:12 +00:00
|
|
|
match_data = new_matcher(value).match(new_partial(value))
|
|
|
|
match_data.matched?.should be_true # Sanity check.
|
2019-02-28 18:07:16 +00:00
|
|
|
expectation = Spectator::Expectations::Expectation.new(match_data, true)
|
2019-02-28 20:52:01 +00:00
|
|
|
expectation.expected_message.should eq(match_data.negated_message)
|
2018-11-14 09:15:55 +00:00
|
|
|
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
|
2019-02-28 22:17:12 +00:00
|
|
|
match_data = new_matcher(42).match(new_partial(777))
|
|
|
|
match_data.matched?.should be_false # Sanity check.
|
2019-02-28 18:07:16 +00:00
|
|
|
expectation = Spectator::Expectations::Expectation.new(match_data, false)
|
2019-02-28 20:52:01 +00:00
|
|
|
expectation.expected_message.should eq(match_data.message)
|
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
|
2019-02-28 22:17:12 +00:00
|
|
|
match_data = new_matcher(42).match(new_partial(777))
|
|
|
|
match_data.matched?.should be_false # Sanity check.
|
2019-02-28 18:07:16 +00:00
|
|
|
expectation = Spectator::Expectations::Expectation.new(match_data, true)
|
2019-02-28 20:52:01 +00:00
|
|
|
expectation.expected_message.should eq(match_data.negated_message)
|
2018-11-14 09:15:55 +00:00
|
|
|
end
|
|
|
|
end
|
2018-10-18 23:54:43 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|