Swap label and expected value parameters

This matches the partial initializer parameters.
Also cleaned up some code in the Expectation spec.
This commit is contained in:
Michael Miller 2019-02-28 15:17:12 -07:00
parent f3e50c6432
commit 5ba03a90ff
20 changed files with 74 additions and 110 deletions

View file

@ -5,10 +5,8 @@ describe Spectator::Expectations::Expectation do
context "with a successful match" do context "with a successful match" do
it "is true" do it "is true" do
value = 42 value = 42
partial = new_partial(value) match_data = new_matcher(value).match(new_partial(value))
matcher = Spectator::Matchers::EqualityMatcher.new(value.to_s, value) match_data.matched?.should be_true # Sanity check.
match_data = matcher.match(partial)
matcher.match(partial).matched?.should be_true # Sanity check.
expectation = Spectator::Expectations::Expectation.new(match_data, false) expectation = Spectator::Expectations::Expectation.new(match_data, false)
expectation.satisfied?.should be_true expectation.satisfied?.should be_true
end end
@ -16,10 +14,8 @@ describe Spectator::Expectations::Expectation do
context "when negated" do context "when negated" do
it "is false" do it "is false" do
value = 42 value = 42
partial = new_partial(value) match_data = new_matcher(value).match(new_partial(value))
matcher = Spectator::Matchers::EqualityMatcher.new(value.to_s, value) match_data.matched?.should be_true # Sanity check.
match_data = matcher.match(partial)
matcher.match(partial).matched?.should be_true # Sanity check.
expectation = Spectator::Expectations::Expectation.new(match_data, true) expectation = Spectator::Expectations::Expectation.new(match_data, true)
expectation.satisfied?.should be_false expectation.satisfied?.should be_false
end end
@ -28,24 +24,16 @@ describe Spectator::Expectations::Expectation do
context "with an unsuccessful match" do context "with an unsuccessful match" do
it "is false" do it "is false" do
value1 = 42 match_data = new_matcher(42).match(new_partial(777))
value2 = 777 match_data.matched?.should be_false # Sanity check.
partial = new_partial(value1)
matcher = Spectator::Matchers::EqualityMatcher.new(value2.to_s, value2)
match_data = matcher.match(partial)
matcher.match(partial).matched?.should be_false # Sanity check.
expectation = Spectator::Expectations::Expectation.new(match_data, false) expectation = Spectator::Expectations::Expectation.new(match_data, false)
expectation.satisfied?.should be_false expectation.satisfied?.should be_false
end end
context "when negated" do context "when negated" do
it "is true" do it "is true" do
value1 = 42 match_data = new_matcher(42).match(new_partial(777))
value2 = 777 match_data.matched?.should be_false # Sanity check.
partial = new_partial(value1)
matcher = Spectator::Matchers::EqualityMatcher.new(value2.to_s, value2)
match_data = matcher.match(partial)
matcher.match(partial).matched?.should be_false # Sanity check.
expectation = Spectator::Expectations::Expectation.new(match_data, true) expectation = Spectator::Expectations::Expectation.new(match_data, true)
expectation.satisfied?.should be_true expectation.satisfied?.should be_true
end end
@ -57,9 +45,7 @@ describe Spectator::Expectations::Expectation do
context "with a successful match" do context "with a successful match" do
it "equals the matcher's #message" do it "equals the matcher's #message" do
value = 42 value = 42
partial = new_partial(value) match_data = new_matcher(value).match(new_partial(value))
matcher = Spectator::Matchers::EqualityMatcher.new(value.to_s, value)
match_data = matcher.match(partial)
match_data.matched?.should be_true # Sanity check. match_data.matched?.should be_true # Sanity check.
expectation = Spectator::Expectations::Expectation.new(match_data, false) expectation = Spectator::Expectations::Expectation.new(match_data, false)
expectation.actual_message.should eq(match_data.message) expectation.actual_message.should eq(match_data.message)
@ -68,10 +54,8 @@ describe Spectator::Expectations::Expectation do
context "when negated" do context "when negated" do
it "equals the matcher's #negated_message" do it "equals the matcher's #negated_message" do
value = 42 value = 42
partial = new_partial(value) match_data = new_matcher(value).match(new_partial(value))
matcher = Spectator::Matchers::EqualityMatcher.new(value.to_s, value) match_data.matched?.should be_true # Sanity check.
match_data = matcher.match(partial)
matcher.match(partial).matched?.should be_true # Sanity check.
expectation = Spectator::Expectations::Expectation.new(match_data, true) expectation = Spectator::Expectations::Expectation.new(match_data, true)
expectation.actual_message.should eq(match_data.negated_message) expectation.actual_message.should eq(match_data.negated_message)
end end
@ -80,24 +64,16 @@ describe Spectator::Expectations::Expectation do
context "with an unsuccessful match" do context "with an unsuccessful match" do
it "equals the matcher's #negated_message" do it "equals the matcher's #negated_message" do
value1 = 42 match_data = new_matcher(42).match(new_partial(777))
value2 = 777 match_data.matched?.should be_false # Sanity check.
partial = new_partial(value1)
matcher = Spectator::Matchers::EqualityMatcher.new(value2.to_s, value2)
match_data = matcher.match(partial)
matcher.match(partial).matched?.should be_false # Sanity check.
expectation = Spectator::Expectations::Expectation.new(match_data, false) expectation = Spectator::Expectations::Expectation.new(match_data, false)
expectation.actual_message.should eq(match_data.negated_message) expectation.actual_message.should eq(match_data.negated_message)
end end
context "when negated" do context "when negated" do
it "equals the matcher's #message" do it "equals the matcher's #message" do
value1 = 42 match_data = new_matcher(42).match(new_partial(777))
value2 = 777 match_data.matched?.should be_false # Sanity check.
partial = new_partial(value1)
matcher = Spectator::Matchers::EqualityMatcher.new(value2.to_s, value2)
match_data = matcher.match(partial)
matcher.match(partial).matched?.should be_false # Sanity check.
expectation = Spectator::Expectations::Expectation.new(match_data, true) expectation = Spectator::Expectations::Expectation.new(match_data, true)
expectation.actual_message.should eq(match_data.message) expectation.actual_message.should eq(match_data.message)
end end
@ -109,10 +85,8 @@ describe Spectator::Expectations::Expectation do
context "with a successful match" do context "with a successful match" do
it "equals the matcher's #message" do it "equals the matcher's #message" do
value = 42 value = 42
partial = new_partial(value) match_data = new_matcher(value).match(new_partial(value))
matcher = Spectator::Matchers::EqualityMatcher.new(value.to_s, value) match_data.matched?.should be_true # Sanity check.
match_data = matcher.match(partial)
matcher.match(partial).matched?.should be_true # Sanity check.
expectation = Spectator::Expectations::Expectation.new(match_data, false) expectation = Spectator::Expectations::Expectation.new(match_data, false)
expectation.expected_message.should eq(match_data.message) expectation.expected_message.should eq(match_data.message)
end end
@ -120,10 +94,8 @@ describe Spectator::Expectations::Expectation do
context "when negated" do context "when negated" do
it "equals the matcher's #negated_message" do it "equals the matcher's #negated_message" do
value = 42 value = 42
partial = new_partial(value) match_data = new_matcher(value).match(new_partial(value))
matcher = Spectator::Matchers::EqualityMatcher.new(value.to_s, value) match_data.matched?.should be_true # Sanity check.
match_data = matcher.match(partial)
matcher.match(partial).matched?.should be_true # Sanity check.
expectation = Spectator::Expectations::Expectation.new(match_data, true) expectation = Spectator::Expectations::Expectation.new(match_data, true)
expectation.expected_message.should eq(match_data.negated_message) expectation.expected_message.should eq(match_data.negated_message)
end end
@ -132,24 +104,16 @@ describe Spectator::Expectations::Expectation do
context "with an unsuccessful match" do context "with an unsuccessful match" do
it "equals the matcher's #message" do it "equals the matcher's #message" do
value1 = 42 match_data = new_matcher(42).match(new_partial(777))
value2 = 777 match_data.matched?.should be_false # Sanity check.
partial = new_partial(value1)
matcher = Spectator::Matchers::EqualityMatcher.new(value2.to_s, value2)
match_data = matcher.match(partial)
matcher.match(partial).matched?.should be_false # Sanity check.
expectation = Spectator::Expectations::Expectation.new(match_data, false) expectation = Spectator::Expectations::Expectation.new(match_data, false)
expectation.expected_message.should eq(match_data.message) expectation.expected_message.should eq(match_data.message)
end end
context "when negated" do context "when negated" do
it "equals the matcher's #negated_message" do it "equals the matcher's #negated_message" do
value1 = 42 match_data = new_matcher(42).match(new_partial(777))
value2 = 777 match_data.matched?.should be_false # Sanity check.
partial = new_partial(value1)
matcher = Spectator::Matchers::EqualityMatcher.new(value2.to_s, value2)
match_data = matcher.match(partial)
matcher.match(partial).matched?.should be_false # Sanity check.
expectation = Spectator::Expectations::Expectation.new(match_data, true) expectation = Spectator::Expectations::Expectation.new(match_data, true)
expectation.expected_message.should eq(match_data.negated_message) expectation.expected_message.should eq(match_data.negated_message)
end end

View file

@ -8,17 +8,17 @@ def new_partial(actual : T = 123) forall T
Spectator::Expectations::ValueExpectationPartial.new(actual, __FILE__, __LINE__) Spectator::Expectations::ValueExpectationPartial.new(actual, __FILE__, __LINE__)
end end
def new_matcher(label : String, expected : T) forall T def new_matcher(expected : T, label : String) forall T
Spectator::Matchers::EqualityMatcher.new(label, expected) Spectator::Matchers::EqualityMatcher.new(expected, label)
end end
def new_matcher(expected : T = 123) forall T def new_matcher(expected : T = 123) forall T
new_matcher(expected.to_s, expected) Spectator::Matchers::EqualityMatcher.new(expected)
end end
def new_expectation(expected : ExpectedType = 123, actual : ActualType = 123) forall ExpectedType, ActualType def new_expectation(expected : ExpectedType = 123, actual : ActualType = 123) forall ExpectedType, ActualType
partial = new_partial(actual, "foo") partial = new_partial(actual, "foo")
matcher = new_matcher("bar", expected) matcher = new_matcher(expected, "bar")
match_data = matcher.match(partial) match_data = matcher.match(partial)
Spectator::Expectations::Expectation.new(match_data, false) Spectator::Expectations::Expectation.new(match_data, false)
end end

View file

@ -102,7 +102,7 @@ describe Spectator::Matchers::CaseMatcher do
value = 42 value = 42
label = "everything" label = "everything"
partial = new_partial(value) partial = new_partial(value)
matcher = Spectator::Matchers::CaseMatcher.new(label, value) matcher = Spectator::Matchers::CaseMatcher.new(value, label)
matcher.message(partial).should contain(label) matcher.message(partial).should contain(label)
end end
@ -137,7 +137,7 @@ describe Spectator::Matchers::CaseMatcher do
value = 42 value = 42
label = "everything" label = "everything"
partial = new_partial(value) partial = new_partial(value)
matcher = Spectator::Matchers::CaseMatcher.new(label, value) matcher = Spectator::Matchers::CaseMatcher.new(value, label)
matcher.negated_message(partial).should contain(label) matcher.negated_message(partial).should contain(label)
end end

View file

@ -280,7 +280,7 @@ describe Spectator::Matchers::ContainMatcher do
search = "baz" search = "baz"
label = "everything" label = "everything"
partial = new_partial(value) partial = new_partial(value)
matcher = Spectator::Matchers::ContainMatcher.new(label, {search}) matcher = Spectator::Matchers::ContainMatcher.new({search}, label)
matcher.message(partial).should contain(label) matcher.message(partial).should contain(label)
end end
@ -310,7 +310,7 @@ describe Spectator::Matchers::ContainMatcher do
search = "baz" search = "baz"
label = "everything" label = "everything"
partial = new_partial(value) partial = new_partial(value)
matcher = Spectator::Matchers::ContainMatcher.new(label, {search}) matcher = Spectator::Matchers::ContainMatcher.new({search}, label)
matcher.negated_message(partial).should contain(label) matcher.negated_message(partial).should contain(label)
end end

View file

@ -225,7 +225,7 @@ describe Spectator::Matchers::EndWithMatcher do
last = "baz" last = "baz"
label = "everything" label = "everything"
partial = new_partial(value) partial = new_partial(value)
matcher = Spectator::Matchers::EndWithMatcher.new(label, last) matcher = Spectator::Matchers::EndWithMatcher.new(last, label)
matcher.message(partial).should contain(label) matcher.message(partial).should contain(label)
end end
@ -281,7 +281,7 @@ describe Spectator::Matchers::EndWithMatcher do
last = "baz" last = "baz"
label = "everything" label = "everything"
partial = new_partial(value) partial = new_partial(value)
matcher = Spectator::Matchers::EndWithMatcher.new(label, last) matcher = Spectator::Matchers::EndWithMatcher.new(last, label)
matcher.negated_message(partial).should contain(label) matcher.negated_message(partial).should contain(label)
end end

View file

@ -91,7 +91,7 @@ describe Spectator::Matchers::EqualityMatcher do
value = 42 value = 42
label = "everything" label = "everything"
partial = new_partial(value) partial = new_partial(value)
matcher = Spectator::Matchers::EqualityMatcher.new(label, value) matcher = Spectator::Matchers::EqualityMatcher.new(value, label)
match_data = matcher.match(partial) match_data = matcher.match(partial)
match_data.message.should contain(label) match_data.message.should contain(label)
end end
@ -130,7 +130,7 @@ describe Spectator::Matchers::EqualityMatcher do
value = 42 value = 42
label = "everything" label = "everything"
partial = new_partial(value) partial = new_partial(value)
matcher = Spectator::Matchers::EqualityMatcher.new(label, value) matcher = Spectator::Matchers::EqualityMatcher.new(value, label)
match_data = matcher.match(partial) match_data = matcher.match(partial)
match_data.negated_message.should contain(label) match_data.negated_message.should contain(label)
end end

View file

@ -60,7 +60,7 @@ describe Spectator::Matchers::GreaterThanEqualMatcher do
value = 42 value = 42
label = "everything" label = "everything"
partial = new_partial(value) partial = new_partial(value)
matcher = Spectator::Matchers::GreaterThanEqualMatcher.new(label, value) matcher = Spectator::Matchers::GreaterThanEqualMatcher.new(value, label)
matcher.message(partial).should contain(label) matcher.message(partial).should contain(label)
end end
@ -95,7 +95,7 @@ describe Spectator::Matchers::GreaterThanEqualMatcher do
value = 42 value = 42
label = "everything" label = "everything"
partial = new_partial(value) partial = new_partial(value)
matcher = Spectator::Matchers::GreaterThanEqualMatcher.new(label, value) matcher = Spectator::Matchers::GreaterThanEqualMatcher.new(value, label)
matcher.negated_message(partial).should contain(label) matcher.negated_message(partial).should contain(label)
end end

View file

@ -60,7 +60,7 @@ describe Spectator::Matchers::GreaterThanMatcher do
value = 42 value = 42
label = "everything" label = "everything"
partial = new_partial(value) partial = new_partial(value)
matcher = Spectator::Matchers::GreaterThanMatcher.new(label, value) matcher = Spectator::Matchers::GreaterThanMatcher.new(value, label)
matcher.message(partial).should contain(label) matcher.message(partial).should contain(label)
end end
@ -95,7 +95,7 @@ describe Spectator::Matchers::GreaterThanMatcher do
value = 42 value = 42
label = "everything" label = "everything"
partial = new_partial(value) partial = new_partial(value)
matcher = Spectator::Matchers::GreaterThanMatcher.new(label, value) matcher = Spectator::Matchers::GreaterThanMatcher.new(value, label)
matcher.negated_message(partial).should contain(label) matcher.negated_message(partial).should contain(label)
end end

View file

@ -235,7 +235,7 @@ describe Spectator::Matchers::AttributesMatcher do
attributes = {size: 6} attributes = {size: 6}
label = "everything" label = "everything"
partial = new_partial(value) partial = new_partial(value)
matcher = Spectator::Matchers::AttributesMatcher.new(label, attributes) matcher = Spectator::Matchers::AttributesMatcher.new(attributes, label)
matcher.message(partial).should contain(label) matcher.message(partial).should contain(label)
end end
@ -265,7 +265,7 @@ describe Spectator::Matchers::AttributesMatcher do
attributes = {size: 6} attributes = {size: 6}
label = "everything" label = "everything"
partial = new_partial(value) partial = new_partial(value)
matcher = Spectator::Matchers::AttributesMatcher.new(label, attributes) matcher = Spectator::Matchers::AttributesMatcher.new(attributes, label)
matcher.negated_message(partial).should contain(label) matcher.negated_message(partial).should contain(label)
end end

View file

@ -62,7 +62,7 @@ describe Spectator::Matchers::HaveKeyMatcher do
key = :foo key = :foo
label = "blah" label = "blah"
partial = new_partial(tuple) partial = new_partial(tuple)
matcher = Spectator::Matchers::HaveKeyMatcher.new(label, key) matcher = Spectator::Matchers::HaveKeyMatcher.new(key, label)
matcher.message(partial).should contain(label) matcher.message(partial).should contain(label)
end end
@ -92,7 +92,7 @@ describe Spectator::Matchers::HaveKeyMatcher do
key = :foo key = :foo
label = "blah" label = "blah"
partial = new_partial(tuple) partial = new_partial(tuple)
matcher = Spectator::Matchers::HaveKeyMatcher.new(label, key) matcher = Spectator::Matchers::HaveKeyMatcher.new(key, label)
matcher.negated_message(partial).should contain(label) matcher.negated_message(partial).should contain(label)
end end

View file

@ -479,7 +479,7 @@ describe Spectator::Matchers::HaveMatcher do
search = "baz" search = "baz"
label = "everything" label = "everything"
partial = new_partial(value) partial = new_partial(value)
matcher = Spectator::Matchers::HaveMatcher.new(label, {search}) matcher = Spectator::Matchers::HaveMatcher.new({search}, label)
matcher.message(partial).should contain(label) matcher.message(partial).should contain(label)
end end
@ -509,7 +509,7 @@ describe Spectator::Matchers::HaveMatcher do
search = "baz" search = "baz"
label = "everything" label = "everything"
partial = new_partial(value) partial = new_partial(value)
matcher = Spectator::Matchers::HaveMatcher.new(label, {search}) matcher = Spectator::Matchers::HaveMatcher.new({search}, label)
matcher.negated_message(partial).should contain(label) matcher.negated_message(partial).should contain(label)
end end

View file

@ -38,7 +38,7 @@ describe Spectator::Matchers::HaveValueMatcher do
value = "bar" value = "bar"
label = "blah" label = "blah"
partial = new_partial(hash) partial = new_partial(hash)
matcher = Spectator::Matchers::HaveValueMatcher.new(label, value) matcher = Spectator::Matchers::HaveValueMatcher.new(value, label)
matcher.message(partial).should contain(label) matcher.message(partial).should contain(label)
end end
@ -68,7 +68,7 @@ describe Spectator::Matchers::HaveValueMatcher do
value = "bar" value = "bar"
label = "blah" label = "blah"
partial = new_partial(hash) partial = new_partial(hash)
matcher = Spectator::Matchers::HaveValueMatcher.new(label, value) matcher = Spectator::Matchers::HaveValueMatcher.new(value, label)
matcher.negated_message(partial).should contain(label) matcher.negated_message(partial).should contain(label)
end end

View file

@ -82,7 +82,7 @@ describe Spectator::Matchers::InequalityMatcher do
value = 42 value = 42
label = "everything" label = "everything"
partial = new_partial(value) partial = new_partial(value)
matcher = Spectator::Matchers::InequalityMatcher.new(label, value) matcher = Spectator::Matchers::InequalityMatcher.new(value, label)
matcher.message(partial).should contain(label) matcher.message(partial).should contain(label)
end end
@ -117,7 +117,7 @@ describe Spectator::Matchers::InequalityMatcher do
value = 42 value = 42
label = "everything" label = "everything"
partial = new_partial(value) partial = new_partial(value)
matcher = Spectator::Matchers::InequalityMatcher.new(label, value) matcher = Spectator::Matchers::InequalityMatcher.new(value, label)
matcher.negated_message(partial).should contain(label) matcher.negated_message(partial).should contain(label)
end end

View file

@ -60,7 +60,7 @@ describe Spectator::Matchers::LessThanEqualMatcher do
value = 42 value = 42
label = "everything" label = "everything"
partial = new_partial(value) partial = new_partial(value)
matcher = Spectator::Matchers::LessThanEqualMatcher.new(label, value) matcher = Spectator::Matchers::LessThanEqualMatcher.new(value, label)
matcher.message(partial).should contain(label) matcher.message(partial).should contain(label)
end end
@ -95,7 +95,7 @@ describe Spectator::Matchers::LessThanEqualMatcher do
value = 42 value = 42
label = "everything" label = "everything"
partial = new_partial(value) partial = new_partial(value)
matcher = Spectator::Matchers::LessThanEqualMatcher.new(label, value) matcher = Spectator::Matchers::LessThanEqualMatcher.new(value, label)
matcher.negated_message(partial).should contain(label) matcher.negated_message(partial).should contain(label)
end end

View file

@ -60,7 +60,7 @@ describe Spectator::Matchers::LessThanMatcher do
value = 42 value = 42
label = "everything" label = "everything"
partial = new_partial(value) partial = new_partial(value)
matcher = Spectator::Matchers::LessThanMatcher.new(label, value) matcher = Spectator::Matchers::LessThanMatcher.new(value, label)
matcher.message(partial).should contain(label) matcher.message(partial).should contain(label)
end end
@ -95,7 +95,7 @@ describe Spectator::Matchers::LessThanMatcher do
value = 42 value = 42
label = "everything" label = "everything"
partial = new_partial(value) partial = new_partial(value)
matcher = Spectator::Matchers::LessThanMatcher.new(label, value) matcher = Spectator::Matchers::LessThanMatcher.new(value, label)
matcher.negated_message(partial).should contain(label) matcher.negated_message(partial).should contain(label)
end end

View file

@ -150,7 +150,7 @@ describe Spectator::Matchers::RangeMatcher do
value = 5 value = 5
label = "everything" label = "everything"
partial = new_partial(value) partial = new_partial(value)
matcher = Spectator::Matchers::RangeMatcher.new(label, range) matcher = Spectator::Matchers::RangeMatcher.new(range, label)
matcher.message(partial).should contain(label) matcher.message(partial).should contain(label)
end end
@ -180,7 +180,7 @@ describe Spectator::Matchers::RangeMatcher do
value = 5 value = 5
label = "everything" label = "everything"
partial = new_partial(value) partial = new_partial(value)
matcher = Spectator::Matchers::RangeMatcher.new(label, range) matcher = Spectator::Matchers::RangeMatcher.new(range, label)
matcher.negated_message(partial).should contain(label) matcher.negated_message(partial).should contain(label)
end end
@ -252,7 +252,7 @@ describe Spectator::Matchers::RangeMatcher do
value = 3 value = 3
label = "foobar" label = "foobar"
partial = new_partial(value) partial = new_partial(value)
matcher = Spectator::Matchers::RangeMatcher.new(label, diff).of(center) matcher = Spectator::Matchers::RangeMatcher.new(diff, label).of(center)
matcher.message(partial).should contain(label) matcher.message(partial).should contain(label)
end end
@ -282,7 +282,7 @@ describe Spectator::Matchers::RangeMatcher do
value = 3 value = 3
label = "foobar" label = "foobar"
partial = new_partial(value) partial = new_partial(value)
matcher = Spectator::Matchers::RangeMatcher.new(label, diff).of(center) matcher = Spectator::Matchers::RangeMatcher.new(diff, label).of(center)
matcher.negated_message(partial).should contain(label) matcher.negated_message(partial).should contain(label)
end end
@ -380,7 +380,7 @@ describe Spectator::Matchers::RangeMatcher do
value = 5 value = 5
label = "foobar" label = "foobar"
partial = new_partial(value) partial = new_partial(value)
matcher = Spectator::Matchers::RangeMatcher.new(label, range).inclusive matcher = Spectator::Matchers::RangeMatcher.new(range, label).inclusive
matcher.message(partial).should contain(label) matcher.message(partial).should contain(label)
end end
end end
@ -407,7 +407,7 @@ describe Spectator::Matchers::RangeMatcher do
value = 5 value = 5
label = "foobar" label = "foobar"
partial = new_partial(value) partial = new_partial(value)
matcher = Spectator::Matchers::RangeMatcher.new(label, range).inclusive matcher = Spectator::Matchers::RangeMatcher.new(range, label).inclusive
matcher.negated_message(partial).should contain(label) matcher.negated_message(partial).should contain(label)
end end
end end
@ -478,7 +478,7 @@ describe Spectator::Matchers::RangeMatcher do
value = 5 value = 5
label = "foobar" label = "foobar"
partial = new_partial(value) partial = new_partial(value)
matcher = Spectator::Matchers::RangeMatcher.new(label, range).inclusive matcher = Spectator::Matchers::RangeMatcher.new(range, label).inclusive
matcher.message(partial).should contain(label) matcher.message(partial).should contain(label)
end end
end end
@ -497,7 +497,7 @@ describe Spectator::Matchers::RangeMatcher do
value = 5 value = 5
label = "foobar" label = "foobar"
partial = new_partial(value) partial = new_partial(value)
matcher = Spectator::Matchers::RangeMatcher.new(label, range).inclusive matcher = Spectator::Matchers::RangeMatcher.new(range, label).inclusive
matcher.negated_message(partial).should contain(label) matcher.negated_message(partial).should contain(label)
end end
end end
@ -578,7 +578,7 @@ describe Spectator::Matchers::RangeMatcher do
value = 5 value = 5
label = "foobar" label = "foobar"
partial = new_partial(value) partial = new_partial(value)
matcher = Spectator::Matchers::RangeMatcher.new(label, range).exclusive matcher = Spectator::Matchers::RangeMatcher.new(range, label).exclusive
matcher.message(partial).should contain(label) matcher.message(partial).should contain(label)
end end
end end
@ -605,7 +605,7 @@ describe Spectator::Matchers::RangeMatcher do
value = 5 value = 5
label = "foobar" label = "foobar"
partial = new_partial(value) partial = new_partial(value)
matcher = Spectator::Matchers::RangeMatcher.new(label, range).exclusive matcher = Spectator::Matchers::RangeMatcher.new(range, label).exclusive
matcher.negated_message(partial).should contain(label) matcher.negated_message(partial).should contain(label)
end end
end end
@ -676,7 +676,7 @@ describe Spectator::Matchers::RangeMatcher do
value = 5 value = 5
label = "foobar" label = "foobar"
partial = new_partial(value) partial = new_partial(value)
matcher = Spectator::Matchers::RangeMatcher.new(label, range).exclusive matcher = Spectator::Matchers::RangeMatcher.new(range, label).exclusive
matcher.message(partial).should contain(label) matcher.message(partial).should contain(label)
end end
end end
@ -695,7 +695,7 @@ describe Spectator::Matchers::RangeMatcher do
value = 5 value = 5
label = "foobar" label = "foobar"
partial = new_partial(value) partial = new_partial(value)
matcher = Spectator::Matchers::RangeMatcher.new(label, range).exclusive matcher = Spectator::Matchers::RangeMatcher.new(range, label).exclusive
matcher.negated_message(partial).should contain(label) matcher.negated_message(partial).should contain(label)
end end
end end

View file

@ -54,7 +54,7 @@ describe Spectator::Matchers::RegexMatcher do
label = "different" label = "different"
pattern = /foo/ pattern = /foo/
partial = new_partial(value) partial = new_partial(value)
matcher = Spectator::Matchers::RegexMatcher.new(label, pattern) matcher = Spectator::Matchers::RegexMatcher.new(pattern, label)
matcher.message(partial).should contain(label) matcher.message(partial).should contain(label)
end end
@ -92,7 +92,7 @@ describe Spectator::Matchers::RegexMatcher do
label = "different" label = "different"
pattern = /foo/ pattern = /foo/
partial = new_partial(value) partial = new_partial(value)
matcher = Spectator::Matchers::RegexMatcher.new(label, pattern) matcher = Spectator::Matchers::RegexMatcher.new(pattern, label)
matcher.negated_message(partial).should contain(label) matcher.negated_message(partial).should contain(label)
end end

View file

@ -225,7 +225,7 @@ describe Spectator::Matchers::StartWithMatcher do
start = "baz" start = "baz"
label = "everything" label = "everything"
partial = new_partial(value) partial = new_partial(value)
matcher = Spectator::Matchers::StartWithMatcher.new(label, start) matcher = Spectator::Matchers::StartWithMatcher.new(start, label)
matcher.message(partial).should contain(label) matcher.message(partial).should contain(label)
end end
@ -281,7 +281,7 @@ describe Spectator::Matchers::StartWithMatcher do
start = "baz" start = "baz"
label = "everything" label = "everything"
partial = new_partial(value) partial = new_partial(value)
matcher = Spectator::Matchers::StartWithMatcher.new(label, start) matcher = Spectator::Matchers::StartWithMatcher.new(start, label)
matcher.negated_message(partial).should contain(label) matcher.negated_message(partial).should contain(label)
end end

View file

@ -47,19 +47,19 @@ module Spectator::Matchers
lower = center - diff lower = center - diff
upper = center + diff upper = center + diff
range = Range.new(lower, upper) range = Range.new(lower, upper)
RangeMatcher.new("#{center} +/- #{label}", range) RangeMatcher.new(range, "#{center} +/- #{label}")
end end
# Returns a new matcher, with the same bounds, but uses an inclusive range. # Returns a new matcher, with the same bounds, but uses an inclusive range.
def inclusive def inclusive
range = Range.new(@expected.begin, @expected.end, exclusive: false) range = Range.new(@expected.begin, @expected.end, exclusive: false)
RangeMatcher.new(label + " (inclusive)", range) RangeMatcher.new(range, label + " (inclusive)")
end end
# Returns a new matcher, with the same bounds, but uses an exclusive range. # Returns a new matcher, with the same bounds, but uses an exclusive range.
def exclusive def exclusive
range = Range.new(@expected.begin, @expected.end, exclusive: true) range = Range.new(@expected.begin, @expected.end, exclusive: true)
RangeMatcher.new(label + " (exclusive)", range) RangeMatcher.new(range, label + " (exclusive)")
end end
end end
end end

View file

@ -17,14 +17,14 @@ module Spectator::Matchers
# Creates the value matcher. # Creates the value matcher.
# The label should be a string representation of the expectation. # The label should be a string representation of the expectation.
# The expected value is stored for later use. # The expected value is stored for later use.
def initialize(@label : String, @expected : ExpectedType) def initialize(@expected : ExpectedType, @label : String)
end end
# Creates the value matcher. # Creates the value matcher.
# The label is generated by calling `#to_s` on the expected value. # The label is generated by calling `#to_s` on the expected value.
# The expected value is stored for later use. # The expected value is stored for later use.
def initialize(expected : ExpectedType) def initialize(expected : ExpectedType)
initialize(expected.to_s, expected) initialize(expected, expected.to_s)
end end
end end
end end