summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames Wen <jrw2175@columbia.edu>2016-01-20 19:15:05 -0500
committerJames Wen <jrw2175@columbia.edu>2016-01-20 19:21:36 -0500
commit99de353351fe3d976aeeaa26165d26ddd8810597 (patch)
treeafd58a9de5ad2e085e5472c07ed8adc4d079bb3e
parent9fe75c9c5241aaf3ae959a521387a3a4bbdc3de3 (diff)
downloadbundler-99de353351fe3d976aeeaa26165d26ddd8810597.tar.gz
Complete unit test coverage for `Bundler::RemoteSpecification`
-rw-r--r--spec/bundler/remote_specification_spec.rb123
1 files changed, 114 insertions, 9 deletions
diff --git a/spec/bundler/remote_specification_spec.rb b/spec/bundler/remote_specification_spec.rb
index 0e95df094e..1ff986b9a1 100644
--- a/spec/bundler/remote_specification_spec.rb
+++ b/spec/bundler/remote_specification_spec.rb
@@ -1,23 +1,61 @@
require "spec_helper"
describe Bundler::RemoteSpecification do
+ let(:name) { "foo" }
+ let(:version) { Gem::Version.new("1.0.0") }
+ let(:platform) { Gem::Platform::RUBY }
+ let(:spec_fetcher) { double(:spec_fetcher) }
+
+ subject { described_class.new(name, version, platform, spec_fetcher) }
+
it "is Comparable" do
expect(described_class.ancestors).to include(Comparable)
end
- describe "#<=>" do
- let(:name) { "foo" }
- let(:version) { Gem::Version.new("1.0.0") }
- let(:platform) { Gem::Platform::RUBY }
+ it "can match platforms" do
+ expect(described_class.ancestors).to include(Bundler::MatchPlatform)
+ end
- let(:other_name) { name }
- let(:other_version) { version }
- let(:other_platform) { platform }
+ describe "#fetch_platform" do
+ let(:remote_spec) { double(:remote_spec, :platform => "jruby") }
- subject do
- Bundler::RemoteSpecification.new(name, version, platform, nil)
+ before { allow(spec_fetcher).to receive(:fetch_spec).and_return(remote_spec) }
+
+ it "should return the spec platform" do
+ expect(subject.fetch_platform).to eq("jruby")
+ end
+ end
+
+ describe "#full_name" do
+ context "when platform is ruby" do
+ it "should return the spec name and version" do
+ expect(subject.full_name).to eq("foo-1.0.0")
+ end
+ end
+
+ context "when platform is nil" do
+ let(:platform) { nil }
+
+ it "should return the spec name and version" do
+ expect(subject.full_name).to eq("foo-1.0.0")
+ end
end
+ context "when platform is a non-ruby platform" do
+ let(:platform) { "jruby" }
+
+ it "should return the spec name, version, and platform" do
+ expect(subject.full_name).to eq("foo-1.0.0-jruby")
+ end
+ end
+ end
+
+ describe "#<=>" do
+ let(:other_name) { name }
+ let(:other_version) { version }
+ let(:other_platform) { platform }
+ let(:other_spec_fetcher) { spec_fetcher }
+
shared_examples_for "a comparison" do
context "which exactly matches" do
it "returns 0" do
@@ -72,5 +110,72 @@ describe Bundler::RemoteSpecification do
it_should_behave_like "a comparison"
end
+
+ context "comparing a non sortable object" do
+ let(:other) { Object.new }
+ let(:remote_spec) { double(:remote_spec, :platform => "jruby") }
+
+ before do
+ allow(spec_fetcher).to receive(:fetch_spec).and_return(remote_spec)
+ allow(remote_spec).to receive(:<=>).and_return(nil)
+ end
+
+ it "should use default object comparison" do
+ expect(subject <=> other).to eq(nil)
+ end
+ end
+ end
+
+ describe "#__swap__" do
+ let(:spec) { double(:spec) }
+ let(:new_spec) { double(:new_spec) }
+
+ before { subject.instance_variable_set(:@_remote_specification, spec) }
+
+ it "should replace remote specification with the passed spec" do
+ expect(subject.instance_variable_get(:@_remote_specification)).to be(spec)
+ subject.__swap__(new_spec)
+ expect(subject.instance_variable_get(:@_remote_specification)).to be(new_spec)
+ end
+ end
+
+ describe "#sort_obj" do
+ context "when platform is ruby" do
+ it "should return a sorting delegate array with name, version, and -1" do
+ expect(subject.sort_obj).to match_array(["foo", version, -1])
+ end
+ end
+
+ context "when platform is not ruby" do
+ let(:platform) { "jruby" }
+
+ it "should return a sorting delegate array with name, version, and 1" do
+ expect(subject.sort_obj).to match_array(["foo", version, 1])
+ end
+ end
+ end
+
+ describe "method missing" do
+ context "and is present in Gem::Specification" do
+ let(:remote_spec) { double(:remote_spec) }
+
+ before do
+ allow_any_instance_of(Gem::Specification).to receive(:respond_to?).and_return(true)
+ allow(subject).to receive(:_remote_specification).and_return(remote_spec)
+ end
+
+ it "should send through to Gem::Specification" do
+ expect(remote_spec).to receive(:send).with(:missing_method_call).once
+ subject.missing_method_call
+ end
+ end
+
+ context "and is not present in Gem::Specification" do
+ before { allow_any_instance_of(Gem::Specification).to receive(:respond_to?).and_return(false) }
+
+ it "should throw method missing error" do
+ expect { subject.missing_method_call }.to raise_error(NoMethodError)
+ end
+ end
end
end