Skip to content

Commit

Permalink
Fix error message in BeNumericallyMatcher (#432)
Browse files Browse the repository at this point in the history
When passing a non-number as the threshold, the error message should
contain the problematic threshold, not the expected value.
  • Loading branch information
khernyo committed Mar 31, 2021
1 parent 3360b8c commit 09c074a
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
2 changes: 1 addition & 1 deletion matchers/be_numerically_matcher.go
Expand Up @@ -45,7 +45,7 @@ func (matcher *BeNumericallyMatcher) Match(actual interface{}) (success bool, er
return false, fmt.Errorf("Expected a number. Got:\n%s", format.Object(matcher.CompareTo[0], 1))
}
if len(matcher.CompareTo) == 2 && !isNumber(matcher.CompareTo[1]) {
return false, fmt.Errorf("Expected a number. Got:\n%s", format.Object(matcher.CompareTo[0], 1))
return false, fmt.Errorf("Expected a number. Got:\n%s", format.Object(matcher.CompareTo[1], 1))
}

switch matcher.Comparator {
Expand Down
1 change: 1 addition & 0 deletions matchers/be_numerically_matcher_test.go
Expand Up @@ -143,6 +143,7 @@ var _ = Describe("BeNumerically", func() {
success, err = (&BeNumericallyMatcher{Comparator: "~", CompareTo: []interface{}{3.0, "foo"}}).Match(5.0)
Expect(success).Should(BeFalse())
Expect(err).Should(HaveOccurred())
Expect(err.Error()).Should(ContainSubstring("foo"))

success, err = (&BeNumericallyMatcher{Comparator: "==", CompareTo: []interface{}{"bar"}}).Match(5)
Expect(success).Should(BeFalse())
Expand Down

0 comments on commit 09c074a

Please sign in to comment.