From 5ba03a90ff243205ec3f762744e1659090254b3d Mon Sep 17 00:00:00 2001 From: Michael Miller Date: Thu, 28 Feb 2019 15:17:12 -0700 Subject: [PATCH] Swap label and expected value parameters This matches the partial initializer parameters. Also cleaned up some code in the Expectation spec. --- spec/expectations/expectation_spec.cr | 82 ++++++------------- spec/helpers/expectations_helper.cr | 8 +- spec/matchers/case_matcher_spec.cr | 4 +- spec/matchers/contain_matcher_spec.cr | 4 +- spec/matchers/end_with_matcher_spec.cr | 4 +- spec/matchers/equality_matcher_spec.cr | 4 +- .../greater_than_equal_matcher_spec.cr | 4 +- spec/matchers/greater_than_matcher_spec.cr | 4 +- spec/matchers/have_attributes_matcher_spec.cr | 4 +- spec/matchers/have_key_matcher_spec.cr | 4 +- spec/matchers/have_matcher_spec.cr | 4 +- spec/matchers/have_value_matcher_spec.cr | 4 +- spec/matchers/inequality_matcher_spec.cr | 4 +- spec/matchers/less_than_equal_matcher_spec.cr | 4 +- spec/matchers/less_than_matcher_spec.cr | 4 +- spec/matchers/range_matcher_spec.cr | 24 +++--- spec/matchers/regex_matcher_spec.cr | 4 +- spec/matchers/start_with_matcher_spec.cr | 4 +- src/spectator/matchers/range_matcher.cr | 6 +- src/spectator/matchers/value_matcher.cr | 4 +- 20 files changed, 74 insertions(+), 110 deletions(-) diff --git a/spec/expectations/expectation_spec.cr b/spec/expectations/expectation_spec.cr index bfc2b0f..e00a72e 100644 --- a/spec/expectations/expectation_spec.cr +++ b/spec/expectations/expectation_spec.cr @@ -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 diff --git a/spec/helpers/expectations_helper.cr b/spec/helpers/expectations_helper.cr index ac04060..bb2daec 100644 --- a/spec/helpers/expectations_helper.cr +++ b/spec/helpers/expectations_helper.cr @@ -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 diff --git a/spec/matchers/case_matcher_spec.cr b/spec/matchers/case_matcher_spec.cr index 84cd32c..2c6daba 100644 --- a/spec/matchers/case_matcher_spec.cr +++ b/spec/matchers/case_matcher_spec.cr @@ -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 diff --git a/spec/matchers/contain_matcher_spec.cr b/spec/matchers/contain_matcher_spec.cr index ce57f8f..b79e345 100644 --- a/spec/matchers/contain_matcher_spec.cr +++ b/spec/matchers/contain_matcher_spec.cr @@ -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 diff --git a/spec/matchers/end_with_matcher_spec.cr b/spec/matchers/end_with_matcher_spec.cr index 7aab554..353afb4 100644 --- a/spec/matchers/end_with_matcher_spec.cr +++ b/spec/matchers/end_with_matcher_spec.cr @@ -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 diff --git a/spec/matchers/equality_matcher_spec.cr b/spec/matchers/equality_matcher_spec.cr index 013272a..e973a15 100644 --- a/spec/matchers/equality_matcher_spec.cr +++ b/spec/matchers/equality_matcher_spec.cr @@ -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 diff --git a/spec/matchers/greater_than_equal_matcher_spec.cr b/spec/matchers/greater_than_equal_matcher_spec.cr index 6a7326a..64e003d 100644 --- a/spec/matchers/greater_than_equal_matcher_spec.cr +++ b/spec/matchers/greater_than_equal_matcher_spec.cr @@ -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 diff --git a/spec/matchers/greater_than_matcher_spec.cr b/spec/matchers/greater_than_matcher_spec.cr index c52cffc..e739482 100644 --- a/spec/matchers/greater_than_matcher_spec.cr +++ b/spec/matchers/greater_than_matcher_spec.cr @@ -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 diff --git a/spec/matchers/have_attributes_matcher_spec.cr b/spec/matchers/have_attributes_matcher_spec.cr index ad43548..473eb7c 100644 --- a/spec/matchers/have_attributes_matcher_spec.cr +++ b/spec/matchers/have_attributes_matcher_spec.cr @@ -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 diff --git a/spec/matchers/have_key_matcher_spec.cr b/spec/matchers/have_key_matcher_spec.cr index 94eab6a..78a0d8f 100644 --- a/spec/matchers/have_key_matcher_spec.cr +++ b/spec/matchers/have_key_matcher_spec.cr @@ -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 diff --git a/spec/matchers/have_matcher_spec.cr b/spec/matchers/have_matcher_spec.cr index 5319aa2..d89de0a 100644 --- a/spec/matchers/have_matcher_spec.cr +++ b/spec/matchers/have_matcher_spec.cr @@ -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 diff --git a/spec/matchers/have_value_matcher_spec.cr b/spec/matchers/have_value_matcher_spec.cr index 08851db..9f1e385 100644 --- a/spec/matchers/have_value_matcher_spec.cr +++ b/spec/matchers/have_value_matcher_spec.cr @@ -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 diff --git a/spec/matchers/inequality_matcher_spec.cr b/spec/matchers/inequality_matcher_spec.cr index 2a025df..19a2b0f 100644 --- a/spec/matchers/inequality_matcher_spec.cr +++ b/spec/matchers/inequality_matcher_spec.cr @@ -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 diff --git a/spec/matchers/less_than_equal_matcher_spec.cr b/spec/matchers/less_than_equal_matcher_spec.cr index 51a8fac..c6fe661 100644 --- a/spec/matchers/less_than_equal_matcher_spec.cr +++ b/spec/matchers/less_than_equal_matcher_spec.cr @@ -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 diff --git a/spec/matchers/less_than_matcher_spec.cr b/spec/matchers/less_than_matcher_spec.cr index 5b1b2f9..376d5c7 100644 --- a/spec/matchers/less_than_matcher_spec.cr +++ b/spec/matchers/less_than_matcher_spec.cr @@ -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 diff --git a/spec/matchers/range_matcher_spec.cr b/spec/matchers/range_matcher_spec.cr index c56c057..fe223eb 100644 --- a/spec/matchers/range_matcher_spec.cr +++ b/spec/matchers/range_matcher_spec.cr @@ -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 diff --git a/spec/matchers/regex_matcher_spec.cr b/spec/matchers/regex_matcher_spec.cr index 889423b..d2eff25 100644 --- a/spec/matchers/regex_matcher_spec.cr +++ b/spec/matchers/regex_matcher_spec.cr @@ -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 diff --git a/spec/matchers/start_with_matcher_spec.cr b/spec/matchers/start_with_matcher_spec.cr index a6f3077..872c43c 100644 --- a/spec/matchers/start_with_matcher_spec.cr +++ b/spec/matchers/start_with_matcher_spec.cr @@ -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 diff --git a/src/spectator/matchers/range_matcher.cr b/src/spectator/matchers/range_matcher.cr index 349b867..b328ae7 100644 --- a/src/spectator/matchers/range_matcher.cr +++ b/src/spectator/matchers/range_matcher.cr @@ -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 diff --git a/src/spectator/matchers/value_matcher.cr b/src/spectator/matchers/value_matcher.cr index 510741e..9ffa6d8 100644 --- a/src/spectator/matchers/value_matcher.cr +++ b/src/spectator/matchers/value_matcher.cr @@ -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