From fd43f1135ccd239667ea03fb17fa6334610e9fbe Mon Sep 17 00:00:00 2001 From: Christian Bruckmayer Date: Wed, 22 Aug 2018 09:25:40 +0200 Subject: [PATCH] Fix DepProxy#== undefind method error DepProxy#== crashed with an undefind method error for anything other than a DepProxy class or nil as parameter. This was caused that it was assumed only DepProxy instances or nil can get passed as parameter. This commit implements checking the class as well and returns false if the classes are not the same. Fixes jruby/jruby#5280 travis-ci/travis-ci#9994 --- lib/bundler/dep_proxy.rb | 2 +- spec/bundler/dep_proxy_spec.rb | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 spec/bundler/dep_proxy_spec.rb diff --git a/lib/bundler/dep_proxy.rb b/lib/bundler/dep_proxy.rb index 7a9423b14aa..77db9ebfb78 100644 --- a/lib/bundler/dep_proxy.rb +++ b/lib/bundler/dep_proxy.rb @@ -14,7 +14,7 @@ def hash end def ==(other) - return if other.nil? + return false if other.class != self.class dep == other.dep && __platform == other.__platform end diff --git a/spec/bundler/dep_proxy_spec.rb b/spec/bundler/dep_proxy_spec.rb new file mode 100644 index 00000000000..16d2210b758 --- /dev/null +++ b/spec/bundler/dep_proxy_spec.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +RSpec.describe Bundler::DepProxy do + let(:dep) { Bundler::Dependency.new("rake", ">= 0") } + subject { described_class.new(dep, Gem::Platform::RUBY) } + let(:same) { subject } + let(:other) { subject.dup } + let(:different) { described_class.new(dep, Gem::Platform::JAVA) } + + describe "#eql?" do + it { expect(subject.eql?(same)).to be true } + it { expect(subject.eql?(other)).to be true } + it { expect(subject.eql?(different)).to be false } + it { expect(subject.eql?(nil)).to be false } + it { expect(subject.eql?("foobar")).to be false } + end +end