Fix for when version is nil
When version is nil, (version <==> other.version) also returns nil and then the nill object doesn't have a nonzero? method. I'm not sure what package put me into this state, but, this fix repaired my environment. Also, there is probably a more ruby-esque way to do this, but, I'm not a ruby expert ;-)
This commit is contained in:
parent
0cf4596952
commit
8ed8d6979c
@ -36,7 +36,10 @@ class PkgVersion
|
||||
def <=>(other)
|
||||
return unless other.is_a?(PkgVersion)
|
||||
|
||||
(version <=> other.version).nonzero? || revision <=> other.revision
|
||||
comp_ver = (version <=> other.version)
|
||||
return if comp_ver.nil?
|
||||
|
||||
comp_ver.nonzero? || revision <=> other.revision
|
||||
end
|
||||
alias eql? ==
|
||||
|
||||
|
||||
@ -54,6 +54,11 @@ describe PkgVersion do
|
||||
describe "#<=>" do
|
||||
it "returns nil if the comparison fails" do
|
||||
expect(described_class.new(Version.create("1.0"), 0) <=> Object.new).to be nil
|
||||
expect(Object.new <=> described_class.new(Version.create("1.0"), 0)).to be nil
|
||||
expect(Object.new <=> described_class.new(Version.create("1.0"), 0)).to be nil
|
||||
expect(described_class.new(Version.create("1.0"), 0) <=> nil).to be nil
|
||||
# This one used to fail due to dereferencing a null `self`
|
||||
expect(described_class.new(nil, 0) <=> described_class.new(Version.create("1.0"), 0)).to be nil
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user