Skip to content
Snippets Groups Projects
Commit f8956b11 authored by Markus Reiter's avatar Markus Reiter
Browse files

Convert Dependencies and Requirements tests to specs.

parent 0dfe85df
No related branches found
No related tags found
No related merge requests found
require "dependencies"
require "dependency"
describe Dependencies do
describe "#<<" do
it "returns itself" do
expect(subject << Dependency.new("foo")).to eq(subject)
end
it "preserves order" do
hash = { 0 => "foo", 1 => "bar", 2 => "baz" }
subject << Dependency.new(hash[0])
subject << Dependency.new(hash[1])
subject << Dependency.new(hash[2])
subject.each_with_index do |dep, i|
expect(dep.name).to eq(hash[i])
end
end
end
specify "#*" do
subject << Dependency.new("foo")
subject << Dependency.new("bar")
expect(subject * ", ").to eq("foo, bar")
end
specify "#to_a" do
dep = Dependency.new("foo")
subject << dep
expect(subject.to_a).to eq([dep])
end
specify "#to_ary" do
dep = Dependency.new("foo")
subject << dep
expect(subject.to_ary).to eq([dep])
end
specify "type helpers" do
foo = Dependency.new("foo")
bar = Dependency.new("bar", [:optional])
baz = Dependency.new("baz", [:build])
qux = Dependency.new("qux", [:recommended])
quux = Dependency.new("quux")
subject << foo << bar << baz << qux << quux
expect(subject.required).to eq([foo, quux])
expect(subject.optional).to eq([bar])
expect(subject.build).to eq([baz])
expect(subject.recommended).to eq([qux])
expect(subject.default.sort_by(&:name)).to eq([foo, baz, quux, qux].sort_by(&:name))
end
specify "equality" do
a = Dependencies.new
b = Dependencies.new
dep = Dependency.new("foo")
a << dep
b << dep
expect(a).to eq(b)
expect(a).to eql(b)
b << Dependency.new("bar", [:optional])
expect(a).not_to eq(b)
expect(a).not_to eql(b)
end
specify "#empty?" do
expect(subject).to be_empty
subject << Dependency.new("foo")
expect(subject).not_to be_empty
end
specify "#inspect" do
expect(subject.inspect).to eq("#<Dependencies: []>")
subject << Dependency.new("foo")
expect(subject.inspect).to eq("#<Dependencies: [#<Dependency: \"foo\" []>]>")
end
end
require "testing_env"
require "dependencies"
require "dependency"
require "requirements"
class DependenciesTests < Homebrew::TestCase
def setup
super
@deps = Dependencies.new
end
def test_shovel_returns_self
assert_same @deps, @deps << Dependency.new("foo")
end
def test_preserves_order
hash = { 0 => "foo", 1 => "bar", 2 => "baz" }
@deps << Dependency.new(hash[0])
@deps << Dependency.new(hash[1])
@deps << Dependency.new(hash[2])
@deps.each_with_index do |dep, idx|
assert_equal hash[idx], dep.name
end
end
def test_repetition
@deps << Dependency.new("foo")
@deps << Dependency.new("bar")
assert_equal "foo, bar", @deps*", "
end
def test_to_a
dep = Dependency.new("foo")
@deps << dep
assert_equal [dep], @deps.to_a
end
def test_to_ary
dep = Dependency.new("foo")
@deps << dep
assert_equal [dep], @deps.to_ary
end
def test_type_helpers
foo = Dependency.new("foo")
bar = Dependency.new("bar", [:optional])
baz = Dependency.new("baz", [:build])
qux = Dependency.new("qux", [:recommended])
quux = Dependency.new("quux")
@deps << foo << bar << baz << qux << quux
assert_equal [foo, quux], @deps.required
assert_equal [bar], @deps.optional
assert_equal [baz], @deps.build
assert_equal [qux], @deps.recommended
assert_equal [foo, baz, quux, qux].sort_by(&:name), @deps.default.sort_by(&:name)
end
def test_equality
a = Dependencies.new
b = Dependencies.new
dep = Dependency.new("foo")
a << dep
b << dep
assert_equal a, b
assert_eql a, b
b << Dependency.new("bar", [:optional])
refute_equal a, b
refute_eql a, b
end
def test_empty
a = Dependencies.new
assert a.empty?
a << Dependency.new("foo")
refute a.empty?
end
def test_inspect
a = Dependencies.new
assert_equal "#<Dependencies: []>", a.inspect
a << Dependency.new("foo")
assert_equal "#<Dependencies: [#<Dependency: \"foo\" []>]>", a.inspect
end
end
class RequirementsTests < Homebrew::TestCase
def setup
super
@reqs = Requirements.new
end
def test_shovel_returns_self
assert_same @reqs, @reqs << Object.new
end
def test_merging_multiple_dependencies
@reqs << X11Requirement.new << X11Requirement.new
assert_equal 1, @reqs.count
@reqs << Requirement.new
assert_equal 2, @reqs.count
end
def test_comparison_prefers_larger
@reqs << X11Requirement.new << X11Requirement.new("x11", %w[2.6])
assert_equal [X11Requirement.new("x11", %w[2.6])], @reqs.to_a
end
def test_comparison_does_not_merge_smaller
@reqs << X11Requirement.new("x11", %w[2.6]) << X11Requirement.new
assert_equal [X11Requirement.new("x11", %w[2.6])], @reqs.to_a
end
end
require "requirements"
describe Requirements do
describe "#<<" do
it "returns itself" do
expect(subject << Object.new).to be(subject)
end
it "merges duplicate requirements" do
subject << X11Requirement.new << X11Requirement.new
expect(subject.count).to eq(1)
subject << Requirement.new
expect(subject.count).to eq(2)
end
it "prefers the larger requirement when merging duplicates" do
subject << X11Requirement.new << X11Requirement.new("x11", %w[2.6])
expect(subject.to_a).to eq([X11Requirement.new("x11", %w[2.6])])
end
it "does not use the smaller requirement when merging duplicates" do
subject << X11Requirement.new("x11", %w[2.6]) << X11Requirement.new
expect(subject.to_a).to eq([X11Requirement.new("x11", %w[2.6])])
end
end
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment