caracal 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +23 -0
- data/Gemfile +3 -0
- data/LICENSE.txt +22 -0
- data/README.md +941 -0
- data/Rakefile +2 -0
- data/caracal.gemspec +27 -0
- data/lib/caracal.rb +31 -0
- data/lib/caracal/core/file_name.rb +39 -0
- data/lib/caracal/core/fonts.rb +75 -0
- data/lib/caracal/core/images.rb +37 -0
- data/lib/caracal/core/line_breaks.rb +29 -0
- data/lib/caracal/core/list_styles.rb +92 -0
- data/lib/caracal/core/lists.rb +57 -0
- data/lib/caracal/core/models/base_model.rb +51 -0
- data/lib/caracal/core/models/border_model.rb +120 -0
- data/lib/caracal/core/models/font_model.rb +64 -0
- data/lib/caracal/core/models/image_model.rb +118 -0
- data/lib/caracal/core/models/line_break_model.rb +15 -0
- data/lib/caracal/core/models/link_model.rb +65 -0
- data/lib/caracal/core/models/list_item_model.rb +105 -0
- data/lib/caracal/core/models/list_model.rb +130 -0
- data/lib/caracal/core/models/list_style_model.rb +129 -0
- data/lib/caracal/core/models/margin_model.rb +76 -0
- data/lib/caracal/core/models/page_break_model.rb +15 -0
- data/lib/caracal/core/models/page_number_model.rb +69 -0
- data/lib/caracal/core/models/page_size_model.rb +70 -0
- data/lib/caracal/core/models/paragraph_model.rb +141 -0
- data/lib/caracal/core/models/relationship_model.rb +108 -0
- data/lib/caracal/core/models/rule_model.rb +27 -0
- data/lib/caracal/core/models/style_model.rb +134 -0
- data/lib/caracal/core/models/table_cell_model.rb +155 -0
- data/lib/caracal/core/models/table_model.rb +206 -0
- data/lib/caracal/core/models/text_model.rb +92 -0
- data/lib/caracal/core/page_breaks.rb +29 -0
- data/lib/caracal/core/page_numbers.rb +51 -0
- data/lib/caracal/core/page_settings.rb +72 -0
- data/lib/caracal/core/relationships.rb +90 -0
- data/lib/caracal/core/rules.rb +35 -0
- data/lib/caracal/core/styles.rb +86 -0
- data/lib/caracal/core/tables.rb +41 -0
- data/lib/caracal/core/text.rb +73 -0
- data/lib/caracal/document.rb +242 -0
- data/lib/caracal/errors.rb +23 -0
- data/lib/caracal/renderers/app_renderer.rb +41 -0
- data/lib/caracal/renderers/content_types_renderer.rb +53 -0
- data/lib/caracal/renderers/core_renderer.rb +44 -0
- data/lib/caracal/renderers/document_renderer.rb +349 -0
- data/lib/caracal/renderers/fonts_renderer.rb +56 -0
- data/lib/caracal/renderers/footer_renderer.rb +69 -0
- data/lib/caracal/renderers/numbering_renderer.rb +87 -0
- data/lib/caracal/renderers/package_relationships_renderer.rb +50 -0
- data/lib/caracal/renderers/relationships_renderer.rb +48 -0
- data/lib/caracal/renderers/settings_renderer.rb +58 -0
- data/lib/caracal/renderers/styles_renderer.rb +163 -0
- data/lib/caracal/renderers/xml_renderer.rb +83 -0
- data/lib/caracal/version.rb +3 -0
- data/lib/tilt/caracal.rb +21 -0
- data/spec/lib/caracal/core/file_name_spec.rb +54 -0
- data/spec/lib/caracal/core/fonts_spec.rb +119 -0
- data/spec/lib/caracal/core/images_spec.rb +25 -0
- data/spec/lib/caracal/core/line_breaks_spec.rb +25 -0
- data/spec/lib/caracal/core/list_styles_spec.rb +121 -0
- data/spec/lib/caracal/core/lists_spec.rb +43 -0
- data/spec/lib/caracal/core/models/base_model_spec.rb +38 -0
- data/spec/lib/caracal/core/models/border_model_spec.rb +159 -0
- data/spec/lib/caracal/core/models/font_model_spec.rb +92 -0
- data/spec/lib/caracal/core/models/image_model_spec.rb +192 -0
- data/spec/lib/caracal/core/models/line_break_model_spec.rb +21 -0
- data/spec/lib/caracal/core/models/link_model_spec.rb +139 -0
- data/spec/lib/caracal/core/models/list_item_model_spec.rb +190 -0
- data/spec/lib/caracal/core/models/list_model_spec.rb +178 -0
- data/spec/lib/caracal/core/models/list_style_model_spec.rb +212 -0
- data/spec/lib/caracal/core/models/margin_model_spec.rb +111 -0
- data/spec/lib/caracal/core/models/page_break_model_spec.rb +21 -0
- data/spec/lib/caracal/core/models/page_number_model_spec.rb +101 -0
- data/spec/lib/caracal/core/models/page_size_model_spec.rb +91 -0
- data/spec/lib/caracal/core/models/paragraph_model_spec.rb +162 -0
- data/spec/lib/caracal/core/models/relationship_model_spec.rb +183 -0
- data/spec/lib/caracal/core/models/rule_model_spec.rb +108 -0
- data/spec/lib/caracal/core/models/style_model_spec.rb +187 -0
- data/spec/lib/caracal/core/models/table_cell_model_spec.rb +221 -0
- data/spec/lib/caracal/core/models/table_model_spec.rb +222 -0
- data/spec/lib/caracal/core/models/text_model_spec.rb +132 -0
- data/spec/lib/caracal/core/page_breaks_spec.rb +25 -0
- data/spec/lib/caracal/core/page_numbers_spec.rb +80 -0
- data/spec/lib/caracal/core/page_settings_spec.rb +143 -0
- data/spec/lib/caracal/core/relationships_spec.rb +119 -0
- data/spec/lib/caracal/core/rules_spec.rb +25 -0
- data/spec/lib/caracal/core/styles_spec.rb +129 -0
- data/spec/lib/caracal/core/tables_spec.rb +25 -0
- data/spec/lib/caracal/core/text_spec.rb +52 -0
- data/spec/lib/caracal/errors_spec.rb +10 -0
- data/spec/spec_helper.rb +8 -0
- metadata +245 -0
@@ -0,0 +1,187 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Caracal::Core::Models::StyleModel do
|
4
|
+
subject do
|
5
|
+
described_class.new do
|
6
|
+
id 'Normal'
|
7
|
+
name 'normal'
|
8
|
+
font 'Arial'
|
9
|
+
size 20
|
10
|
+
line 360
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
#-------------------------------------------------------------
|
15
|
+
# Configuration
|
16
|
+
#-------------------------------------------------------------
|
17
|
+
|
18
|
+
describe 'configuration tests' do
|
19
|
+
|
20
|
+
# constants
|
21
|
+
describe 'constants' do
|
22
|
+
it { expect(described_class::DEFAULT_STYLE_COLOR).to eq '333333' }
|
23
|
+
it { expect(described_class::DEFAULT_STYLE_SIZE).to eq 20 }
|
24
|
+
it { expect(described_class::DEFAULT_STYLE_BOLD).to eq false }
|
25
|
+
it { expect(described_class::DEFAULT_STYLE_ITALIC).to eq false }
|
26
|
+
it { expect(described_class::DEFAULT_STYLE_UNDERLINE).to eq false }
|
27
|
+
it { expect(described_class::DEFAULT_STYLE_ALIGN).to eq :left }
|
28
|
+
it { expect(described_class::DEFAULT_STYLE_TOP).to eq 0 }
|
29
|
+
it { expect(described_class::DEFAULT_STYLE_BOTTOM).to eq 0 }
|
30
|
+
it { expect(described_class::DEFAULT_STYLE_LINE).to eq 360 }
|
31
|
+
it { expect(described_class::DEFAULT_STYLE_BASE).to eq 'Normal' }
|
32
|
+
it { expect(described_class::DEFAULT_STYLE_NEXT).to eq 'Normal' }
|
33
|
+
end
|
34
|
+
|
35
|
+
# accessors
|
36
|
+
describe 'accessors' do
|
37
|
+
it { expect(subject.style_default).to eq true }
|
38
|
+
it { expect(subject.style_id).to eq 'Normal' }
|
39
|
+
it { expect(subject.style_name).to eq 'normal' }
|
40
|
+
it { expect(subject.style_color).to eq '333333' }
|
41
|
+
it { expect(subject.style_font).to eq 'Arial' }
|
42
|
+
it { expect(subject.style_size).to eq 20 }
|
43
|
+
it { expect(subject.style_bold).to eq false }
|
44
|
+
it { expect(subject.style_italic).to eq false }
|
45
|
+
it { expect(subject.style_underline).to eq false }
|
46
|
+
it { expect(subject.style_align).to eq :left }
|
47
|
+
it { expect(subject.style_top).to eq 0 }
|
48
|
+
it { expect(subject.style_bottom).to eq 0 }
|
49
|
+
it { expect(subject.style_line).to eq 360 }
|
50
|
+
it { expect(subject.style_base).to eq 'Normal' }
|
51
|
+
it { expect(subject.style_next).to eq 'Normal' }
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
|
56
|
+
|
57
|
+
#-------------------------------------------------------------
|
58
|
+
# Public Methods
|
59
|
+
#-------------------------------------------------------------
|
60
|
+
|
61
|
+
describe 'public method tests' do
|
62
|
+
|
63
|
+
#=============== SETTERS ==========================
|
64
|
+
|
65
|
+
# booleans
|
66
|
+
describe '.bold' do
|
67
|
+
before { subject.bold(true) }
|
68
|
+
|
69
|
+
it { expect(subject.style_bold).to eq true }
|
70
|
+
end
|
71
|
+
describe '.italic' do
|
72
|
+
before { subject.italic(true) }
|
73
|
+
|
74
|
+
it { expect(subject.style_italic).to eq true }
|
75
|
+
end
|
76
|
+
describe '.underline' do
|
77
|
+
before { subject.underline(true) }
|
78
|
+
|
79
|
+
it { expect(subject.style_underline).to eq true }
|
80
|
+
end
|
81
|
+
|
82
|
+
# integers
|
83
|
+
describe '.bottom' do
|
84
|
+
before { subject.bottom(100) }
|
85
|
+
|
86
|
+
it { expect(subject.style_bottom).to eq 100 }
|
87
|
+
end
|
88
|
+
describe '.size' do
|
89
|
+
before { subject.size(24) }
|
90
|
+
|
91
|
+
it { expect(subject.style_size).to eq 24 }
|
92
|
+
end
|
93
|
+
describe '.line' do
|
94
|
+
before { subject.line(480) }
|
95
|
+
|
96
|
+
it { expect(subject.style_line).to eq 480 }
|
97
|
+
end
|
98
|
+
describe '.top' do
|
99
|
+
before { subject.top(100) }
|
100
|
+
|
101
|
+
it { expect(subject.style_top).to eq 100 }
|
102
|
+
end
|
103
|
+
|
104
|
+
# strings
|
105
|
+
describe '.id' do
|
106
|
+
before { subject.id('heading1') }
|
107
|
+
|
108
|
+
it { expect(subject.style_id).to eq 'heading1' }
|
109
|
+
end
|
110
|
+
describe '.name' do
|
111
|
+
before { subject.name('Heading 1') }
|
112
|
+
|
113
|
+
it { expect(subject.style_name).to eq 'Heading 1' }
|
114
|
+
end
|
115
|
+
describe '.color' do
|
116
|
+
before { subject.color('444444') }
|
117
|
+
|
118
|
+
it { expect(subject.style_color).to eq '444444' }
|
119
|
+
end
|
120
|
+
describe '.font' do
|
121
|
+
before { subject.font('Helvetica') }
|
122
|
+
|
123
|
+
it { expect(subject.style_font).to eq 'Helvetica' }
|
124
|
+
end
|
125
|
+
|
126
|
+
# symbols
|
127
|
+
describe '.align' do
|
128
|
+
before { subject.align(:right) }
|
129
|
+
|
130
|
+
it { expect(subject.style_align).to eq :right }
|
131
|
+
end
|
132
|
+
|
133
|
+
|
134
|
+
#=================== STATE ===============================
|
135
|
+
|
136
|
+
# .matches?
|
137
|
+
describe '.matches?' do
|
138
|
+
describe 'when search term matches' do
|
139
|
+
let(:actual) { subject.matches?('normal') }
|
140
|
+
|
141
|
+
it { expect(actual).to eq true }
|
142
|
+
end
|
143
|
+
describe 'when search term does not match' do
|
144
|
+
let(:actual) { subject.matches?('Dummy') }
|
145
|
+
|
146
|
+
it { expect(actual).to eq false }
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
|
151
|
+
#=============== VALIDATION ===========================
|
152
|
+
|
153
|
+
describe '.valid?' do
|
154
|
+
describe 'when type and id provided' do
|
155
|
+
it { expect(subject.valid?).to eq true }
|
156
|
+
end
|
157
|
+
[:id, :name].each do |prop|
|
158
|
+
describe "when #{ prop } nil" do
|
159
|
+
before do
|
160
|
+
allow(subject).to receive("style_#{ prop }").and_return(nil)
|
161
|
+
end
|
162
|
+
|
163
|
+
it { expect(subject.valid?).to eq false }
|
164
|
+
end
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
end
|
169
|
+
|
170
|
+
|
171
|
+
#-------------------------------------------------------------
|
172
|
+
# Private Methods
|
173
|
+
#-------------------------------------------------------------
|
174
|
+
|
175
|
+
describe 'private method tests' do
|
176
|
+
|
177
|
+
# .option_keys
|
178
|
+
describe '.option_keys' do
|
179
|
+
let(:actual) { subject.send(:option_keys).sort }
|
180
|
+
let(:expected) { [:bold, :italic, :underline, :top, :bottom, :size, :line, :id, :name, :color, :font, :align].sort }
|
181
|
+
|
182
|
+
it { expect(actual).to eq expected }
|
183
|
+
end
|
184
|
+
|
185
|
+
end
|
186
|
+
|
187
|
+
end
|
@@ -0,0 +1,221 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Caracal::Core::Models::TableCellModel do
|
4
|
+
subject do
|
5
|
+
described_class.new do
|
6
|
+
background 'cccccc'
|
7
|
+
margins do
|
8
|
+
top 101
|
9
|
+
bottom 102
|
10
|
+
left 103
|
11
|
+
right 104
|
12
|
+
end
|
13
|
+
width 2000
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
#-------------------------------------------------------------
|
18
|
+
# Configuration
|
19
|
+
#-------------------------------------------------------------
|
20
|
+
|
21
|
+
describe 'configuration tests' do
|
22
|
+
|
23
|
+
# constants
|
24
|
+
describe 'constants' do
|
25
|
+
it { expect(described_class::DEFAULT_CELL_BACKGROUND).to eq 'ffffff' }
|
26
|
+
it { expect(described_class::DEFAULT_CELL_MARGINS).to be_a(Caracal::Core::Models::MarginModel) }
|
27
|
+
it { expect(described_class::DEFAULT_CELL_MARGINS.margin_top).to eq 100 }
|
28
|
+
it { expect(described_class::DEFAULT_CELL_MARGINS.margin_bottom).to eq 100 }
|
29
|
+
it { expect(described_class::DEFAULT_CELL_MARGINS.margin_left).to eq 100 }
|
30
|
+
it { expect(described_class::DEFAULT_CELL_MARGINS.margin_right).to eq 100 }
|
31
|
+
end
|
32
|
+
|
33
|
+
# accessors
|
34
|
+
describe 'accessors' do
|
35
|
+
it { expect(subject.cell_background).to eq 'cccccc' }
|
36
|
+
it { expect(subject.cell_margins).to be_a(Caracal::Core::Models::MarginModel) }
|
37
|
+
it { expect(subject.cell_width).to eq 2000 }
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
|
42
|
+
|
43
|
+
#-------------------------------------------------------------
|
44
|
+
# Public Methods
|
45
|
+
#-------------------------------------------------------------
|
46
|
+
|
47
|
+
describe 'public method tests' do
|
48
|
+
|
49
|
+
#=============== DATA ACCESSORS ====================
|
50
|
+
|
51
|
+
describe 'data tests' do
|
52
|
+
|
53
|
+
# .contents
|
54
|
+
describe '.contents' do
|
55
|
+
it { expect(subject.contents).to be_a(Array) }
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
59
|
+
|
60
|
+
|
61
|
+
#=============== GETTERS ==========================
|
62
|
+
|
63
|
+
describe 'getter tests' do
|
64
|
+
|
65
|
+
# margin attrs
|
66
|
+
describe 'margin attr tests' do
|
67
|
+
let(:model) { Caracal::Core::Models::MarginModel.new({ top: 201, bottom: 202, left: 203, right: 204 }) }
|
68
|
+
|
69
|
+
before do
|
70
|
+
allow(subject).to receive(:cell_margins).and_return(model)
|
71
|
+
end
|
72
|
+
|
73
|
+
[:top, :bottom, :left, :right].each do |m|
|
74
|
+
describe "cell_margin_#{ m }" do
|
75
|
+
it { expect(subject.send("cell_margin_#{ m }")).to eq model.send("margin_#{ m }") }
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
end
|
81
|
+
|
82
|
+
|
83
|
+
#=============== SETTERS ==========================
|
84
|
+
|
85
|
+
# .background
|
86
|
+
describe '.background' do
|
87
|
+
before { subject.background('999999') }
|
88
|
+
|
89
|
+
it { expect(subject.cell_background).to eq '999999' }
|
90
|
+
end
|
91
|
+
|
92
|
+
# .width
|
93
|
+
describe '.width' do
|
94
|
+
before { subject.width(7500) }
|
95
|
+
|
96
|
+
it { expect(subject.cell_width).to eq 7500 }
|
97
|
+
end
|
98
|
+
|
99
|
+
|
100
|
+
#=============== CONTENT FNS =======================
|
101
|
+
|
102
|
+
describe 'content functions' do
|
103
|
+
|
104
|
+
# .br
|
105
|
+
describe '.br' do
|
106
|
+
let!(:size) { subject.contents.size }
|
107
|
+
|
108
|
+
before { subject.br }
|
109
|
+
|
110
|
+
it { expect(subject.contents.size).to eq size + 1 }
|
111
|
+
it { expect(subject.contents.last).to be_a(Caracal::Core::Models::LineBreakModel) }
|
112
|
+
end
|
113
|
+
|
114
|
+
# .img
|
115
|
+
describe '.img' do
|
116
|
+
let!(:size) { subject.contents.size }
|
117
|
+
|
118
|
+
before { subject.img 'https://www.google.com/images/srpr/logo11w.png', width: 538, height: 190 }
|
119
|
+
|
120
|
+
it { expect(subject.contents.size).to eq size + 1 }
|
121
|
+
it { expect(subject.contents.last).to be_a(Caracal::Core::Models::ImageModel) }
|
122
|
+
end
|
123
|
+
|
124
|
+
# .ol
|
125
|
+
describe '.ol' do
|
126
|
+
let!(:size) { subject.contents.size }
|
127
|
+
|
128
|
+
before do
|
129
|
+
subject.ol do
|
130
|
+
li 'Item 1'
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
it { expect(subject.contents.size).to eq size + 1 }
|
135
|
+
it { expect(subject.contents.last).to be_a(Caracal::Core::Models::ListModel) }
|
136
|
+
end
|
137
|
+
|
138
|
+
# .ul
|
139
|
+
describe '.ul' do
|
140
|
+
let!(:size) { subject.contents.size }
|
141
|
+
|
142
|
+
before do
|
143
|
+
subject.ul do
|
144
|
+
li 'Item 1'
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
it { expect(subject.contents.size).to eq size + 1 }
|
149
|
+
it { expect(subject.contents.last).to be_a(Caracal::Core::Models::ListModel) }
|
150
|
+
end
|
151
|
+
|
152
|
+
# .hr
|
153
|
+
describe '.hr' do
|
154
|
+
let!(:size) { subject.contents.size }
|
155
|
+
|
156
|
+
before { subject.hr }
|
157
|
+
|
158
|
+
it { expect(subject.contents.size).to eq size + 1 }
|
159
|
+
it { expect(subject.contents.last).to be_a(Caracal::Core::Models::RuleModel) }
|
160
|
+
end
|
161
|
+
|
162
|
+
# .table
|
163
|
+
describe '.table' do
|
164
|
+
let!(:size) { subject.contents.size }
|
165
|
+
|
166
|
+
before { subject.table [['Sample Text']] }
|
167
|
+
|
168
|
+
it { expect(subject.contents.size).to eq size + 1 }
|
169
|
+
it { expect(subject.contents.last).to be_a(Caracal::Core::Models::TableModel) }
|
170
|
+
end
|
171
|
+
|
172
|
+
# text
|
173
|
+
[:p, :h1, :h2, :h3, :h4, :h5, :h6].each do |cmd|
|
174
|
+
describe ".#{ cmd }" do
|
175
|
+
let!(:size) { subject.contents.size }
|
176
|
+
|
177
|
+
before { subject.send(cmd, 'Sample text.') }
|
178
|
+
|
179
|
+
it { expect(subject.contents.size).to eq size + 1 }
|
180
|
+
it { expect(subject.contents.last).to be_a(Caracal::Core::Models::ParagraphModel) }
|
181
|
+
end
|
182
|
+
end
|
183
|
+
|
184
|
+
end
|
185
|
+
|
186
|
+
|
187
|
+
#=============== VALIDATION ========================
|
188
|
+
|
189
|
+
describe '.valid?' do
|
190
|
+
describe 'when content provided' do
|
191
|
+
before { allow(subject).to receive(:contents).and_return(['a']) }
|
192
|
+
|
193
|
+
it { expect(subject.valid?).to eq true }
|
194
|
+
end
|
195
|
+
describe 'when content not provided' do
|
196
|
+
before { allow(subject).to receive(:contents).and_return([]) }
|
197
|
+
|
198
|
+
it { expect(subject.valid?).to eq false }
|
199
|
+
end
|
200
|
+
end
|
201
|
+
|
202
|
+
end
|
203
|
+
|
204
|
+
|
205
|
+
#-------------------------------------------------------------
|
206
|
+
# Private Methods
|
207
|
+
#-------------------------------------------------------------
|
208
|
+
|
209
|
+
describe 'private method tests' do
|
210
|
+
|
211
|
+
# .option_keys
|
212
|
+
describe '.option_keys' do
|
213
|
+
let(:actual) { subject.send(:option_keys).sort }
|
214
|
+
let(:expected) { [:background, :width, :margins].sort }
|
215
|
+
|
216
|
+
it { expect(actual).to eq expected }
|
217
|
+
end
|
218
|
+
|
219
|
+
end
|
220
|
+
|
221
|
+
end
|
@@ -0,0 +1,222 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Caracal::Core::Models::TableModel do
|
4
|
+
subject do
|
5
|
+
described_class.new do
|
6
|
+
data [ ['top lft', 'top right'], ['bottom left', 'bottom right'] ]
|
7
|
+
align :right
|
8
|
+
border_color '666666'
|
9
|
+
border_line :double
|
10
|
+
border_size 8
|
11
|
+
border_spacing 4
|
12
|
+
width 8000
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
#-------------------------------------------------------------
|
17
|
+
# Configuration
|
18
|
+
#-------------------------------------------------------------
|
19
|
+
|
20
|
+
describe 'configuration tests' do
|
21
|
+
|
22
|
+
# constants
|
23
|
+
describe 'constants' do
|
24
|
+
it { expect(described_class::DEFAULT_TABLE_ALIGN).to eq :center }
|
25
|
+
it { expect(described_class::DEFAULT_TABLE_BORDER_COLOR).to eq 'auto' }
|
26
|
+
it { expect(described_class::DEFAULT_TABLE_BORDER_LINE).to eq :single }
|
27
|
+
it { expect(described_class::DEFAULT_TABLE_BORDER_SIZE).to eq 0 }
|
28
|
+
it { expect(described_class::DEFAULT_TABLE_BORDER_SPACING).to eq 0 }
|
29
|
+
end
|
30
|
+
|
31
|
+
# accessors
|
32
|
+
describe 'accessors' do
|
33
|
+
it { expect(subject.table_align).to eq :right }
|
34
|
+
it { expect(subject.table_width).to eq 8000 }
|
35
|
+
it { expect(subject.table_border_color).to eq '666666' }
|
36
|
+
it { expect(subject.table_border_line).to eq :double }
|
37
|
+
it { expect(subject.table_border_size).to eq 8 }
|
38
|
+
it { expect(subject.table_border_spacing).to eq 4 }
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
|
43
|
+
|
44
|
+
#-------------------------------------------------------------
|
45
|
+
# Public Methods
|
46
|
+
#-------------------------------------------------------------
|
47
|
+
|
48
|
+
describe 'public method tests' do
|
49
|
+
|
50
|
+
#=============== DATA ACCESSORS ====================
|
51
|
+
|
52
|
+
describe 'data tests' do
|
53
|
+
let(:data) { [['top left', 'top right'], ['bottom left', 'bottom right']] }
|
54
|
+
|
55
|
+
before do
|
56
|
+
allow(subject).to receive(:rows).and_return(data)
|
57
|
+
end
|
58
|
+
|
59
|
+
# .rows
|
60
|
+
describe '.rows' do
|
61
|
+
it { expect(subject.rows[0]).to be_a(Array) }
|
62
|
+
it { expect(subject.rows[0][1]).to eq 'top right' }
|
63
|
+
end
|
64
|
+
|
65
|
+
# .cols
|
66
|
+
describe '.cols' do
|
67
|
+
it { expect(subject.cols[0]).to be_a(Array) }
|
68
|
+
it { expect(subject.cols[0][1]).to eq 'bottom left' }
|
69
|
+
end
|
70
|
+
|
71
|
+
# .cells
|
72
|
+
describe '.cells' do
|
73
|
+
it { expect(subject.cells[0]).to eq 'top left' }
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
|
78
|
+
#=============== GETTERS ==========================
|
79
|
+
|
80
|
+
describe 'getter tests' do
|
81
|
+
|
82
|
+
# border attrs
|
83
|
+
describe 'border attr tests' do
|
84
|
+
let(:model) { Caracal::Core::Models::BorderModel.new({ color: '000000', line: :double, size: 10, spacing: 2 }) }
|
85
|
+
|
86
|
+
before do
|
87
|
+
allow(subject).to receive(:table_border_color).and_return('auto')
|
88
|
+
allow(subject).to receive(:table_border_line).and_return(:single)
|
89
|
+
allow(subject).to receive(:table_border_size).and_return(8)
|
90
|
+
allow(subject).to receive(:table_border_spacing).and_return(1)
|
91
|
+
end
|
92
|
+
|
93
|
+
[:top, :bottom, :left, :right, :horizontal, :vertical].each do |m|
|
94
|
+
[:color, :line, :size, :spacing].each do |attr|
|
95
|
+
describe "table_border_#{ m }_#{ attr }" do
|
96
|
+
let(:actual) { subject.send("table_border_#{ m }_#{ attr }") }
|
97
|
+
|
98
|
+
describe 'when detailed setting present' do
|
99
|
+
before do
|
100
|
+
allow(subject).to receive("table_border_#{ m }").and_return(model)
|
101
|
+
end
|
102
|
+
|
103
|
+
it { expect(actual).to eq model.send("border_#{ attr }") }
|
104
|
+
end
|
105
|
+
describe 'when detailed setting not present' do
|
106
|
+
before do
|
107
|
+
allow(subject).to receive("table_border_#{ m }").and_return(nil)
|
108
|
+
end
|
109
|
+
|
110
|
+
it { expect(actual).to eq subject.send("table_border_#{ attr }") }
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
describe "table_border_#{ m }_total_size" do
|
115
|
+
let(:actual) { subject.send("table_border_#{ m }_total_size") }
|
116
|
+
|
117
|
+
describe 'when detailed setting present' do
|
118
|
+
before do
|
119
|
+
allow(subject).to receive("table_border_#{ m }").and_return(model)
|
120
|
+
end
|
121
|
+
|
122
|
+
it { expect(actual).to eq model.total_size }
|
123
|
+
end
|
124
|
+
describe 'when detailed setting not present' do
|
125
|
+
before do
|
126
|
+
allow(subject).to receive("table_border_#{ m }").and_return(nil)
|
127
|
+
end
|
128
|
+
|
129
|
+
it { expect(actual).to eq subject.send("table_border_#{ m }_total_size") }
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
end
|
136
|
+
|
137
|
+
|
138
|
+
#=============== SETTERS ==========================
|
139
|
+
|
140
|
+
# .align
|
141
|
+
describe '.align' do
|
142
|
+
before { subject.align(:center) }
|
143
|
+
|
144
|
+
it { expect(subject.table_align).to eq :center }
|
145
|
+
end
|
146
|
+
|
147
|
+
# .border_color
|
148
|
+
describe '.border_color' do
|
149
|
+
before { subject.border_color('999999') }
|
150
|
+
|
151
|
+
it { expect(subject.table_border_color).to eq '999999' }
|
152
|
+
end
|
153
|
+
|
154
|
+
# .border_line
|
155
|
+
describe '.border_line' do
|
156
|
+
before { subject.border_line(:none) }
|
157
|
+
|
158
|
+
it { expect(subject.table_border_line).to eq :none }
|
159
|
+
end
|
160
|
+
|
161
|
+
# .border_size
|
162
|
+
describe '.border_size' do
|
163
|
+
before { subject.border_size(24) }
|
164
|
+
|
165
|
+
it { expect(subject.table_border_size).to eq 24 }
|
166
|
+
end
|
167
|
+
|
168
|
+
# .border_spacing
|
169
|
+
describe '.border_spacing' do
|
170
|
+
before { subject.border_spacing(16) }
|
171
|
+
|
172
|
+
it { expect(subject.table_border_spacing).to eq 16 }
|
173
|
+
end
|
174
|
+
|
175
|
+
# .width
|
176
|
+
describe '.width' do
|
177
|
+
before { subject.width(7500) }
|
178
|
+
|
179
|
+
it { expect(subject.table_width).to eq 7500 }
|
180
|
+
end
|
181
|
+
|
182
|
+
|
183
|
+
|
184
|
+
|
185
|
+
#=============== VALIDATION ===========================
|
186
|
+
|
187
|
+
describe '.valid?' do
|
188
|
+
describe 'when data provided' do
|
189
|
+
it { expect(subject.valid?).to eq true }
|
190
|
+
end
|
191
|
+
describe 'when no data provided' do
|
192
|
+
before do
|
193
|
+
allow(subject).to receive(:cells).and_return([[]])
|
194
|
+
end
|
195
|
+
|
196
|
+
it { expect(subject.valid?).to eq false }
|
197
|
+
end
|
198
|
+
end
|
199
|
+
|
200
|
+
end
|
201
|
+
|
202
|
+
|
203
|
+
#-------------------------------------------------------------
|
204
|
+
# Private Methods
|
205
|
+
#-------------------------------------------------------------
|
206
|
+
|
207
|
+
describe 'private method tests' do
|
208
|
+
|
209
|
+
# .option_keys
|
210
|
+
describe '.option_keys' do
|
211
|
+
let(:actual) { subject.send(:option_keys).sort }
|
212
|
+
let(:expected1) { [:data, :align, :width] }
|
213
|
+
let(:expected2) { [:border_color, :border_line, :border_size, :border_spacing] }
|
214
|
+
let(:expected3) { [:border_top, :border_bottom, :border_left, :border_right, :border_horizontal, :border_vertical] }
|
215
|
+
let(:expected) { (expected1 + expected2 + expected3).sort }
|
216
|
+
|
217
|
+
it { expect(actual).to eq expected }
|
218
|
+
end
|
219
|
+
|
220
|
+
end
|
221
|
+
|
222
|
+
end
|