-
Notifications
You must be signed in to change notification settings - Fork 6
/
border_spec.rb
125 lines (97 loc) · 3.62 KB
/
border_spec.rb
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
require "spec_helper"
describe Tabulo::Border do
around(:all) do |group|
Tabulo::Deprecation.without_warnings { group.run }
end
describe "#initialize" do
it "returns a new Border" do
border = Tabulo::Border.new
expect(border).to be_a(Tabulo::Border)
end
it "initializes various instance variables" do
border = Tabulo::Border.new(corner_top_left: "/", tee_left: "~", intersection: "*")
expect(border.instance_variable_get(:@corner_top_left)).to eq("/")
expect(border.instance_variable_get(:@tee_left)).to eq("~")
expect(border.instance_variable_get(:@intersection)).to eq("*")
end
end
describe ".from" do
subject do
Tabulo::Border.from(initializer, styler)
end
let(:styler) { nil }
context "when passed `:ascii`" do
let(:initializer) { :ascii }
it "returns a new Border" do
expect(subject).to be_a(Tabulo::Border)
end
end
context "when passed `:classic`" do
let(:initializer) { :classic }
it "returns a new Border" do
expect(subject).to be_a(Tabulo::Border)
end
end
context "when passed `:reduced_ascii`" do
let(:initializer) { :reduced_ascii }
it "returns a new Border" do
expect(subject).to be_a(Tabulo::Border)
end
end
context "when passed `:reduced_modern`" do
let(:initializer) { :reduced_modern }
it "returns a new Border" do
expect(subject).to be_a(Tabulo::Border)
end
end
context "when passed `:markdown`" do
let(:initializer) { :markdown }
it "returns a new Border" do
expect(subject).to be_a(Tabulo::Border)
end
end
context "when passed `:modern`" do
let(:initializer) { :modern }
it "returns a new Border" do
expect(subject).to be_a(Tabulo::Border)
end
end
context "when passed `:blank`" do
let(:initializer) { :blank }
it "returns a new Border" do
expect(subject).to be_a(Tabulo::Border)
end
end
context "when `initializer` parameter is passed an unrecognized value" do
let(:initializer) { :coolness }
it "raises an exception" do
expect { subject }.to raise_error(Tabulo::InvalidBorderError)
end
end
context "when passed a callable to the `styler` parameter" do
let(:initializer) { :ascii }
let(:styler) { double("styler", call: "some styled border") }
it "uses the styler to style the border characters" do
expect(styler).to receive(:call)
subject.join_cell_contents(%w[hello goodbye])
end
end
end
describe "#horizontal_rule" do
it "returns a horizontal line suitable for rendering within a table with the indicated column widths, "\
"at the indicated position, with" do
border = Tabulo::Border.from(:modern)
column_widths = [3, 5, 12]
expect(border.horizontal_rule(column_widths, :top)).to eq("┌───┬─────┬────────────┐")
expect(border.horizontal_rule(column_widths, :middle)).to eq("├───┼─────┼────────────┤")
expect(border.horizontal_rule(column_widths, :bottom)).to eq("└───┴─────┴────────────┘")
end
end
describe "#join_cell_contents" do
it "renders a string in which the passed cell contents are joined by styled border characters" do
border = Tabulo::Border.from(:ascii, -> (x) { "!#{x}!" })
expect(border.join_cell_contents([" hello ", " good morning ", " huh "])).to \
eq("!|! hello !|! good morning !|! huh !|!")
end
end
end