1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
require "utils/formatter"
require "utils/tty"
describe Formatter do
describe "::columns" do
let(:input) {
%w[
aa
bbb
ccc
dd
]
}
subject { described_class.columns(input) }
it "doesn't output columns if $stdout is not a TTY." do
allow_any_instance_of(IO).to receive(:tty?).and_return(false)
allow(Tty).to receive(:width).and_return(10)
expect(subject).to eq(
"aa\n" \
"bbb\n" \
"ccc\n" \
"dd\n",
)
end
describe "$stdout is a TTY" do
it "outputs columns" do
allow_any_instance_of(IO).to receive(:tty?).and_return(true)
allow(Tty).to receive(:width).and_return(10)
expect(subject).to eq(
"aa ccc\n" \
"bbb dd\n",
)
end
it "outputs only one line if everything fits" do
allow_any_instance_of(IO).to receive(:tty?).and_return(true)
allow(Tty).to receive(:width).and_return(20)
expect(subject).to eq(
"aa bbb ccc dd\n",
)
end
end
describe "with empty input" do
let(:input) { [] }
it { is_expected.to eq("\n") }
end
end
describe "::pluralize" do
it "pluralizes words" do
expect(described_class.pluralize(0, "cask")).to eq("0 casks")
expect(described_class.pluralize(1, "cask")).to eq("1 cask")
expect(described_class.pluralize(2, "cask")).to eq("2 casks")
end
it "allows specifying custom plural forms" do
expect(described_class.pluralize(1, "child", "children")).to eq("1 child")
expect(described_class.pluralize(2, "child", "children")).to eq("2 children")
end
it "has plural forms of Homebrew jargon" do
expect(described_class.pluralize(1, "formula")).to eq("1 formula")
expect(described_class.pluralize(2, "formula")).to eq("2 formulae")
end
it "pluralizes the last word of a string" do
expect(described_class.pluralize(1, "new formula")).to eq("1 new formula")
expect(described_class.pluralize(2, "new formula")).to eq("2 new formulae")
end
end
end
|