Allow the negate formating for cmp (#6862)

* Allow the negate formating for cmp

The 'cmp' matcher when used with a negation as 'should_not' does
has a confusion formating when control fails:
expected: 3
     got: 3

This, because the 'format_actual' always pass 'false' to the
'format_expectation'. Thus the 'format_expectation' never reach the
'negate_str'.

Signed-off-by: Pg <pg.developper.fr@gmail.com>

* Linting

Signed-off-by: Pg <pg.developper.fr@gmail.com>
Co-authored-by: Vasundhara Jagdale <vjagdale@progress.com>

---------

Signed-off-by: Pg <pg.developper.fr@gmail.com>
Co-authored-by: Vasundhara Jagdale <vjagdale@progress.com>
This commit is contained in:
Pg 2024-02-20 10:29:54 +01:00 committed by GitHub
parent cb807a4ac3
commit f5fd9a75f7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -299,9 +299,9 @@ RSpec::Matchers.define :cmp do |first_expected| # rubocop:disable Metrics/BlockL
end
end
def format_actual(actual)
def format_actual(actual, negate = false)
actual = "0%o" % actual if octal?(@expected) && !actual.nil?
"\n%s\n got: %s\n\n(compared using `cmp` matcher)\n" % [format_expectation(false), actual]
"\n%s\n got: %s\n\n(compared using `cmp` matcher)\n" % [format_expectation(negate), actual]
end
def format_expectation(negate)
@ -316,7 +316,7 @@ RSpec::Matchers.define :cmp do |first_expected| # rubocop:disable Metrics/BlockL
end
failure_message_when_negated do |actual|
format_actual actual
format_actual actual, true
end
description do