You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
The text was updated successfully, but these errors were encountered:
ag-TJNII
changed the title
Cannot compare SemVer to nil
Cannot compare Semantic::Version to nil
Mar 18, 2021
bdcheung
added a commit
to bdcheung/semantic
that referenced
this issue
Jun 21, 2021
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
nil
argument case and throwing ArgumentError if passed something that doesn't behave like a Semantic::Version.The text was updated successfully, but these errors were encountered: