diff options
| author | Markus Reiter | 2017-02-27 12:55:44 +0100 | 
|---|---|---|
| committer | GitHub | 2017-02-27 12:55:44 +0100 | 
| commit | 0dfe85df1376097ae966f6d710df716ad9a38ff2 (patch) | |
| tree | ecb8ad5c660a0a312dc14fd5ab1fa46c1b93a298 /Library/Homebrew/test/dependency_collector_spec.rb | |
| parent | 7db5f7ce60e0f5a2d70d5009d9cae3a2b19afe47 (diff) | |
| parent | dda5d3ac0564cb491f9d55f2b0d2476d40ee1ee9 (diff) | |
| download | brew-0dfe85df1376097ae966f6d710df716ad9a38ff2.tar.bz2 | |
Merge pull request #2207 from reitermarkus/spec-dependency_collector
Convert DependencyCollector test to spec.
Diffstat (limited to 'Library/Homebrew/test/dependency_collector_spec.rb')
| -rw-r--r-- | Library/Homebrew/test/dependency_collector_spec.rb | 137 | 
1 files changed, 137 insertions, 0 deletions
diff --git a/Library/Homebrew/test/dependency_collector_spec.rb b/Library/Homebrew/test/dependency_collector_spec.rb new file mode 100644 index 000000000..82d117939 --- /dev/null +++ b/Library/Homebrew/test/dependency_collector_spec.rb @@ -0,0 +1,137 @@ +require "dependency_collector" + +RSpec::Matchers.alias_matcher :be_a_build_requirement, :be_build + +describe DependencyCollector do +  def find_dependency(name) +    subject.deps.find { |dep| dep.name == name } +  end + +  def find_requirement(klass) +    subject.requirements.find { |req| req.is_a? klass } +  end + +  after(:each) do +    described_class.clear_cache +  end + +  describe "#add" do +    specify "dependency creation" do +      subject.add "foo" => :build +      subject.add "bar" => ["--universal", :optional] +      expect(find_dependency("foo")).to be_an_instance_of(Dependency) +      expect(find_dependency("bar").tags.count).to eq(2) +    end + +    it "returns the created dependency" do +      expect(subject.add("foo")).to eq(Dependency.new("foo")) +    end + +    specify "requirement creation" do +      subject.add :x11 +      expect(find_requirement(X11Requirement)).to be_an_instance_of(X11Requirement) +    end + +    it "deduplicates requirements" do +      2.times { subject.add :x11 } +      expect(subject.requirements.count).to eq(1) +    end + +    specify "requirement tags" do +      subject.add x11: "2.5.1" +      subject.add xcode: :build +      expect(find_requirement(X11Requirement).tags).to be_empty +      expect(find_requirement(XcodeRequirement)).to be_a_build_requirement +    end + +    specify "x11 without tag" do +      subject.add :x11 +      expect(find_requirement(X11Requirement).tags).to be_empty +    end + +    specify "x11 with minimum version" do +      subject.add x11: "2.5.1" +      expect(find_requirement(X11Requirement).min_version.to_s).to eq("2.5.1") +    end + +    specify "x11 with tag" do +      subject.add x11: :optional +      expect(find_requirement(X11Requirement)).to be_optional +    end + +    specify "x11 with minimum version and tag" do +      subject.add x11: ["2.5.1", :optional] +      dep = find_requirement(X11Requirement) +      expect(dep.min_version.to_s).to eq("2.5.1") +      expect(dep).to be_optional +    end + +    specify "ant dependency" do +      subject.add ant: :build +      expect(find_dependency("ant")).to eq(Dependency.new("ant", [:build])) +    end + +    it "doesn't mutate the dependency spec" do +      spec = { "foo" => :optional } +      copy = spec.dup +      subject.add(spec) +      expect(spec).to eq(copy) +    end + +    it "creates a resource dependency from a '.git' URL" do +      resource = Resource.new +      resource.url("git://example.com/foo/bar.git") +      expect(subject.add(resource)).to be_an_instance_of(GitRequirement) +    end + +    it "creates a resource dependency from a '.7z' URL" do +      resource = Resource.new +      resource.url("http://example.com/foo.7z") +      expect(subject.add(resource)).to eq(Dependency.new("p7zip", [:build])) +    end + +    it "creates a resource dependency from a '.gz' URL" do +      resource = Resource.new +      resource.url("http://example.com/foo.tar.gz") +      expect(subject.add(resource)).to be nil +    end + +    it "creates a resource dependency from a '.lz' URL" do +      resource = Resource.new +      resource.url("http://example.com/foo.lz") +      expect(subject.add(resource)).to eq(Dependency.new("lzip", [:build])) +    end + +    it "creates a resource dependency from a '.lha' URL" do +      resource = Resource.new +      resource.url("http://example.com/foo.lha") +      expect(subject.add(resource)).to eq(Dependency.new("lha", [:build])) +    end + +    it "creates a resource dependency from a '.lzh' URL" do +      resource = Resource.new +      resource.url("http://example.com/foo.lzh") +      expect(subject.add(resource)).to eq(Dependency.new("lha", [:build])) +    end + +    it "creates a resource dependency from a '.rar' URL" do +      resource = Resource.new +      resource.url("http://example.com/foo.rar") +      expect(subject.add(resource)).to eq(Dependency.new("unrar", [:build])) +    end + +    it "raises a TypeError for unknown classes" do +      expect { subject.add(Class.new) }.to raise_error(TypeError) +    end + +    it "raises a TypeError for unknown Types" do +      expect { subject.add(Object.new) }.to raise_error(TypeError) +    end + +    it "raises a TypeError for a Resource with an unknown download strategy" do +      resource = Resource.new +      resource.download_strategy = Class.new +      expect { subject.add(resource) }.to raise_error(TypeError) +    end +  end +end  | 
