Convert Dependency test to spec.
This commit is contained in:
		
							parent
							
								
									0a8c8f90b6
								
							
						
					
					
						commit
						3abfdc9e80
					
				
							
								
								
									
										24
									
								
								Library/Homebrew/test/dependable_spec.rb
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										24
									
								
								Library/Homebrew/test/dependable_spec.rb
									
									
									
									
									
										Normal file
									
								
							@ -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
 | 
			
		||||
							
								
								
									
										121
									
								
								Library/Homebrew/test/dependency_spec.rb
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										121
									
								
								Library/Homebrew/test/dependency_spec.rb
									
									
									
									
									
										Normal file
									
								
							@ -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
 | 
			
		||||
@ -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
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user