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,21 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Caracal::Core::Models::LineBreakModel do
|
4
|
+
let(:name) { 'Arial' }
|
5
|
+
|
6
|
+
subject { described_class.new }
|
7
|
+
|
8
|
+
|
9
|
+
#-------------------------------------------------------------
|
10
|
+
# Configuration
|
11
|
+
#-------------------------------------------------------------
|
12
|
+
|
13
|
+
describe 'configuration tests' do
|
14
|
+
|
15
|
+
describe 'inheritance' do
|
16
|
+
it { expect(subject).to be_a(Caracal::Core::Models::BaseModel) }
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
@@ -0,0 +1,139 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Caracal::Core::Models::LinkModel do
|
4
|
+
subject do
|
5
|
+
described_class.new do
|
6
|
+
content 'Link Text'
|
7
|
+
href 'http://www.google.com'
|
8
|
+
style 'Fancy'
|
9
|
+
color '666666'
|
10
|
+
size 20
|
11
|
+
bold false
|
12
|
+
italic false
|
13
|
+
underline true
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
#-------------------------------------------------------------
|
18
|
+
# Configuration
|
19
|
+
#-------------------------------------------------------------
|
20
|
+
|
21
|
+
describe 'configuration tests' do
|
22
|
+
|
23
|
+
# accessors
|
24
|
+
describe 'accessors' do
|
25
|
+
it { expect(subject.link_content).to eq 'Link Text' }
|
26
|
+
it { expect(subject.link_href).to eq 'http://www.google.com' }
|
27
|
+
it { expect(subject.link_style).to eq 'Fancy' }
|
28
|
+
it { expect(subject.link_color).to eq '666666' }
|
29
|
+
it { expect(subject.link_size).to eq 20 }
|
30
|
+
it { expect(subject.link_bold).to eq false }
|
31
|
+
it { expect(subject.link_italic).to eq false }
|
32
|
+
it { expect(subject.link_underline).to eq true }
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
|
38
|
+
#-------------------------------------------------------------
|
39
|
+
# Public Methods
|
40
|
+
#-------------------------------------------------------------
|
41
|
+
|
42
|
+
describe 'public method tests' do
|
43
|
+
|
44
|
+
#=============== GETTERS ==========================
|
45
|
+
|
46
|
+
# .run_attributes
|
47
|
+
describe '.run_attributes' do
|
48
|
+
let(:expected) { { style: 'Fancy', color: '666666', size: 20, bold: false, italic: false, underline: true } }
|
49
|
+
|
50
|
+
it { expect(subject.run_attributes).to eq expected }
|
51
|
+
end
|
52
|
+
|
53
|
+
|
54
|
+
#=============== SETTERS ==========================
|
55
|
+
|
56
|
+
# booleans
|
57
|
+
describe '.bold' do
|
58
|
+
before { subject.bold(true) }
|
59
|
+
|
60
|
+
it { expect(subject.link_bold).to eq true }
|
61
|
+
end
|
62
|
+
describe '.italic' do
|
63
|
+
before { subject.italic(true) }
|
64
|
+
|
65
|
+
it { expect(subject.link_italic).to eq true }
|
66
|
+
end
|
67
|
+
describe '.underline' do
|
68
|
+
before { subject.underline(true) }
|
69
|
+
|
70
|
+
it { expect(subject.link_underline).to eq true }
|
71
|
+
end
|
72
|
+
|
73
|
+
# integers
|
74
|
+
describe '.size' do
|
75
|
+
before { subject.size(24) }
|
76
|
+
|
77
|
+
it { expect(subject.link_size).to eq 24 }
|
78
|
+
end
|
79
|
+
|
80
|
+
# strings
|
81
|
+
describe '.color' do
|
82
|
+
before { subject.color('999999') }
|
83
|
+
|
84
|
+
it { expect(subject.link_color).to eq '999999' }
|
85
|
+
end
|
86
|
+
describe '.content' do
|
87
|
+
before { subject.content('Something Else') }
|
88
|
+
|
89
|
+
it { expect(subject.link_content).to eq 'Something Else' }
|
90
|
+
end
|
91
|
+
describe '.href' do
|
92
|
+
before { subject.href('http://www.google.com') }
|
93
|
+
|
94
|
+
it { expect(subject.link_href).to eq 'http://www.google.com' }
|
95
|
+
end
|
96
|
+
describe '.style' do
|
97
|
+
before { subject.style('Dummy') }
|
98
|
+
|
99
|
+
it { expect(subject.link_style).to eq 'Dummy' }
|
100
|
+
end
|
101
|
+
|
102
|
+
|
103
|
+
#=============== VALIDATION ===========================
|
104
|
+
|
105
|
+
describe '.valid?' do
|
106
|
+
describe 'when required attributes provided' do
|
107
|
+
it { expect(subject.valid?).to eq true }
|
108
|
+
end
|
109
|
+
[:content, :href].each do |prop|
|
110
|
+
describe "when #{ prop } nil" do
|
111
|
+
before do
|
112
|
+
allow(subject).to receive("link_#{ prop }").and_return(nil)
|
113
|
+
end
|
114
|
+
|
115
|
+
it { expect(subject.valid?).to eq false }
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
end
|
121
|
+
|
122
|
+
|
123
|
+
#-------------------------------------------------------------
|
124
|
+
# Private Methods
|
125
|
+
#-------------------------------------------------------------
|
126
|
+
|
127
|
+
describe 'private method tests' do
|
128
|
+
|
129
|
+
# .option_keys
|
130
|
+
describe '.option_keys' do
|
131
|
+
let(:actual) { subject.send(:option_keys).sort }
|
132
|
+
let(:expected) { [:content, :href, :style, :color, :size, :bold, :italic, :underline].sort }
|
133
|
+
|
134
|
+
it { expect(actual).to eq expected }
|
135
|
+
end
|
136
|
+
|
137
|
+
end
|
138
|
+
|
139
|
+
end
|
@@ -0,0 +1,190 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Caracal::Core::Models::ListItemModel do
|
4
|
+
subject do
|
5
|
+
described_class.new content: 'Lorem ipsum dolor....' do
|
6
|
+
type :ordered
|
7
|
+
level 2
|
8
|
+
style 'Fancy'
|
9
|
+
color '666666'
|
10
|
+
size 20
|
11
|
+
bold false
|
12
|
+
italic false
|
13
|
+
underline true
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
#-------------------------------------------------------------
|
18
|
+
# Configuration
|
19
|
+
#-------------------------------------------------------------
|
20
|
+
|
21
|
+
describe 'configuration tests' do
|
22
|
+
|
23
|
+
# accessors
|
24
|
+
describe 'accessors' do
|
25
|
+
it { expect(subject.respond_to? :nested_list).to eq true }
|
26
|
+
it { expect(subject.respond_to? :nested_list=).to eq true }
|
27
|
+
it { expect(subject.list_item_type).to eq :ordered }
|
28
|
+
it { expect(subject.list_item_level).to eq 2 }
|
29
|
+
it { expect(subject.list_item_style).to eq 'Fancy' }
|
30
|
+
it { expect(subject.list_item_color).to eq '666666' }
|
31
|
+
it { expect(subject.list_item_size).to eq 20 }
|
32
|
+
it { expect(subject.list_item_bold).to eq false }
|
33
|
+
it { expect(subject.list_item_italic).to eq false }
|
34
|
+
it { expect(subject.list_item_underline).to eq true }
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
|
39
|
+
|
40
|
+
#-------------------------------------------------------------
|
41
|
+
# Public Methods
|
42
|
+
#-------------------------------------------------------------
|
43
|
+
|
44
|
+
describe 'public method tests' do
|
45
|
+
|
46
|
+
#=============== GETTERS ==========================
|
47
|
+
|
48
|
+
# .runs
|
49
|
+
describe '.runs' do
|
50
|
+
it { expect(subject.runs).to be_a(Array) }
|
51
|
+
end
|
52
|
+
|
53
|
+
|
54
|
+
#=============== SETTERS ==========================
|
55
|
+
|
56
|
+
# booleans
|
57
|
+
describe '.bold' do
|
58
|
+
before { subject.bold(true) }
|
59
|
+
|
60
|
+
it { expect(subject.list_item_bold).to eq true }
|
61
|
+
end
|
62
|
+
describe '.italic' do
|
63
|
+
before { subject.italic(true) }
|
64
|
+
|
65
|
+
it { expect(subject.list_item_italic).to eq true }
|
66
|
+
end
|
67
|
+
describe '.underline' do
|
68
|
+
before { subject.underline(true) }
|
69
|
+
|
70
|
+
it { expect(subject.list_item_underline).to eq true }
|
71
|
+
end
|
72
|
+
|
73
|
+
# integers
|
74
|
+
describe '.level' do
|
75
|
+
before { subject.level(3) }
|
76
|
+
|
77
|
+
it { expect(subject.list_item_level).to eq 3 }
|
78
|
+
end
|
79
|
+
describe '.size' do
|
80
|
+
before { subject.size(24) }
|
81
|
+
|
82
|
+
it { expect(subject.list_item_size).to eq 24 }
|
83
|
+
end
|
84
|
+
|
85
|
+
# strings
|
86
|
+
describe '.color' do
|
87
|
+
before { subject.color('999999') }
|
88
|
+
|
89
|
+
it { expect(subject.list_item_color).to eq '999999' }
|
90
|
+
end
|
91
|
+
describe '.style' do
|
92
|
+
before { subject.style('Dummy') }
|
93
|
+
|
94
|
+
it { expect(subject.list_item_style).to eq 'Dummy' }
|
95
|
+
end
|
96
|
+
|
97
|
+
# symbols
|
98
|
+
describe '.type' do
|
99
|
+
before { subject.type(:ordered) }
|
100
|
+
|
101
|
+
it { expect(subject.list_item_type).to eq :ordered }
|
102
|
+
end
|
103
|
+
|
104
|
+
|
105
|
+
#=============== SUB-METHODS ==========================
|
106
|
+
|
107
|
+
# .link
|
108
|
+
describe '.link' do
|
109
|
+
let!(:length) { subject.runs.length }
|
110
|
+
|
111
|
+
before { subject.link 'Text', 'http://www.google.com' }
|
112
|
+
|
113
|
+
it { expect(subject.runs.size).to eq length + 1 }
|
114
|
+
end
|
115
|
+
|
116
|
+
# .text
|
117
|
+
describe '.text' do
|
118
|
+
let!(:length) { subject.runs.length }
|
119
|
+
|
120
|
+
before { subject.text 'Text' }
|
121
|
+
|
122
|
+
it { expect(subject.runs.size).to eq length + 1 }
|
123
|
+
end
|
124
|
+
|
125
|
+
# .ol
|
126
|
+
describe '.ol' do
|
127
|
+
describe 'when no nested list provided' do
|
128
|
+
subject do
|
129
|
+
described_class.new type: :ordered, level: 0 do
|
130
|
+
text 'Item text.'
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
it { expect(subject.nested_list).to eq nil }
|
135
|
+
end
|
136
|
+
describe 'when nested list provided' do
|
137
|
+
subject do
|
138
|
+
described_class.new type: :ordered, level: 0 do
|
139
|
+
text 'Item text.'
|
140
|
+
ol do
|
141
|
+
li 'Nested item text.'
|
142
|
+
end
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
it { expect(subject.nested_list).to be_a(Caracal::Core::Models::ListModel) }
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
|
151
|
+
|
152
|
+
#=============== VALIDATION ===========================
|
153
|
+
|
154
|
+
describe '.valid?' do
|
155
|
+
describe 'when at least one run exists' do
|
156
|
+
before do
|
157
|
+
allow(subject).to receive(:runs).and_return(['a'])
|
158
|
+
end
|
159
|
+
|
160
|
+
it { expect(subject.valid?).to eq true }
|
161
|
+
end
|
162
|
+
describe 'when no runs exist' do
|
163
|
+
before do
|
164
|
+
allow(subject).to receive(:runs).and_return([])
|
165
|
+
end
|
166
|
+
|
167
|
+
it { expect(subject.valid?).to eq false }
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
171
|
+
end
|
172
|
+
|
173
|
+
|
174
|
+
#-------------------------------------------------------------
|
175
|
+
# Private Methods
|
176
|
+
#-------------------------------------------------------------
|
177
|
+
|
178
|
+
describe 'private method tests' do
|
179
|
+
|
180
|
+
# .option_keys
|
181
|
+
describe '.option_keys' do
|
182
|
+
let(:actual) { subject.send(:option_keys).sort }
|
183
|
+
let(:expected) { [:type, :level, :content, :style, :color, :size, :bold, :italic, :underline].sort }
|
184
|
+
|
185
|
+
it { expect(actual).to eq expected }
|
186
|
+
end
|
187
|
+
|
188
|
+
end
|
189
|
+
|
190
|
+
end
|
@@ -0,0 +1,178 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Caracal::Core::Models::ListModel do
|
4
|
+
subject do
|
5
|
+
described_class.new do
|
6
|
+
type :ordered
|
7
|
+
level 1
|
8
|
+
li 'Item 1'
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
#-------------------------------------------------------------
|
13
|
+
# Configuration
|
14
|
+
#-------------------------------------------------------------
|
15
|
+
|
16
|
+
describe 'configuration tests' do
|
17
|
+
|
18
|
+
# constants
|
19
|
+
describe 'constants' do
|
20
|
+
it { expect(described_class::DEFAULT_LIST_TYPE).to eq :unordered }
|
21
|
+
it { expect(described_class::DEFAULT_LIST_LEVEL).to eq 0 }
|
22
|
+
end
|
23
|
+
|
24
|
+
# accessors
|
25
|
+
describe 'accessors' do
|
26
|
+
it { expect(subject.list_type).to eq :ordered }
|
27
|
+
it { expect(subject.list_level).to eq 1 }
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
|
33
|
+
#-------------------------------------------------------------
|
34
|
+
# Public Methods
|
35
|
+
#-------------------------------------------------------------
|
36
|
+
|
37
|
+
describe 'public method tests' do
|
38
|
+
|
39
|
+
#=============== GETTERS ==========================
|
40
|
+
|
41
|
+
# .items
|
42
|
+
describe '.items' do
|
43
|
+
it { expect(subject.items).to be_a(Array) }
|
44
|
+
end
|
45
|
+
|
46
|
+
# .recursive_items
|
47
|
+
describe '.recursive_items' do
|
48
|
+
describe 'when no nested lists provided' do
|
49
|
+
subject do
|
50
|
+
described_class.new type: :ordered, level: 0 do
|
51
|
+
li 'Item 1'
|
52
|
+
li 'Item 2'
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
it { expect(subject.recursive_items.size).to eq 2 }
|
57
|
+
it { expect(subject.recursive_items[0].list_item_level).to eq 0 }
|
58
|
+
end
|
59
|
+
describe 'when one nested list provided' do
|
60
|
+
subject do
|
61
|
+
described_class.new type: :ordered, level: 0 do
|
62
|
+
li 'Item 1'
|
63
|
+
li 'Item 2' do
|
64
|
+
ol do
|
65
|
+
li 'SubItem 1'
|
66
|
+
li 'SubItem 2'
|
67
|
+
end
|
68
|
+
end
|
69
|
+
li 'Item 3'
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
it { expect(subject.recursive_items.size).to eq 5 }
|
74
|
+
it { expect(subject.recursive_items[0].list_item_level).to eq 0 }
|
75
|
+
it { expect(subject.recursive_items[2].list_item_level).to eq 1 }
|
76
|
+
it { expect(subject.recursive_items[4].list_item_level).to eq 0 }
|
77
|
+
end
|
78
|
+
describe 'when more than one nested list provided' do
|
79
|
+
subject do
|
80
|
+
described_class.new type: :ordered, level: 0 do
|
81
|
+
li 'Item 1'
|
82
|
+
li 'Item 2' do
|
83
|
+
ol do
|
84
|
+
li 'SubItem 1' do
|
85
|
+
ul do
|
86
|
+
li 'NestedItem 1'
|
87
|
+
end
|
88
|
+
end
|
89
|
+
li 'SubItem 2'
|
90
|
+
end
|
91
|
+
end
|
92
|
+
li 'Item 3'
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
it { expect(subject.recursive_items.size).to eq 6 }
|
97
|
+
it { expect(subject.recursive_items[0].list_item_level).to eq 0 }
|
98
|
+
it { expect(subject.recursive_items[2].list_item_level).to eq 1 }
|
99
|
+
it { expect(subject.recursive_items[3].list_item_level).to eq 2 }
|
100
|
+
it { expect(subject.recursive_items[4].list_item_level).to eq 1 }
|
101
|
+
it { expect(subject.recursive_items[5].list_item_level).to eq 0 }
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
|
106
|
+
#=============== SETTERS ==========================
|
107
|
+
|
108
|
+
# .type
|
109
|
+
describe '.type' do
|
110
|
+
before { subject.type(:dummy) }
|
111
|
+
|
112
|
+
it { expect(subject.list_type).to eq :dummy }
|
113
|
+
end
|
114
|
+
|
115
|
+
# .level
|
116
|
+
describe '.level' do
|
117
|
+
before { subject.level(2) }
|
118
|
+
|
119
|
+
it { expect(subject.list_level).to eq 2 }
|
120
|
+
end
|
121
|
+
|
122
|
+
|
123
|
+
#=============== SUB-METHODS ==========================
|
124
|
+
|
125
|
+
# .li
|
126
|
+
describe '.li' do
|
127
|
+
let!(:length) { subject.items.length }
|
128
|
+
|
129
|
+
before { subject.li 'Text' }
|
130
|
+
|
131
|
+
it { expect(subject.items.size).to eq length + 1 }
|
132
|
+
end
|
133
|
+
|
134
|
+
|
135
|
+
#=============== VALIDATION ===========================
|
136
|
+
|
137
|
+
describe '.valid?' do
|
138
|
+
describe 'when all required attributes provides' do
|
139
|
+
it { expect(subject.valid?).to eq true }
|
140
|
+
end
|
141
|
+
[:type, :level].each do |attr|
|
142
|
+
describe "when #{ attr } nil" do
|
143
|
+
before do
|
144
|
+
allow(subject).to receive("list_#{ attr }").and_return(nil)
|
145
|
+
end
|
146
|
+
|
147
|
+
it { expect(subject.valid?).to eq false }
|
148
|
+
end
|
149
|
+
end
|
150
|
+
describe 'when items empty' do
|
151
|
+
before do
|
152
|
+
allow(subject).to receive(:items).and_return([])
|
153
|
+
end
|
154
|
+
|
155
|
+
it { expect(subject.valid?).to eq false }
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
159
|
+
end
|
160
|
+
|
161
|
+
|
162
|
+
#-------------------------------------------------------------
|
163
|
+
# Private Methods
|
164
|
+
#-------------------------------------------------------------
|
165
|
+
|
166
|
+
describe 'private method tests' do
|
167
|
+
|
168
|
+
# .option_keys
|
169
|
+
describe '.option_keys' do
|
170
|
+
let(:actual) { subject.send(:option_keys).sort }
|
171
|
+
let(:expected) { [:type, :level].sort }
|
172
|
+
|
173
|
+
it { expect(actual).to eq expected }
|
174
|
+
end
|
175
|
+
|
176
|
+
end
|
177
|
+
|
178
|
+
end
|