cmp should recognise a string being a negative int (#3007)

Signed-off-by: James Stocks <jstocks@chef.io>
This commit is contained in:
James Stocks 2018-05-02 15:19:57 +01:00 committed by Clinton Wolfe
parent 91a92abf4b
commit b42bfeb77d
2 changed files with 14 additions and 1 deletions

View file

@ -211,7 +211,7 @@ end
RSpec::Matchers.define :cmp do |first_expected| # rubocop:disable Metrics/BlockLength RSpec::Matchers.define :cmp do |first_expected| # rubocop:disable Metrics/BlockLength
def integer?(value) def integer?(value)
!(value =~ /\A0+\Z|\A[1-9]\d*\Z/).nil? !(value =~ /\A-?0+\Z|\A-?[1-9]\d*\Z/).nil?
end end
def float?(value) def float?(value)

View file

@ -71,6 +71,19 @@ if os.linux?
it { should_not cmp >= 13 } it { should_not cmp >= 13 }
end 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 # versions
describe '2.4.12' do describe '2.4.12' do
it { should cmp == '2.4.12' } it { should cmp == '2.4.12' }