Convert Descriptions test to spec.

This commit is contained in:
Markus Reiter 2017-02-15 03:33:21 +01:00
parent 5a2a063802
commit 66735b91a3
2 changed files with 42 additions and 48 deletions

View File

@ -0,0 +1,42 @@
require "descriptions"
describe Descriptions do
subject { described_class.new(descriptions_hash) }
let(:descriptions_hash) { {} }
it "can print description for a core Formula" do
descriptions_hash["homebrew/core/foo"] = "Core foo"
expect { subject.print }.to output("foo: Core foo\n").to_stdout
end
it "can print description for an external Formula" do
descriptions_hash["somedev/external/foo"] = "External foo"
expect { subject.print }.to output("foo: External foo\n").to_stdout
end
it "can print descriptions for duplicate Formulae" do
descriptions_hash["homebrew/core/foo"] = "Core foo"
descriptions_hash["somedev/external/foo"] = "External foo"
expect { subject.print }.to output(
<<-EOS.undent
homebrew/core/foo: Core foo
somedev/external/foo: External foo
EOS
).to_stdout
end
it "can print descriptions for duplicate core and external Formulae" do
descriptions_hash["homebrew/core/foo"] = "Core foo"
descriptions_hash["somedev/external/foo"] = "External foo"
descriptions_hash["otherdev/external/foo"] = "Other external foo"
expect { subject.print }.to output(
<<-EOS.undent
homebrew/core/foo: Core foo
otherdev/external/foo: Other external foo
somedev/external/foo: External foo
EOS
).to_stdout
end
end

View File

@ -1,48 +0,0 @@
require "testing_env"
require "descriptions"
class DescriptionsTest < Homebrew::TestCase
def setup
super
@descriptions_hash = {}
@descriptions = Descriptions.new(@descriptions_hash)
@old_stdout = $stdout
$stdout = StringIO.new
end
def teardown
$stdout = @old_stdout
super
end
def test_single_core_formula
@descriptions_hash["homebrew/core/foo"] = "Core foo"
@descriptions.print
assert_equal "foo: Core foo", $stdout.string.chomp
end
def test_single_external_formula
@descriptions_hash["somedev/external/foo"] = "External foo"
@descriptions.print
assert_equal "foo: External foo", $stdout.string.chomp
end
def test_even_dupes
@descriptions_hash["homebrew/core/foo"] = "Core foo"
@descriptions_hash["somedev/external/foo"] = "External foo"
@descriptions.print
assert_equal "homebrew/core/foo: Core foo\nsomedev/external/foo: External foo",
$stdout.string.chomp
end
def test_odd_dupes
@descriptions_hash["homebrew/core/foo"] = "Core foo"
@descriptions_hash["somedev/external/foo"] = "External foo"
@descriptions_hash["otherdev/external/foo"] = "Other external foo"
@descriptions.print
assert_equal "homebrew/core/foo: Core foo\notherdev/external/foo: Other external foo\nsomedev/external/foo: External foo",
$stdout.string.chomp
end
end