From b42bfeb77d8d5f5558a421405f5b8ce2e5b697ee Mon Sep 17 00:00:00 2001 From: James Stocks Date: Wed, 2 May 2018 15:19:57 +0100 Subject: [PATCH] cmp should recognise a string being a negative int (#3007) Signed-off-by: James Stocks --- lib/matchers/matchers.rb | 2 +- .../default/controls/cmp_matcher_spec.rb | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/matchers/matchers.rb b/lib/matchers/matchers.rb index ba572760b..196ee11ad 100644 --- a/lib/matchers/matchers.rb +++ b/lib/matchers/matchers.rb @@ -211,7 +211,7 @@ end RSpec::Matchers.define :cmp do |first_expected| # rubocop:disable Metrics/BlockLength def integer?(value) - !(value =~ /\A0+\Z|\A[1-9]\d*\Z/).nil? + !(value =~ /\A-?0+\Z|\A-?[1-9]\d*\Z/).nil? end def float?(value) diff --git a/test/integration/default/controls/cmp_matcher_spec.rb b/test/integration/default/controls/cmp_matcher_spec.rb index 3e1df6677..0bdd6e9da 100644 --- a/test/integration/default/controls/cmp_matcher_spec.rb +++ b/test/integration/default/controls/cmp_matcher_spec.rb @@ -71,6 +71,19 @@ if os.linux? it { should_not cmp >= 13 } end + describe '-12' do + it { should cmp -12 } + it { should cmp < -11 } + it { should cmp > -13 } + it { should_not cmp < -12 } + it { should_not cmp > -12 } + it { should cmp <= -12 } + it { should cmp >= -12 } + it { should cmp >= -666 } + it { should_not cmp <= -13 } + it { should_not cmp >= -11 } + end + # versions describe '2.4.12' do it { should cmp == '2.4.12' }