2018-10-15 21:45:32 +00:00
|
|
|
require "../spec_helper"
|
|
|
|
|
|
|
|
describe Spectator::Expectations::ValueExpectationPartial do
|
|
|
|
describe "#actual" do
|
2018-10-19 17:01:22 +00:00
|
|
|
context "with a label" do
|
|
|
|
it "contains the value passed to the constructor" do
|
|
|
|
actual = 777
|
|
|
|
partial = Spectator::Expectations::ValueExpectationPartial.new(actual.to_s, actual)
|
|
|
|
partial.actual.should eq(actual)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "without a label" do
|
|
|
|
it "contains the value passed to the constructor" do
|
|
|
|
actual = 777
|
|
|
|
partial = Spectator::Expectations::ValueExpectationPartial.new(actual)
|
|
|
|
partial.actual.should eq(actual)
|
|
|
|
end
|
2018-10-15 21:45:32 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "#label" do
|
2018-10-19 03:52:00 +00:00
|
|
|
context "when provided" do
|
2018-10-15 21:45:32 +00:00
|
|
|
it "contains the value passed to the constructor" do
|
|
|
|
actual = 777
|
|
|
|
label = "lucky"
|
|
|
|
partial = Spectator::Expectations::ValueExpectationPartial.new(label, actual)
|
|
|
|
partial.label.should eq(label)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-10-19 03:52:00 +00:00
|
|
|
context "when omitted" do
|
2018-10-15 21:45:32 +00:00
|
|
|
it "contains a stringified version of #actual" do
|
|
|
|
actual = 777
|
2018-10-19 03:52:00 +00:00
|
|
|
partial = Spectator::Expectations::ValueExpectationPartial.new(actual)
|
2018-10-15 21:45:32 +00:00
|
|
|
partial.label.should eq(actual.to_s)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "#to" do
|
2018-11-14 20:10:42 +00:00
|
|
|
it "reports an expectation" do
|
|
|
|
spy = SpyExample.create do
|
|
|
|
actual = 777
|
|
|
|
expected = 777
|
|
|
|
partial = Spectator::Expectations::ValueExpectationPartial.new(actual)
|
|
|
|
matcher = Spectator::Matchers::EqualityMatcher.new(expected)
|
|
|
|
partial.to(matcher)
|
|
|
|
end
|
|
|
|
Spectator::Internals::Harness.run(spy)
|
|
|
|
spy.harness.expectations.size.should eq(1)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "reports multiple expectations" do
|
|
|
|
spy = SpyExample.create do
|
|
|
|
actual = 777
|
|
|
|
expected = 777
|
|
|
|
partial = Spectator::Expectations::ValueExpectationPartial.new(actual)
|
|
|
|
matcher = Spectator::Matchers::EqualityMatcher.new(expected)
|
|
|
|
5.times { partial.to(matcher) }
|
|
|
|
end
|
|
|
|
Spectator::Internals::Harness.run(spy)
|
|
|
|
spy.harness.expectations.size.should eq(5)
|
|
|
|
end
|
|
|
|
|
|
|
|
context "with a met condition" do
|
|
|
|
it "reports a satisifed expectation" do
|
|
|
|
spy = SpyExample.create do
|
|
|
|
actual = 777
|
|
|
|
expected = 777
|
|
|
|
partial = Spectator::Expectations::ValueExpectationPartial.new(actual)
|
|
|
|
matcher = Spectator::Matchers::EqualityMatcher.new(expected)
|
|
|
|
partial.to(matcher)
|
|
|
|
end
|
|
|
|
Spectator::Internals::Harness.run(spy)
|
|
|
|
spy.harness.expectations.first.satisfied?.should be_true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "with an unmet condition" do
|
|
|
|
it "reports an unsatisfied expectation" do
|
|
|
|
spy = SpyExample.create do
|
|
|
|
actual = 777
|
|
|
|
expected = 42
|
|
|
|
partial = Spectator::Expectations::ValueExpectationPartial.new(actual)
|
|
|
|
matcher = Spectator::Matchers::EqualityMatcher.new(expected)
|
|
|
|
partial.to(matcher)
|
|
|
|
end
|
|
|
|
Spectator::Internals::Harness.run(spy)
|
|
|
|
spy.harness.expectations.first.satisfied?.should be_false
|
|
|
|
end
|
|
|
|
end
|
2018-10-15 21:45:32 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
{% for method in [:to_not, :not_to] %}
|
|
|
|
describe "{{method.id}}" do
|
2018-11-14 20:10:42 +00:00
|
|
|
it "reports an expectation" do
|
|
|
|
spy = SpyExample.create do
|
|
|
|
actual = 777
|
|
|
|
expected = 777
|
|
|
|
partial = Spectator::Expectations::ValueExpectationPartial.new(actual)
|
|
|
|
matcher = Spectator::Matchers::EqualityMatcher.new(expected)
|
|
|
|
partial.{{method.id}}(matcher)
|
|
|
|
end
|
|
|
|
Spectator::Internals::Harness.run(spy)
|
|
|
|
spy.harness.expectations.size.should eq(1)
|
|
|
|
end
|
2018-10-15 21:45:32 +00:00
|
|
|
|
2018-11-14 20:10:42 +00:00
|
|
|
it "reports multiple expectations" do
|
|
|
|
spy = SpyExample.create do
|
|
|
|
actual = 777
|
|
|
|
expected = 42
|
|
|
|
partial = Spectator::Expectations::ValueExpectationPartial.new(actual)
|
|
|
|
matcher = Spectator::Matchers::EqualityMatcher.new(expected)
|
|
|
|
5.times { partial.{{method.id}}(matcher) }
|
|
|
|
end
|
|
|
|
Spectator::Internals::Harness.run(spy)
|
|
|
|
spy.harness.expectations.size.should eq(5)
|
|
|
|
end
|
|
|
|
|
|
|
|
context "with a met condition" do
|
|
|
|
it "reports an unsatisifed expectation" do
|
|
|
|
spy = SpyExample.create do
|
|
|
|
actual = 777
|
|
|
|
expected = 777
|
|
|
|
partial = Spectator::Expectations::ValueExpectationPartial.new(actual)
|
|
|
|
matcher = Spectator::Matchers::EqualityMatcher.new(expected)
|
|
|
|
partial.{{method.id}}(matcher)
|
|
|
|
end
|
|
|
|
Spectator::Internals::Harness.run(spy)
|
|
|
|
spy.harness.expectations.first.satisfied?.should be_false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "with an unmet condition" do
|
|
|
|
it "reports an satisfied expectation" do
|
|
|
|
spy = SpyExample.create do
|
|
|
|
actual = 777
|
|
|
|
expected = 42
|
|
|
|
partial = Spectator::Expectations::ValueExpectationPartial.new(actual)
|
|
|
|
matcher = Spectator::Matchers::EqualityMatcher.new(expected)
|
|
|
|
partial.{{method.id}}(matcher)
|
|
|
|
end
|
|
|
|
Spectator::Internals::Harness.run(spy)
|
|
|
|
spy.harness.expectations.first.satisfied?.should be_true
|
|
|
|
end
|
|
|
|
end
|
2018-10-15 21:45:32 +00:00
|
|
|
end
|
|
|
|
{% end %}
|
|
|
|
end
|