Skip to content

Gem::Version allows proper comparison of version strings

gitlab-qa-bot requested to merge github/fork/pboling/patch-1 into main

Created by: pboling

Using Gem::Version will result in comparisons that handle pre and rc and other variations of versions properly. Also it won't result in version silliness like '2.2.10' < '2.2.2' # => true.

With string version comparison, you have to resort to whacky hacks like converting to Float (line 76), or knowing all possible variations of the comparator.

>> '2.2.10' < '2.2.2'
=> true
>> Gem::Version.new('2.2.10') < Gem::Version.new('2.2.2')
=> false

Gem::Version is also part of Rubygems proper, so it is always available (in this context)!

Version comparison will always be an ongoing issue for rspec-core as it still supports back to Ruby 1.8.7. Related: https://github.com/rspec/rspec-core/pull/2750

Merge request reports