aboutsummaryrefslogtreecommitdiffstats
path: root/Library
diff options
context:
space:
mode:
authorMaxim Belkin2018-02-20 21:33:38 +0000
committerMaxim Belkin2018-02-20 21:33:38 +0000
commit14d7a7a08c9aab7db14ea03f59ec85899e5e3ba6 (patch)
treeee1c13ac58238ef2852a1bbebbbce2286f0562bd /Library
parentc6dac68d8bdb652152d89a097a9ab9f270832d68 (diff)
downloadbrew-14d7a7a08c9aab7db14ea03f59ec85899e5e3ba6.tar.bz2
Code refactoring 4.0
Diffstat (limited to 'Library')
-rw-r--r--Library/Homebrew/extend/os/dependency_collector.rb1
-rw-r--r--Library/Homebrew/extend/os/linux/dependency_collector.rb5
-rw-r--r--Library/Homebrew/test/os/dependency_collector_spec.rb23
-rw-r--r--Library/Homebrew/test/os/linux/dependency_collector_spec.rb53
-rw-r--r--Library/Homebrew/test/os/mac/dependency_collector_spec.rb12
5 files changed, 71 insertions, 23 deletions
diff --git a/Library/Homebrew/extend/os/dependency_collector.rb b/Library/Homebrew/extend/os/dependency_collector.rb
index 56fcad31d..fffec1c99 100644
--- a/Library/Homebrew/extend/os/dependency_collector.rb
+++ b/Library/Homebrew/extend/os/dependency_collector.rb
@@ -1,2 +1,3 @@
require "dependency_collector"
require "extend/os/mac/dependency_collector" if OS.mac?
+require "extend/os/linux/dependency_collector" if OS.linux?
diff --git a/Library/Homebrew/extend/os/linux/dependency_collector.rb b/Library/Homebrew/extend/os/linux/dependency_collector.rb
new file mode 100644
index 000000000..dc5b994b8
--- /dev/null
+++ b/Library/Homebrew/extend/os/linux/dependency_collector.rb
@@ -0,0 +1,5 @@
+class DependencyCollector
+ def xz_dep_if_needed(tags)
+ Dependency.new("xz", tags) unless which("xz")
+ end
+end
diff --git a/Library/Homebrew/test/os/dependency_collector_spec.rb b/Library/Homebrew/test/os/dependency_collector_spec.rb
deleted file mode 100644
index eaae99fe9..000000000
--- a/Library/Homebrew/test/os/dependency_collector_spec.rb
+++ /dev/null
@@ -1,23 +0,0 @@
-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
- it "creates a resource dependency from a '.zip' URL" do
- resource = Resource.new
- resource.url("http://example.com/foo.zip")
- expect(subject.add(resource)).to eq(Dependency.new("zip", [:build]))
- end
-
- it "creates a resource dependency from a '.bz2' URL" do
- resource = Resource.new
- resource.url("http://example.com/foo.tar.bz2")
- expect(subject.add(resource)).to eq(Dependency.new("bzip2", [:build]))
- end
- end
-end
diff --git a/Library/Homebrew/test/os/linux/dependency_collector_spec.rb b/Library/Homebrew/test/os/linux/dependency_collector_spec.rb
new file mode 100644
index 000000000..5771fd59a
--- /dev/null
+++ b/Library/Homebrew/test/os/linux/dependency_collector_spec.rb
@@ -0,0 +1,53 @@
+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
+
+ context "when xz, zip, and bzip2 are not available" do
+ it "creates a resource dependency from a '.xz' URL" do
+ 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]))
+ end
+
+ it "creates a resource dependency from a '.zip' URL" do
+ resource.url("http://example.com/foo.zip")
+ allow_any_instance_of(Object).to receive(:which).with("zip")
+ expect(subject.add(resource)).to eq(Dependency.new("zip", [:build]))
+ end
+
+ it "creates a resource dependency from a '.bz2' URL" do
+ 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]))
+ end
+ end
+
+ context "when xz, zip, and bzip2 are available" do
+ it "does not create a resource dependency from a '.xz' URL" do
+ 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
+ end
+
+ it "does not create a resource dependency from a '.zip' URL" do
+ resource.url("http://example.com/foo.zip")
+ allow_any_instance_of(Object).to receive(:which).with("zip").and_return(Pathname.new("foo"))
+ expect(subject.add(resource)).to be nil
+ end
+
+ it "does not create a resource dependency from a '.bz2' URL" do
+ 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
+ end
+ end
+ end
+end
diff --git a/Library/Homebrew/test/os/mac/dependency_collector_spec.rb b/Library/Homebrew/test/os/mac/dependency_collector_spec.rb
index 5d260ebf7..a8fe8ba54 100644
--- a/Library/Homebrew/test/os/mac/dependency_collector_spec.rb
+++ b/Library/Homebrew/test/os/mac/dependency_collector_spec.rb
@@ -36,6 +36,18 @@ describe DependencyCollector do
expect(subject.add(resource)).to be nil
end
+ specify "Resource dependency from a '.zip' URL" do
+ resource = Resource.new
+ resource.url("http://example.com/foo.zip")
+ expect(subject.add(resource)).to be nil
+ end
+
+ specify "Resource dependency from a '.bz2' URL" do
+ resource = Resource.new
+ resource.url("http://example.com/foo.tar.bz2")
+ expect(subject.add(resource)).to be nil
+ end
+
specify "Resource dependency from a '.git' URL" do
resource = Resource.new
resource.url("git://example.com/foo/bar.git")