diff --git a/Library/Homebrew/test/version_spec.rb b/Library/Homebrew/test/version_spec.rb index e255fe9ef0..60b98c2179 100644 --- a/Library/Homebrew/test/version_spec.rb +++ b/Library/Homebrew/test/version_spec.rb @@ -183,6 +183,10 @@ describe Version do expect(described_class.create("1")).to be == 1 end + it "can be compared against tokens" do + expect(described_class.create("1")).to be == Version::Token.create("1") + 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 909ed38006..1b337377c9 100644 --- a/Library/Homebrew/version.rb +++ b/Library/Homebrew/version.rb @@ -446,6 +446,7 @@ class Version other = Version.new(other.to_s) if other.is_a? Integer return 1 if other.nil? + 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