2018-02-20 21:33:38 +00:00
|
|
|
require "dependency_collector"
|
|
|
|
|
|
|
|
describe DependencyCollector do
|
|
|
|
alias_matcher :be_a_build_requirement, :be_build
|
|
|
|
|
|
|
|
after(:each) do
|
|
|
|
described_class.clear_cache
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "#add" do
|
|
|
|
resource = Resource.new
|
|
|
|
|
2018-03-04 11:51:06 -08:00
|
|
|
context "when xz, unzip, and bzip2 are not available" do
|
2018-02-20 21:33:38 +00:00
|
|
|
it "creates a resource dependency from a '.xz' URL" do
|
2018-02-21 13:44:51 +00:00
|
|
|
resource.url("http://example.com/foo.xz")
|
|
|
|
allow_any_instance_of(Object).to receive(:which).with("xz")
|
|
|
|
expect(subject.add(resource)).to eq(Dependency.new("xz", [:build]))
|
2018-02-20 21:33:38 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "creates a resource dependency from a '.zip' URL" do
|
2018-02-21 13:44:51 +00:00
|
|
|
resource.url("http://example.com/foo.zip")
|
2018-03-04 11:51:06 -08:00
|
|
|
allow_any_instance_of(Object).to receive(:which).with("unzip")
|
|
|
|
expect(subject.add(resource)).to eq(Dependency.new("unzip", [:build]))
|
2018-02-20 21:33:38 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "creates a resource dependency from a '.bz2' URL" do
|
2018-02-21 13:44:51 +00:00
|
|
|
resource.url("http://example.com/foo.tar.bz2")
|
|
|
|
allow_any_instance_of(Object).to receive(:which).with("bzip2")
|
|
|
|
expect(subject.add(resource)).to eq(Dependency.new("bzip2", [:build]))
|
2018-02-20 21:33:38 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when xz, zip, and bzip2 are available" do
|
|
|
|
it "does not create a resource dependency from a '.xz' URL" do
|
2018-02-21 13:44:51 +00:00
|
|
|
resource.url("http://example.com/foo.xz")
|
|
|
|
allow_any_instance_of(Object).to receive(:which).with("xz").and_return(Pathname.new("foo"))
|
|
|
|
expect(subject.add(resource)).to be nil
|
2018-02-20 21:33:38 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "does not create a resource dependency from a '.zip' URL" do
|
2018-02-21 13:44:51 +00:00
|
|
|
resource.url("http://example.com/foo.zip")
|
2018-03-04 11:51:06 -08:00
|
|
|
allow_any_instance_of(Object).to receive(:which).with("unzip").and_return(Pathname.new("foo"))
|
2018-02-21 13:44:51 +00:00
|
|
|
expect(subject.add(resource)).to be nil
|
2018-02-20 21:33:38 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "does not create a resource dependency from a '.bz2' URL" do
|
2018-02-21 13:44:51 +00:00
|
|
|
resource.url("http://example.com/foo.tar.bz2")
|
|
|
|
allow_any_instance_of(Object).to receive(:which).with("bzip2").and_return(Pathname.new("foo"))
|
|
|
|
expect(subject.add(resource)).to be nil
|
2018-02-20 21:33:38 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|