summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Blair <tim@bla.ir>2015-07-08 21:57:07 +0100
committerAndre Arko <andre@arko.net>2015-07-09 22:22:39 -0700
commita400ae031f4895b6bd85671bd52de843ce16792a (patch)
tree9d48eed3f1427ef56f6714ef4502d06b19c11d38
parentcb871004ed2b7fc774075b426045864b748487bc (diff)
downloadbundler-a400ae031f4895b6bd85671bd52de843ce16792a.tar.gz
Clean up duplicate specs for RemoteSpecification
-rw-r--r--spec/bundler/remote_specification_spec.rb106
1 files changed, 41 insertions, 65 deletions
diff --git a/spec/bundler/remote_specification_spec.rb b/spec/bundler/remote_specification_spec.rb
index 83b0cd794b..fa3534d8a2 100644
--- a/spec/bundler/remote_specification_spec.rb
+++ b/spec/bundler/remote_specification_spec.rb
@@ -8,93 +8,69 @@ describe Bundler::RemoteSpecification do
describe "#<=>" do
let(:name) { "foo" }
let(:version) { Gem::Version.new("1.0.0") }
- let(:newer_version) { Gem::Version.new("1.1.0") }
- let(:older_version) { Gem::Version.new("0.9.0") }
let(:platform) { Gem::Platform::RUBY }
+ let(:other_name) { name }
+ let(:other_version) { version }
+ let(:other_platform) { platform }
+
subject 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)
+ shared_examples_for "a comparison" do
+ context "which exactly matches" do
+ it "returns 0" do
+ expect(subject <=> other).to eq(0)
+ end
end
- it "compares based on the same version" do
- expect(subject <=> same_gem).to eq(0)
+ context "which is different by name" do
+ let(:other_name) { "a" }
+ it "doesn't return 0" do
+ expect(subject <=> other).not_to eq(0)
+ end
end
- it "compares based on an older version" do
- expect(subject).to be < newer_gem
+ context "which has a lower version" do
+ let(:other_version) { Gem::Version.new("0.9.0") }
+ it "returns 1" do
+ expect(subject <=> other).to eq(1)
+ end
end
- it "compares based on a newer version" do
- expect(subject).to be > older_gem
+ context "which has a higher version" do
+ let(:other_version) { Gem::Version.new("1.1.0") }
+ it "returns -1" do
+ expect(subject <=> other).to eq(-1)
+ end
end
- it "compares based on platform" do
- expect(subject <=> different_platform).not_to eq(0)
+ context "which has a different platform" do
+ let(:other_platform) { Gem::Platform.new("x86-mswin32") }
+ it "doesn't return 0" do
+ expect(subject <=> other).not_to eq(0)
+ end
end
end
- context "given a Gem::Specification" do
- let(:same_gem) do
- Gem::Specification.new(name, version)
+ context "comparing another Bundler::RemoteSpecification" do
+ let(:other) do
+ Bundler::RemoteSpecification.new(other_name, other_version,
+ other_platform, nil)
end
- let(:different_name) do
- Gem::Specification.new("bar", version)
- end
-
- let(:newer_gem) do
- Gem::Specification.new(name, newer_version)
- end
-
- let(:older_gem) do
- Gem::Specification.new(name, older_version)
- end
-
- let(:different_platform) do
- s = Gem::Specification.new(name, version)
- s.platform = Gem::Platform.new "x86-mswin32"
- s
- end
-
- it "compares based on name" do
- expect(subject <=> different_name).not_to eq(0)
- end
+ it_should_behave_like "a comparison"
+ end
- it "compares based on version" do
- expect(subject <=> same_gem).to eq(0)
- expect(subject).to be < newer_gem
- expect(subject).to be > older_gem
+ context "comparing a Gem::Specification" do
+ let(:other) do
+ Gem::Specification.new(other_name, other_version).tap do |s|
+ s.platform = other_platform
+ end
end
- it "compares based on platform" do
- expect(subject <=> different_platform).not_to eq(0)
- end
+ it_should_behave_like "a comparison"
end
end
end