mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
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:
parent
f3e50c6432
commit
5ba03a90ff
20 changed files with 74 additions and 110 deletions
|
@ -5,10 +5,8 @@ describe Spectator::Expectations::Expectation do
|
|||
context "with a successful match" do
|
||||
it "is true" do
|
||||
value = 42
|
||||
partial = new_partial(value)
|
||||
matcher = Spectator::Matchers::EqualityMatcher.new(value.to_s, value)
|
||||
match_data = matcher.match(partial)
|
||||
matcher.match(partial).matched?.should be_true # Sanity check.
|
||||
match_data = new_matcher(value).match(new_partial(value))
|
||||
match_data.matched?.should be_true # Sanity check.
|
||||
expectation = Spectator::Expectations::Expectation.new(match_data, false)
|
||||
expectation.satisfied?.should be_true
|
||||
end
|
||||
|
@ -16,10 +14,8 @@ describe Spectator::Expectations::Expectation do
|
|||
context "when negated" do
|
||||
it "is false" do
|
||||
value = 42
|
||||
partial = new_partial(value)
|
||||
matcher = Spectator::Matchers::EqualityMatcher.new(value.to_s, value)
|
||||
match_data = matcher.match(partial)
|
||||
matcher.match(partial).matched?.should be_true # Sanity check.
|
||||
match_data = new_matcher(value).match(new_partial(value))
|
||||
match_data.matched?.should be_true # Sanity check.
|
||||
expectation = Spectator::Expectations::Expectation.new(match_data, true)
|
||||
expectation.satisfied?.should be_false
|
||||
end
|
||||
|
@ -28,24 +24,16 @@ describe Spectator::Expectations::Expectation do
|
|||
|
||||
context "with an unsuccessful match" do
|
||||
it "is false" do
|
||||
value1 = 42
|
||||
value2 = 777
|
||||
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.
|
||||
match_data = new_matcher(42).match(new_partial(777))
|
||||
match_data.matched?.should be_false # Sanity check.
|
||||
expectation = Spectator::Expectations::Expectation.new(match_data, false)
|
||||
expectation.satisfied?.should be_false
|
||||
end
|
||||
|
||||
context "when negated" do
|
||||
it "is true" do
|
||||
value1 = 42
|
||||
value2 = 777
|
||||
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.
|
||||
match_data = new_matcher(42).match(new_partial(777))
|
||||
match_data.matched?.should be_false # Sanity check.
|
||||
expectation = Spectator::Expectations::Expectation.new(match_data, true)
|
||||
expectation.satisfied?.should be_true
|
||||
end
|
||||
|
@ -57,9 +45,7 @@ describe Spectator::Expectations::Expectation do
|
|||
context "with a successful match" do
|
||||
it "equals the matcher's #message" do
|
||||
value = 42
|
||||
partial = new_partial(value)
|
||||
matcher = Spectator::Matchers::EqualityMatcher.new(value.to_s, value)
|
||||
match_data = matcher.match(partial)
|
||||
match_data = new_matcher(value).match(new_partial(value))
|
||||
match_data.matched?.should be_true # Sanity check.
|
||||
expectation = Spectator::Expectations::Expectation.new(match_data, false)
|
||||
expectation.actual_message.should eq(match_data.message)
|
||||
|
@ -68,10 +54,8 @@ describe Spectator::Expectations::Expectation do
|
|||
context "when negated" do
|
||||
it "equals the matcher's #negated_message" do
|
||||
value = 42
|
||||
partial = new_partial(value)
|
||||
matcher = Spectator::Matchers::EqualityMatcher.new(value.to_s, value)
|
||||
match_data = matcher.match(partial)
|
||||
matcher.match(partial).matched?.should be_true # Sanity check.
|
||||
match_data = new_matcher(value).match(new_partial(value))
|
||||
match_data.matched?.should be_true # Sanity check.
|
||||
expectation = Spectator::Expectations::Expectation.new(match_data, true)
|
||||
expectation.actual_message.should eq(match_data.negated_message)
|
||||
end
|
||||
|
@ -80,24 +64,16 @@ describe Spectator::Expectations::Expectation do
|
|||
|
||||
context "with an unsuccessful match" do
|
||||
it "equals the matcher's #negated_message" do
|
||||
value1 = 42
|
||||
value2 = 777
|
||||
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.
|
||||
match_data = new_matcher(42).match(new_partial(777))
|
||||
match_data.matched?.should be_false # Sanity check.
|
||||
expectation = Spectator::Expectations::Expectation.new(match_data, false)
|
||||
expectation.actual_message.should eq(match_data.negated_message)
|
||||
end
|
||||
|
||||
context "when negated" do
|
||||
it "equals the matcher's #message" do
|
||||
value1 = 42
|
||||
value2 = 777
|
||||
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.
|
||||
match_data = new_matcher(42).match(new_partial(777))
|
||||
match_data.matched?.should be_false # Sanity check.
|
||||
expectation = Spectator::Expectations::Expectation.new(match_data, true)
|
||||
expectation.actual_message.should eq(match_data.message)
|
||||
end
|
||||
|
@ -109,10 +85,8 @@ describe Spectator::Expectations::Expectation do
|
|||
context "with a successful match" do
|
||||
it "equals the matcher's #message" do
|
||||
value = 42
|
||||
partial = new_partial(value)
|
||||
matcher = Spectator::Matchers::EqualityMatcher.new(value.to_s, value)
|
||||
match_data = matcher.match(partial)
|
||||
matcher.match(partial).matched?.should be_true # Sanity check.
|
||||
match_data = new_matcher(value).match(new_partial(value))
|
||||
match_data.matched?.should be_true # Sanity check.
|
||||
expectation = Spectator::Expectations::Expectation.new(match_data, false)
|
||||
expectation.expected_message.should eq(match_data.message)
|
||||
end
|
||||
|
@ -120,10 +94,8 @@ describe Spectator::Expectations::Expectation do
|
|||
context "when negated" do
|
||||
it "equals the matcher's #negated_message" do
|
||||
value = 42
|
||||
partial = new_partial(value)
|
||||
matcher = Spectator::Matchers::EqualityMatcher.new(value.to_s, value)
|
||||
match_data = matcher.match(partial)
|
||||
matcher.match(partial).matched?.should be_true # Sanity check.
|
||||
match_data = new_matcher(value).match(new_partial(value))
|
||||
match_data.matched?.should be_true # Sanity check.
|
||||
expectation = Spectator::Expectations::Expectation.new(match_data, true)
|
||||
expectation.expected_message.should eq(match_data.negated_message)
|
||||
end
|
||||
|
@ -132,24 +104,16 @@ describe Spectator::Expectations::Expectation do
|
|||
|
||||
context "with an unsuccessful match" do
|
||||
it "equals the matcher's #message" do
|
||||
value1 = 42
|
||||
value2 = 777
|
||||
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.
|
||||
match_data = new_matcher(42).match(new_partial(777))
|
||||
match_data.matched?.should be_false # Sanity check.
|
||||
expectation = Spectator::Expectations::Expectation.new(match_data, false)
|
||||
expectation.expected_message.should eq(match_data.message)
|
||||
end
|
||||
|
||||
context "when negated" do
|
||||
it "equals the matcher's #negated_message" do
|
||||
value1 = 42
|
||||
value2 = 777
|
||||
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.
|
||||
match_data = new_matcher(42).match(new_partial(777))
|
||||
match_data.matched?.should be_false # Sanity check.
|
||||
expectation = Spectator::Expectations::Expectation.new(match_data, true)
|
||||
expectation.expected_message.should eq(match_data.negated_message)
|
||||
end
|
||||
|
|
|
@ -8,17 +8,17 @@ def new_partial(actual : T = 123) forall T
|
|||
Spectator::Expectations::ValueExpectationPartial.new(actual, __FILE__, __LINE__)
|
||||
end
|
||||
|
||||
def new_matcher(label : String, expected : T) forall T
|
||||
Spectator::Matchers::EqualityMatcher.new(label, expected)
|
||||
def new_matcher(expected : T, label : String) forall T
|
||||
Spectator::Matchers::EqualityMatcher.new(expected, label)
|
||||
end
|
||||
|
||||
def new_matcher(expected : T = 123) forall T
|
||||
new_matcher(expected.to_s, expected)
|
||||
Spectator::Matchers::EqualityMatcher.new(expected)
|
||||
end
|
||||
|
||||
def new_expectation(expected : ExpectedType = 123, actual : ActualType = 123) forall ExpectedType, ActualType
|
||||
partial = new_partial(actual, "foo")
|
||||
matcher = new_matcher("bar", expected)
|
||||
matcher = new_matcher(expected, "bar")
|
||||
match_data = matcher.match(partial)
|
||||
Spectator::Expectations::Expectation.new(match_data, false)
|
||||
end
|
||||
|
|
|
@ -102,7 +102,7 @@ describe Spectator::Matchers::CaseMatcher do
|
|||
value = 42
|
||||
label = "everything"
|
||||
partial = new_partial(value)
|
||||
matcher = Spectator::Matchers::CaseMatcher.new(label, value)
|
||||
matcher = Spectator::Matchers::CaseMatcher.new(value, label)
|
||||
matcher.message(partial).should contain(label)
|
||||
end
|
||||
|
||||
|
@ -137,7 +137,7 @@ describe Spectator::Matchers::CaseMatcher do
|
|||
value = 42
|
||||
label = "everything"
|
||||
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)
|
||||
end
|
||||
|
||||
|
|
|
@ -280,7 +280,7 @@ describe Spectator::Matchers::ContainMatcher do
|
|||
search = "baz"
|
||||
label = "everything"
|
||||
partial = new_partial(value)
|
||||
matcher = Spectator::Matchers::ContainMatcher.new(label, {search})
|
||||
matcher = Spectator::Matchers::ContainMatcher.new({search}, label)
|
||||
matcher.message(partial).should contain(label)
|
||||
end
|
||||
|
||||
|
@ -310,7 +310,7 @@ describe Spectator::Matchers::ContainMatcher do
|
|||
search = "baz"
|
||||
label = "everything"
|
||||
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)
|
||||
end
|
||||
|
||||
|
|
|
@ -225,7 +225,7 @@ describe Spectator::Matchers::EndWithMatcher do
|
|||
last = "baz"
|
||||
label = "everything"
|
||||
partial = new_partial(value)
|
||||
matcher = Spectator::Matchers::EndWithMatcher.new(label, last)
|
||||
matcher = Spectator::Matchers::EndWithMatcher.new(last, label)
|
||||
matcher.message(partial).should contain(label)
|
||||
end
|
||||
|
||||
|
@ -281,7 +281,7 @@ describe Spectator::Matchers::EndWithMatcher do
|
|||
last = "baz"
|
||||
label = "everything"
|
||||
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)
|
||||
end
|
||||
|
||||
|
|
|
@ -91,7 +91,7 @@ describe Spectator::Matchers::EqualityMatcher do
|
|||
value = 42
|
||||
label = "everything"
|
||||
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.message.should contain(label)
|
||||
end
|
||||
|
@ -130,7 +130,7 @@ describe Spectator::Matchers::EqualityMatcher do
|
|||
value = 42
|
||||
label = "everything"
|
||||
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.negated_message.should contain(label)
|
||||
end
|
||||
|
|
|
@ -60,7 +60,7 @@ describe Spectator::Matchers::GreaterThanEqualMatcher do
|
|||
value = 42
|
||||
label = "everything"
|
||||
partial = new_partial(value)
|
||||
matcher = Spectator::Matchers::GreaterThanEqualMatcher.new(label, value)
|
||||
matcher = Spectator::Matchers::GreaterThanEqualMatcher.new(value, label)
|
||||
matcher.message(partial).should contain(label)
|
||||
end
|
||||
|
||||
|
@ -95,7 +95,7 @@ describe Spectator::Matchers::GreaterThanEqualMatcher do
|
|||
value = 42
|
||||
label = "everything"
|
||||
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)
|
||||
end
|
||||
|
||||
|
|
|
@ -60,7 +60,7 @@ describe Spectator::Matchers::GreaterThanMatcher do
|
|||
value = 42
|
||||
label = "everything"
|
||||
partial = new_partial(value)
|
||||
matcher = Spectator::Matchers::GreaterThanMatcher.new(label, value)
|
||||
matcher = Spectator::Matchers::GreaterThanMatcher.new(value, label)
|
||||
matcher.message(partial).should contain(label)
|
||||
end
|
||||
|
||||
|
@ -95,7 +95,7 @@ describe Spectator::Matchers::GreaterThanMatcher do
|
|||
value = 42
|
||||
label = "everything"
|
||||
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)
|
||||
end
|
||||
|
||||
|
|
|
@ -235,7 +235,7 @@ describe Spectator::Matchers::AttributesMatcher do
|
|||
attributes = {size: 6}
|
||||
label = "everything"
|
||||
partial = new_partial(value)
|
||||
matcher = Spectator::Matchers::AttributesMatcher.new(label, attributes)
|
||||
matcher = Spectator::Matchers::AttributesMatcher.new(attributes, label)
|
||||
matcher.message(partial).should contain(label)
|
||||
end
|
||||
|
||||
|
@ -265,7 +265,7 @@ describe Spectator::Matchers::AttributesMatcher do
|
|||
attributes = {size: 6}
|
||||
label = "everything"
|
||||
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)
|
||||
end
|
||||
|
||||
|
|
|
@ -62,7 +62,7 @@ describe Spectator::Matchers::HaveKeyMatcher do
|
|||
key = :foo
|
||||
label = "blah"
|
||||
partial = new_partial(tuple)
|
||||
matcher = Spectator::Matchers::HaveKeyMatcher.new(label, key)
|
||||
matcher = Spectator::Matchers::HaveKeyMatcher.new(key, label)
|
||||
matcher.message(partial).should contain(label)
|
||||
end
|
||||
|
||||
|
@ -92,7 +92,7 @@ describe Spectator::Matchers::HaveKeyMatcher do
|
|||
key = :foo
|
||||
label = "blah"
|
||||
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)
|
||||
end
|
||||
|
||||
|
|
|
@ -479,7 +479,7 @@ describe Spectator::Matchers::HaveMatcher do
|
|||
search = "baz"
|
||||
label = "everything"
|
||||
partial = new_partial(value)
|
||||
matcher = Spectator::Matchers::HaveMatcher.new(label, {search})
|
||||
matcher = Spectator::Matchers::HaveMatcher.new({search}, label)
|
||||
matcher.message(partial).should contain(label)
|
||||
end
|
||||
|
||||
|
@ -509,7 +509,7 @@ describe Spectator::Matchers::HaveMatcher do
|
|||
search = "baz"
|
||||
label = "everything"
|
||||
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)
|
||||
end
|
||||
|
||||
|
|
|
@ -38,7 +38,7 @@ describe Spectator::Matchers::HaveValueMatcher do
|
|||
value = "bar"
|
||||
label = "blah"
|
||||
partial = new_partial(hash)
|
||||
matcher = Spectator::Matchers::HaveValueMatcher.new(label, value)
|
||||
matcher = Spectator::Matchers::HaveValueMatcher.new(value, label)
|
||||
matcher.message(partial).should contain(label)
|
||||
end
|
||||
|
||||
|
@ -68,7 +68,7 @@ describe Spectator::Matchers::HaveValueMatcher do
|
|||
value = "bar"
|
||||
label = "blah"
|
||||
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)
|
||||
end
|
||||
|
||||
|
|
|
@ -82,7 +82,7 @@ describe Spectator::Matchers::InequalityMatcher do
|
|||
value = 42
|
||||
label = "everything"
|
||||
partial = new_partial(value)
|
||||
matcher = Spectator::Matchers::InequalityMatcher.new(label, value)
|
||||
matcher = Spectator::Matchers::InequalityMatcher.new(value, label)
|
||||
matcher.message(partial).should contain(label)
|
||||
end
|
||||
|
||||
|
@ -117,7 +117,7 @@ describe Spectator::Matchers::InequalityMatcher do
|
|||
value = 42
|
||||
label = "everything"
|
||||
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)
|
||||
end
|
||||
|
||||
|
|
|
@ -60,7 +60,7 @@ describe Spectator::Matchers::LessThanEqualMatcher do
|
|||
value = 42
|
||||
label = "everything"
|
||||
partial = new_partial(value)
|
||||
matcher = Spectator::Matchers::LessThanEqualMatcher.new(label, value)
|
||||
matcher = Spectator::Matchers::LessThanEqualMatcher.new(value, label)
|
||||
matcher.message(partial).should contain(label)
|
||||
end
|
||||
|
||||
|
@ -95,7 +95,7 @@ describe Spectator::Matchers::LessThanEqualMatcher do
|
|||
value = 42
|
||||
label = "everything"
|
||||
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)
|
||||
end
|
||||
|
||||
|
|
|
@ -60,7 +60,7 @@ describe Spectator::Matchers::LessThanMatcher do
|
|||
value = 42
|
||||
label = "everything"
|
||||
partial = new_partial(value)
|
||||
matcher = Spectator::Matchers::LessThanMatcher.new(label, value)
|
||||
matcher = Spectator::Matchers::LessThanMatcher.new(value, label)
|
||||
matcher.message(partial).should contain(label)
|
||||
end
|
||||
|
||||
|
@ -95,7 +95,7 @@ describe Spectator::Matchers::LessThanMatcher do
|
|||
value = 42
|
||||
label = "everything"
|
||||
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)
|
||||
end
|
||||
|
||||
|
|
|
@ -150,7 +150,7 @@ describe Spectator::Matchers::RangeMatcher do
|
|||
value = 5
|
||||
label = "everything"
|
||||
partial = new_partial(value)
|
||||
matcher = Spectator::Matchers::RangeMatcher.new(label, range)
|
||||
matcher = Spectator::Matchers::RangeMatcher.new(range, label)
|
||||
matcher.message(partial).should contain(label)
|
||||
end
|
||||
|
||||
|
@ -180,7 +180,7 @@ describe Spectator::Matchers::RangeMatcher do
|
|||
value = 5
|
||||
label = "everything"
|
||||
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)
|
||||
end
|
||||
|
||||
|
@ -252,7 +252,7 @@ describe Spectator::Matchers::RangeMatcher do
|
|||
value = 3
|
||||
label = "foobar"
|
||||
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)
|
||||
end
|
||||
|
||||
|
@ -282,7 +282,7 @@ describe Spectator::Matchers::RangeMatcher do
|
|||
value = 3
|
||||
label = "foobar"
|
||||
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)
|
||||
end
|
||||
|
||||
|
@ -380,7 +380,7 @@ describe Spectator::Matchers::RangeMatcher do
|
|||
value = 5
|
||||
label = "foobar"
|
||||
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)
|
||||
end
|
||||
end
|
||||
|
@ -407,7 +407,7 @@ describe Spectator::Matchers::RangeMatcher do
|
|||
value = 5
|
||||
label = "foobar"
|
||||
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)
|
||||
end
|
||||
end
|
||||
|
@ -478,7 +478,7 @@ describe Spectator::Matchers::RangeMatcher do
|
|||
value = 5
|
||||
label = "foobar"
|
||||
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)
|
||||
end
|
||||
end
|
||||
|
@ -497,7 +497,7 @@ describe Spectator::Matchers::RangeMatcher do
|
|||
value = 5
|
||||
label = "foobar"
|
||||
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)
|
||||
end
|
||||
end
|
||||
|
@ -578,7 +578,7 @@ describe Spectator::Matchers::RangeMatcher do
|
|||
value = 5
|
||||
label = "foobar"
|
||||
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)
|
||||
end
|
||||
end
|
||||
|
@ -605,7 +605,7 @@ describe Spectator::Matchers::RangeMatcher do
|
|||
value = 5
|
||||
label = "foobar"
|
||||
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)
|
||||
end
|
||||
end
|
||||
|
@ -676,7 +676,7 @@ describe Spectator::Matchers::RangeMatcher do
|
|||
value = 5
|
||||
label = "foobar"
|
||||
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)
|
||||
end
|
||||
end
|
||||
|
@ -695,7 +695,7 @@ describe Spectator::Matchers::RangeMatcher do
|
|||
value = 5
|
||||
label = "foobar"
|
||||
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)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -54,7 +54,7 @@ describe Spectator::Matchers::RegexMatcher do
|
|||
label = "different"
|
||||
pattern = /foo/
|
||||
partial = new_partial(value)
|
||||
matcher = Spectator::Matchers::RegexMatcher.new(label, pattern)
|
||||
matcher = Spectator::Matchers::RegexMatcher.new(pattern, label)
|
||||
matcher.message(partial).should contain(label)
|
||||
end
|
||||
|
||||
|
@ -92,7 +92,7 @@ describe Spectator::Matchers::RegexMatcher do
|
|||
label = "different"
|
||||
pattern = /foo/
|
||||
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)
|
||||
end
|
||||
|
||||
|
|
|
@ -225,7 +225,7 @@ describe Spectator::Matchers::StartWithMatcher do
|
|||
start = "baz"
|
||||
label = "everything"
|
||||
partial = new_partial(value)
|
||||
matcher = Spectator::Matchers::StartWithMatcher.new(label, start)
|
||||
matcher = Spectator::Matchers::StartWithMatcher.new(start, label)
|
||||
matcher.message(partial).should contain(label)
|
||||
end
|
||||
|
||||
|
@ -281,7 +281,7 @@ describe Spectator::Matchers::StartWithMatcher do
|
|||
start = "baz"
|
||||
label = "everything"
|
||||
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)
|
||||
end
|
||||
|
||||
|
|
|
@ -47,19 +47,19 @@ module Spectator::Matchers
|
|||
lower = center - diff
|
||||
upper = center + diff
|
||||
range = Range.new(lower, upper)
|
||||
RangeMatcher.new("#{center} +/- #{label}", range)
|
||||
RangeMatcher.new(range, "#{center} +/- #{label}")
|
||||
end
|
||||
|
||||
# Returns a new matcher, with the same bounds, but uses an inclusive range.
|
||||
def inclusive
|
||||
range = Range.new(@expected.begin, @expected.end, exclusive: false)
|
||||
RangeMatcher.new(label + " (inclusive)", range)
|
||||
RangeMatcher.new(range, label + " (inclusive)")
|
||||
end
|
||||
|
||||
# Returns a new matcher, with the same bounds, but uses an exclusive range.
|
||||
def exclusive
|
||||
range = Range.new(@expected.begin, @expected.end, exclusive: true)
|
||||
RangeMatcher.new(label + " (exclusive)", range)
|
||||
RangeMatcher.new(range, label + " (exclusive)")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -17,14 +17,14 @@ module Spectator::Matchers
|
|||
# Creates the value matcher.
|
||||
# The label should be a string representation of the expectation.
|
||||
# The expected value is stored for later use.
|
||||
def initialize(@label : String, @expected : ExpectedType)
|
||||
def initialize(@expected : ExpectedType, @label : String)
|
||||
end
|
||||
|
||||
# Creates the value matcher.
|
||||
# The label is generated by calling `#to_s` on the expected value.
|
||||
# The expected value is stored for later use.
|
||||
def initialize(expected : ExpectedType)
|
||||
initialize(expected.to_s, expected)
|
||||
initialize(expected, expected.to_s)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue