diff --git a/Library/Homebrew/test/version_spec.rb b/Library/Homebrew/test/version_spec.rb index 60b98c2179..51a8641b82 100644 --- a/Library/Homebrew/test/version_spec.rb +++ b/Library/Homebrew/test/version_spec.rb @@ -184,9 +184,14 @@ describe Version do end it "can be compared against tokens" do + expect(described_class.create("2.1.0-p194")).to be > Version::Token.create("2") expect(described_class.create("1")).to be == Version::Token.create("1") end + it "can be compared against Version::NULL_TOKEN" do + expect(described_class.create("2.1.0-p194")).to be > Version::NULL_TOKEN + end + specify "comparison returns nil for non-version" do v = described_class.create("1.0") expect(v <=> Object.new).to be nil diff --git a/Library/Homebrew/version.rb b/Library/Homebrew/version.rb index 1b337377c9..b3312e3277 100644 --- a/Library/Homebrew/version.rb +++ b/Library/Homebrew/version.rb @@ -445,9 +445,9 @@ class Version # Used by the *_build_version comparisons, which formerly returned Fixnum other = Version.new(other.to_s) if other.is_a? Integer return 1 if other.nil? + return 1 if other.respond_to?(:null?) && other.null? other = Version.new(other.to_s) if other.is_a? Token - return 1 if other.respond_to?(:null?) && other.null? return unless other.is_a?(Version) return 0 if version == other.version return 1 if head? && !other.head?