summaryrefslogtreecommitdiff
path: root/spec/bundler/remote_specification_spec.rb
diff options
context:
space:
mode:
authorTim Blair <tim@bla.ir>2015-07-08 21:18:43 +0100
committerTim Blair <tim@bla.ir>2015-07-08 21:59:33 +0100
commit4285007dcd107c4d7d0817c55bfd53ccf2170b2c (patch)
tree36a9019939dd18b2d7563c014744801bee851796 /spec/bundler/remote_specification_spec.rb
parent53bd2feaf342dc9678c6ace2299e15244af68c43 (diff)
downloadbundler-4285007dcd107c4d7d0817c55bfd53ccf2170b2c.tar.gz
Ensure two RemoteSpecifications are comparable
The RemoteSpecification#sort_obj method was added in e5d936e7 (which was cherry-picked from #3767) to fix #3762, but it still fails when comparing two instances of RemoteSpecification. As #sort_obj is private, the check for other.respond_to?(:sort_obj) returns false, which means the <=> check falls back to the default (from Object) which returns nil if the objects being compared don't match. This then results in an ArgumentError when (e.g.) sorting an array containing multiple instances of RemoteSpecification. The fix is simple: make RemoteSpecification#sort_obj public.
Diffstat (limited to 'spec/bundler/remote_specification_spec.rb')
-rw-r--r--spec/bundler/remote_specification_spec.rb43
1 files changed, 43 insertions, 0 deletions
diff --git a/spec/bundler/remote_specification_spec.rb b/spec/bundler/remote_specification_spec.rb
index c93d6f908b..83b0cd794b 100644
--- a/spec/bundler/remote_specification_spec.rb
+++ b/spec/bundler/remote_specification_spec.rb
@@ -16,6 +16,49 @@ describe Bundler::RemoteSpecification do
Bundler::RemoteSpecification.new(name, version, platform, nil)
end
+ context "given a Bundler::RemoteSpecification" do
+ let(:same_gem) do
+ Bundler::RemoteSpecification.new(name, version, platform, nil)
+ end
+
+ let(:different_name) do
+ Bundler::RemoteSpecification.new("bar", version, platform, nil)
+ end
+
+ let(:newer_gem) do
+ Bundler::RemoteSpecification.new(name, newer_version, platform, nil)
+ end
+
+ let(:older_gem) do
+ Bundler::RemoteSpecification.new(name, older_version, platform, nil)
+ end
+
+ let(:different_platform) do
+ plt = Gem::Platform.new "x86-mswin32"
+ Bundler::RemoteSpecification.new(name, version, plt, nil)
+ end
+
+ it "compares based on name" do
+ expect(subject <=> different_name).not_to eq(0)
+ end
+
+ it "compares based on the same version" do
+ expect(subject <=> same_gem).to eq(0)
+ end
+
+ it "compares based on an older version" do
+ expect(subject).to be < newer_gem
+ end
+
+ it "compares based on a newer version" do
+ expect(subject).to be > older_gem
+ end
+
+ it "compares based on platform" do
+ expect(subject <=> different_platform).not_to eq(0)
+ end
+ end
+
context "given a Gem::Specification" do
let(:same_gem) do
Gem::Specification.new(name, version)