diff options
author | Homu <homu@barosl.com> | 2016-01-19 19:15:02 -0800 |
---|---|---|
committer | Homu <homu@barosl.com> | 2016-01-19 19:15:02 -0800 |
commit | 9fe75c9c5241aaf3ae959a521387a3a4bbdc3de3 (patch) | |
tree | 03c15f13d1f1101aa69456440b2228b1f9a4a7f5 | |
parent | 340866ec79d91823d17467e3a17187ef7e260a66 (diff) | |
parent | 1ab95244a0600cf01f1d190bc69ae140c69b8fb3 (diff) | |
download | bundler-9fe75c9c5241aaf3ae959a521387a3a4bbdc3de3.tar.gz |
Auto merge of #4216 - RochesterinNYC:add-unit-tests-for-bundler-source, r=segiddins
Add unit tests for `Bundler::Source`
-rw-r--r-- | spec/bundler/source_spec.rb | 118 |
1 files changed, 118 insertions, 0 deletions
diff --git a/spec/bundler/source_spec.rb b/spec/bundler/source_spec.rb new file mode 100644 index 0000000000..5e1fb0ad9d --- /dev/null +++ b/spec/bundler/source_spec.rb @@ -0,0 +1,118 @@ +require "spec_helper" + +describe Bundler::Source do + class ExampleSource < Bundler::Source + end + + subject { ExampleSource.new } + + describe "#unmet_deps" do + let(:specs) { double(:specs) } + let(:unmet_dependency_names) { double(:unmet_dependency_names) } + + before do + allow(subject).to receive(:specs).and_return(specs) + allow(specs).to receive(:unmet_dependency_names).and_return(unmet_dependency_names) + end + + it "should return the names of unmet dependencies" do + expect(subject.unmet_deps).to eq(unmet_dependency_names) + end + end + + describe "#version_message" do + let(:spec) { double(:spec, :name => "nokogiri", :version => ">= 1.6") } + + shared_examples_for "the lockfile specs are not relevant" do + it "should return a string with the spec name and version" do + expect(subject.version_message(spec)).to eq("nokogiri >= 1.6") + end + end + + context "when there are locked gems" do + let(:locked_gems) { double(:locked_gems) } + + before { allow(Bundler).to receive(:locked_gems).and_return(locked_gems) } + + context "that contain the relevant gem spec" do + before do + specs = double(:specs) + allow(locked_gems).to receive(:specs).and_return(specs) + allow(specs).to receive(:find).and_return(locked_gem) + end + + context "without a version" do + let(:locked_gem) { double(:locked_gem, :name => "nokogiri", :version => nil) } + + it_behaves_like "the lockfile specs are not relevant" + end + + context "with the same version" do + let(:locked_gem) { double(:locked_gem, :name => "nokogiri", :version => ">= 1.6") } + + it_behaves_like "the lockfile specs are not relevant" + end + + context "with a different version" do + let(:locked_gem) { double(:locked_gem, :name => "nokogiri", :version => "< 1.5") } + + it "should return a string with the spec name and version and locked spec version" do + expect(subject.version_message(spec)).to eq("nokogiri >= 1.6 (was < 1.5)") + end + end + end + + context "that do not contain the relevant gem spec" do + before do + specs = double(:specs) + allow(locked_gems).to receive(:specs).and_return(specs) + allow(specs).to receive(:find).and_return(nil) + end + + it_behaves_like "the lockfile specs are not relevant" + end + end + + context "when there are no locked gems" do + before { allow(Bundler).to receive(:locked_gems).and_return(nil) } + + it_behaves_like "the lockfile specs are not relevant" + end + end + + describe "#can_lock?" do + context "when the passed spec's source is equivalent" do + let(:spec) { double(:spec, :source => subject) } + + it "should return true" do + expect(subject.can_lock? spec).to be_truthy + end + end + + context "when the passed spec's source is not equivalent" do + let(:spec) { double(:spec, :source => double(:other_source)) } + + it "should return false" do + expect(subject.can_lock? spec).to be_falsey + end + end + end + + describe "#include?" do + context "when the passed source is equivalent" do + let(:source) { subject } + + it "should return true" do + expect(subject).to include(source) + end + end + + context "when the passed source is not equivalent" do + let(:source) { double(:source) } + + it "should return false" do + expect(subject).to_not include(source) + end + end + end +end |