aboutsummaryrefslogtreecommitdiffstats
path: root/Library
diff options
context:
space:
mode:
authorMarkus Reiter2017-02-27 12:38:18 +0100
committerGitHub2017-02-27 12:38:18 +0100
commitd9e4addb007ecd608fed4fbeaee57b968db63b15 (patch)
tree14c8da073029cedbc55f007c09eb7d0afaf66f67 /Library
parent0a8c8f90b68b9b2dddcf7284c9c1f941aebb1277 (diff)
parent3abfdc9e8012fb7d36010237323a054306a1ea83 (diff)
downloadbrew-d9e4addb007ecd608fed4fbeaee57b968db63b15.tar.bz2
Merge pull request #2205 from reitermarkus/spec-dependency
Convert Dependency test to spec.
Diffstat (limited to 'Library')
-rw-r--r--Library/Homebrew/test/dependable_spec.rb24
-rw-r--r--Library/Homebrew/test/dependency_spec.rb121
-rw-r--r--Library/Homebrew/test/dependency_test.rb131
3 files changed, 145 insertions, 131 deletions
diff --git a/Library/Homebrew/test/dependable_spec.rb b/Library/Homebrew/test/dependable_spec.rb
new file mode 100644
index 000000000..b646b7634
--- /dev/null
+++ b/Library/Homebrew/test/dependable_spec.rb
@@ -0,0 +1,24 @@
+require "dependable"
+
+RSpec::Matchers.alias_matcher :be_a_build_dependency, :be_build
+
+describe Dependable do
+ subject { double(tags: tags).extend(described_class) }
+ let(:tags) { ["foo", "bar", :build] }
+
+ specify "#options" do
+ expect(subject.options.as_flags.sort).to eq(%w[--foo --bar].sort)
+ end
+
+ specify "#build?" do
+ expect(subject).to be_a_build_dependency
+ end
+
+ specify "#optional?" do
+ expect(subject).not_to be_optional
+ end
+
+ specify "#recommended?" do
+ expect(subject).not_to be_recommended
+ end
+end
diff --git a/Library/Homebrew/test/dependency_spec.rb b/Library/Homebrew/test/dependency_spec.rb
new file mode 100644
index 000000000..4af779cc3
--- /dev/null
+++ b/Library/Homebrew/test/dependency_spec.rb
@@ -0,0 +1,121 @@
+require "dependency"
+
+RSpec::Matchers.alias_matcher :be_a_build_dependency, :be_build
+RSpec::Matchers.alias_matcher :be_a_runtime_dependency, :be_run
+
+describe Dependency do
+ describe "::new" do
+ it "accepts a single tag" do
+ dep = described_class.new("foo", %w[bar])
+ expect(dep.tags).to eq(%w[bar])
+ end
+
+ it "accepts multiple tags" do
+ dep = described_class.new("foo", %w[bar baz])
+ expect(dep.tags.sort).to eq(%w[bar baz].sort)
+ end
+
+ it "preserves symbol tags" do
+ dep = described_class.new("foo", [:build])
+ expect(dep.tags).to eq([:build])
+ end
+
+ it "accepts symbol and string tags" do
+ dep = described_class.new("foo", [:build, "bar"])
+ expect(dep.tags).to eq([:build, "bar"])
+ end
+ end
+
+ describe "::merge_repeats" do
+ it "merges duplicate dependencies" do
+ dep = described_class.new("foo", [:build], nil, "foo")
+ dep2 = described_class.new("foo", ["bar"], nil, "foo2")
+ dep3 = described_class.new("xyz", ["abc"], nil, "foo")
+ merged = described_class.merge_repeats([dep, dep2, dep3])
+ expect(merged.count).to eq(2)
+ expect(merged.first).to be_a described_class
+
+ foo_named_dep = merged.find { |d| d.name == "foo" }
+ expect(foo_named_dep.tags).to eq(["bar"])
+ expect(foo_named_dep.option_names).to include("foo")
+ expect(foo_named_dep.option_names).to include("foo2")
+
+ xyz_named_dep = merged.find { |d| d.name == "xyz" }
+ expect(xyz_named_dep.tags).to eq(["abc"])
+ expect(xyz_named_dep.option_names).to include("foo")
+ expect(xyz_named_dep.option_names).not_to include("foo2")
+ end
+
+ it "merges necessity tags" do
+ required_dep = described_class.new("foo")
+ recommended_dep = described_class.new("foo", [:recommended])
+ optional_dep = described_class.new("foo", [:optional])
+
+ deps = described_class.merge_repeats([required_dep, recommended_dep])
+ expect(deps.count).to eq(1)
+ expect(deps.first).to be_required
+ expect(deps.first).not_to be_recommended
+ expect(deps.first).not_to be_optional
+
+ deps = described_class.merge_repeats([required_dep, optional_dep])
+ expect(deps.count).to eq(1)
+ expect(deps.first).to be_required
+ expect(deps.first).not_to be_recommended
+ expect(deps.first).not_to be_optional
+
+ deps = described_class.merge_repeats([recommended_dep, optional_dep])
+ expect(deps.count).to eq(1)
+ expect(deps.first).not_to be_required
+ expect(deps.first).to be_recommended
+ expect(deps.first).not_to be_optional
+ end
+
+ it "merges temporality tags" do
+ normal_dep = described_class.new("foo")
+ build_dep = described_class.new("foo", [:build])
+ run_dep = described_class.new("foo", [:run])
+
+ deps = described_class.merge_repeats([normal_dep, build_dep])
+ expect(deps.count).to eq(1)
+ expect(deps.first).not_to be_a_build_dependency
+ expect(deps.first).not_to be_a_runtime_dependency
+
+ deps = described_class.merge_repeats([normal_dep, run_dep])
+ expect(deps.count).to eq(1)
+ expect(deps.first).not_to be_a_build_dependency
+ expect(deps.first).not_to be_a_runtime_dependency
+
+ deps = described_class.merge_repeats([build_dep, run_dep])
+ expect(deps.count).to eq(1)
+ expect(deps.first).not_to be_a_build_dependency
+ expect(deps.first).not_to be_a_runtime_dependency
+ end
+ end
+
+ specify "equality" do
+ foo1 = described_class.new("foo")
+ foo2 = described_class.new("foo")
+ expect(foo1).to eq(foo2)
+ expect(foo1).to eql(foo2)
+
+ bar = described_class.new("bar")
+ expect(foo1).not_to eq(bar)
+ expect(foo1).not_to eql(bar)
+
+ foo3 = described_class.new("foo", [:build])
+ expect(foo1).not_to eq(foo3)
+ expect(foo1).not_to eql(foo3)
+ end
+end
+
+describe TapDependency do
+ subject { described_class.new("foo/bar/dog") }
+
+ specify "#tap" do
+ expect(subject.tap).to eq(Tap.new("foo", "bar"))
+ end
+
+ specify "#option_names" do
+ expect(subject.option_names).to eq(%w[dog])
+ end
+end
diff --git a/Library/Homebrew/test/dependency_test.rb b/Library/Homebrew/test/dependency_test.rb
deleted file mode 100644
index 404f26d79..000000000
--- a/Library/Homebrew/test/dependency_test.rb
+++ /dev/null
@@ -1,131 +0,0 @@
-require "testing_env"
-require "dependency"
-
-class DependableTests < Homebrew::TestCase
- def setup
- super
- @tags = ["foo", "bar", :build]
- @dep = Struct.new(:tags).new(@tags).extend(Dependable)
- end
-
- def test_options
- assert_equal %w[--foo --bar].sort, @dep.options.as_flags.sort
- end
-
- def test_interrogation
- assert_predicate @dep, :build?
- refute_predicate @dep, :optional?
- refute_predicate @dep, :recommended?
- end
-end
-
-class DependencyTests < Homebrew::TestCase
- def test_accepts_single_tag
- dep = Dependency.new("foo", %w[bar])
- assert_equal %w[bar], dep.tags
- end
-
- def test_accepts_multiple_tags
- dep = Dependency.new("foo", %w[bar baz])
- assert_equal %w[bar baz].sort, dep.tags.sort
- end
-
- def test_preserves_symbol_tags
- dep = Dependency.new("foo", [:build])
- assert_equal [:build], dep.tags
- end
-
- def test_accepts_symbol_and_string_tags
- dep = Dependency.new("foo", [:build, "bar"])
- assert_equal [:build, "bar"], dep.tags
- end
-
- def test_merge_repeats
- dep = Dependency.new("foo", [:build], nil, "foo")
- dep2 = Dependency.new("foo", ["bar"], nil, "foo2")
- dep3 = Dependency.new("xyz", ["abc"], nil, "foo")
- merged = Dependency.merge_repeats([dep, dep2, dep3])
- assert_equal 2, merged.length
- assert_equal Dependency, merged.first.class
-
- foo_named_dep = merged.find { |d| d.name == "foo" }
- assert_equal ["bar"], foo_named_dep.tags
- assert_includes foo_named_dep.option_names, "foo"
- assert_includes foo_named_dep.option_names, "foo2"
-
- xyz_named_dep = merged.find { |d| d.name == "xyz" }
- assert_equal ["abc"], xyz_named_dep.tags
- assert_includes xyz_named_dep.option_names, "foo"
- refute_includes xyz_named_dep.option_names, "foo2"
- end
-
- def test_merges_necessity_tags
- required_dep = Dependency.new("foo")
- recommended_dep = Dependency.new("foo", [:recommended])
- optional_dep = Dependency.new("foo", [:optional])
-
- deps = Dependency.merge_repeats([required_dep, recommended_dep])
- assert_equal deps.count, 1
- assert_predicate deps.first, :required?
- refute_predicate deps.first, :recommended?
- refute_predicate deps.first, :optional?
-
- deps = Dependency.merge_repeats([required_dep, optional_dep])
- assert_equal deps.count, 1
- assert_predicate deps.first, :required?
- refute_predicate deps.first, :recommended?
- refute_predicate deps.first, :optional?
-
- deps = Dependency.merge_repeats([recommended_dep, optional_dep])
- assert_equal deps.count, 1
- refute_predicate deps.first, :required?
- assert_predicate deps.first, :recommended?
- refute_predicate deps.first, :optional?
- end
-
- def test_merges_temporality_tags
- normal_dep = Dependency.new("foo")
- build_dep = Dependency.new("foo", [:build])
- run_dep = Dependency.new("foo", [:run])
-
- deps = Dependency.merge_repeats([normal_dep, build_dep])
- assert_equal deps.count, 1
- refute_predicate deps.first, :build?
- refute_predicate deps.first, :run?
-
- deps = Dependency.merge_repeats([normal_dep, run_dep])
- assert_equal deps.count, 1
- refute_predicate deps.first, :build?
- refute_predicate deps.first, :run?
-
- deps = Dependency.merge_repeats([build_dep, run_dep])
- assert_equal deps.count, 1
- refute_predicate deps.first, :build?
- refute_predicate deps.first, :run?
- end
-
- def test_equality
- foo1 = Dependency.new("foo")
- foo2 = Dependency.new("foo")
- bar = Dependency.new("bar")
- assert_equal foo1, foo2
- assert_eql foo1, foo2
- refute_equal foo1, bar
- refute_eql foo1, bar
- foo3 = Dependency.new("foo", [:build])
- refute_equal foo1, foo3
- refute_eql foo1, foo3
- end
-end
-
-class TapDependencyTests < Homebrew::TestCase
- def test_tap
- dep = TapDependency.new("foo/bar/dog")
- assert_equal Tap.new("foo", "bar"), dep.tap
- end
-
- def test_option_names
- dep = TapDependency.new("foo/bar/dog")
- assert_equal %w[dog], dep.option_names
- end
-end