Comparison operators throw NoMethod error when comparing to nil.
[76] pry(main)> v = Semantic::Version.new('1.2.3')
=> #<Semantic::Version:0x0000563cab56df68 @build=nil, @major=1, @minor=2, @patch=3, @pre=nil, @version="1.2.3">
[77] pry(main)> v == nil
NoMethodError: undefined method `major' for nil:NilClass
from /home/tom/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/semantic-1.6.1/lib/semantic/version.rb:86:in `block in <=>'
[78] pry(main)> v < nil
NoMethodError: undefined method `major' for nil:NilClass
from /home/tom/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/semantic-1.6.1/lib/semantic/version.rb:86:in `block in <=>'
[79] pry(main)> v > nil
NoMethodError: undefined method `major' for nil:NilClass
from /home/tom/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/semantic-1.6.1/lib/semantic/version.rb:86:in `block in <=>'
[80] pry(main)> v <=> nil
NoMethodError: undefined method `major' for nil:NilClass
from /home/tom/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/semantic-1.6.1/lib/semantic/version.rb:86:in `block in <=>'
This is a nuisance when testing methods that return a Semantic::Version on success and nil on error as this will cause rspec to throw obtuse NoMethodError exceptions on the test itself.
Recommend handling the nil argument case and throwing ArgumentError if passed something that doesn't behave like a Semantic::Version.
Comparison operators throw NoMethod error when comparing to nil.
This is a nuisance when testing methods that return a Semantic::Version on success and nil on error as this will cause rspec to throw obtuse NoMethodError exceptions on the test itself.
Recommend handling the
nilargument case and throwing ArgumentError if passed something that doesn't behave like a Semantic::Version.