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,91 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Caracal::Core::Models::PageSizeModel do
|
4
|
+
subject do
|
5
|
+
described_class.new do
|
6
|
+
width 15840
|
7
|
+
height 12240
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
#-------------------------------------------------------------
|
12
|
+
# Configuration
|
13
|
+
#-------------------------------------------------------------
|
14
|
+
|
15
|
+
describe 'configuration tests' do
|
16
|
+
|
17
|
+
# constants
|
18
|
+
describe 'constants' do
|
19
|
+
it { expect(described_class::DEFAULT_PAGE_WIDTH).to eq 12240 }
|
20
|
+
it { expect(described_class::DEFAULT_PAGE_HEIGHT).to eq 15840 }
|
21
|
+
end
|
22
|
+
|
23
|
+
# accessors
|
24
|
+
describe 'accessors' do
|
25
|
+
it { expect(subject.page_width).to eq 15840 }
|
26
|
+
it { expect(subject.page_height).to eq 12240 }
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
|
32
|
+
#-------------------------------------------------------------
|
33
|
+
# Public Methods
|
34
|
+
#-------------------------------------------------------------
|
35
|
+
|
36
|
+
describe 'public method tests' do
|
37
|
+
|
38
|
+
#=============== SETTERS ==========================
|
39
|
+
|
40
|
+
# .width
|
41
|
+
describe '.width' do
|
42
|
+
before { subject.width(10000) }
|
43
|
+
|
44
|
+
it { expect(subject.page_width).to eq 10000 }
|
45
|
+
end
|
46
|
+
|
47
|
+
# .height
|
48
|
+
describe '.height' do
|
49
|
+
before { subject.height(10000) }
|
50
|
+
|
51
|
+
it { expect(subject.page_height).to eq 10000 }
|
52
|
+
end
|
53
|
+
|
54
|
+
|
55
|
+
#=============== VALIDATION ===========================
|
56
|
+
|
57
|
+
describe '.valid?' do
|
58
|
+
describe 'when all sizes gt 0' do
|
59
|
+
it { expect(subject.valid?).to eq true }
|
60
|
+
end
|
61
|
+
[:width, :height].each do |d|
|
62
|
+
describe "when #{ d } lte 0" do
|
63
|
+
before do
|
64
|
+
allow(subject).to receive("page_#{ d }").and_return(0)
|
65
|
+
end
|
66
|
+
|
67
|
+
it { expect(subject.valid?).to eq false }
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
end
|
73
|
+
|
74
|
+
|
75
|
+
#-------------------------------------------------------------
|
76
|
+
# Private Methods
|
77
|
+
#-------------------------------------------------------------
|
78
|
+
|
79
|
+
describe 'private method tests' do
|
80
|
+
|
81
|
+
# .option_keys
|
82
|
+
describe '.option_keys' do
|
83
|
+
let(:actual) { subject.send(:option_keys).sort }
|
84
|
+
let(:expected) { [:width, :height].sort }
|
85
|
+
|
86
|
+
it { expect(actual).to eq expected }
|
87
|
+
end
|
88
|
+
|
89
|
+
end
|
90
|
+
|
91
|
+
end
|
@@ -0,0 +1,162 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Caracal::Core::Models::ParagraphModel do
|
4
|
+
subject do
|
5
|
+
described_class.new content: 'Lorem ipsum dolor....' do
|
6
|
+
style 'Fancy'
|
7
|
+
align :right
|
8
|
+
color '666666'
|
9
|
+
size 20
|
10
|
+
bold false
|
11
|
+
italic false
|
12
|
+
underline true
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
#-------------------------------------------------------------
|
17
|
+
# Configuration
|
18
|
+
#-------------------------------------------------------------
|
19
|
+
|
20
|
+
describe 'configuration tests' do
|
21
|
+
|
22
|
+
# accessors
|
23
|
+
describe 'accessors' do
|
24
|
+
it { expect(subject.paragraph_style).to eq 'Fancy' }
|
25
|
+
it { expect(subject.paragraph_align).to eq :right }
|
26
|
+
it { expect(subject.paragraph_color).to eq '666666' }
|
27
|
+
it { expect(subject.paragraph_size).to eq 20 }
|
28
|
+
it { expect(subject.paragraph_bold).to eq false }
|
29
|
+
it { expect(subject.paragraph_italic).to eq false }
|
30
|
+
it { expect(subject.paragraph_underline).to eq true }
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
|
36
|
+
#-------------------------------------------------------------
|
37
|
+
# Public Methods
|
38
|
+
#-------------------------------------------------------------
|
39
|
+
|
40
|
+
describe 'public method tests' do
|
41
|
+
|
42
|
+
#=============== GETTERS ==========================
|
43
|
+
|
44
|
+
# .runs
|
45
|
+
describe '.runs' do
|
46
|
+
it { expect(subject.runs).to be_a(Array) }
|
47
|
+
end
|
48
|
+
|
49
|
+
# .run_attributes
|
50
|
+
describe '.run_attributes' do
|
51
|
+
let(:expected) { { color: '666666', size: 20, bold: false, italic: false, underline: true } }
|
52
|
+
|
53
|
+
it { expect(subject.run_attributes).to eq expected }
|
54
|
+
end
|
55
|
+
|
56
|
+
|
57
|
+
#=============== SETTERS ==========================
|
58
|
+
|
59
|
+
# booleans
|
60
|
+
describe '.bold' do
|
61
|
+
before { subject.bold(true) }
|
62
|
+
|
63
|
+
it { expect(subject.paragraph_bold).to eq true }
|
64
|
+
end
|
65
|
+
describe '.italic' do
|
66
|
+
before { subject.italic(true) }
|
67
|
+
|
68
|
+
it { expect(subject.paragraph_italic).to eq true }
|
69
|
+
end
|
70
|
+
describe '.underline' do
|
71
|
+
before { subject.underline(true) }
|
72
|
+
|
73
|
+
it { expect(subject.paragraph_underline).to eq true }
|
74
|
+
end
|
75
|
+
|
76
|
+
# integers
|
77
|
+
describe '.size' do
|
78
|
+
before { subject.size(24) }
|
79
|
+
|
80
|
+
it { expect(subject.paragraph_size).to eq 24 }
|
81
|
+
end
|
82
|
+
|
83
|
+
# strings
|
84
|
+
describe '.color' do
|
85
|
+
before { subject.color('999999') }
|
86
|
+
|
87
|
+
it { expect(subject.paragraph_color).to eq '999999' }
|
88
|
+
end
|
89
|
+
describe '.style' do
|
90
|
+
before { subject.style('Dummy') }
|
91
|
+
|
92
|
+
it { expect(subject.paragraph_style).to eq 'Dummy' }
|
93
|
+
end
|
94
|
+
|
95
|
+
# symbols
|
96
|
+
describe '.align' do
|
97
|
+
before { subject.align(:center) }
|
98
|
+
|
99
|
+
it { expect(subject.paragraph_align).to eq :center }
|
100
|
+
end
|
101
|
+
|
102
|
+
|
103
|
+
#=============== SUB-METHODS ==========================
|
104
|
+
|
105
|
+
# .link
|
106
|
+
describe '.link' do
|
107
|
+
let!(:length) { subject.runs.length }
|
108
|
+
|
109
|
+
before { subject.link 'Text', 'http://www.google.com' }
|
110
|
+
|
111
|
+
it { expect(subject.runs.size).to eq length + 1 }
|
112
|
+
end
|
113
|
+
|
114
|
+
# .text
|
115
|
+
describe '.text' do
|
116
|
+
let!(:length) { subject.runs.length }
|
117
|
+
|
118
|
+
before { subject.text 'Text' }
|
119
|
+
|
120
|
+
it { expect(subject.runs.size).to eq length + 1 }
|
121
|
+
end
|
122
|
+
|
123
|
+
|
124
|
+
#=============== VALIDATION ===========================
|
125
|
+
|
126
|
+
describe '.valid?' do
|
127
|
+
describe 'when at least one run exists' do
|
128
|
+
before do
|
129
|
+
allow(subject).to receive(:runs).and_return(['a'])
|
130
|
+
end
|
131
|
+
|
132
|
+
it { expect(subject.valid?).to eq true }
|
133
|
+
end
|
134
|
+
describe 'when no runs exist' do
|
135
|
+
before do
|
136
|
+
allow(subject).to receive(:runs).and_return([])
|
137
|
+
end
|
138
|
+
|
139
|
+
it { expect(subject.valid?).to eq false }
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
end
|
144
|
+
|
145
|
+
|
146
|
+
#-------------------------------------------------------------
|
147
|
+
# Private Methods
|
148
|
+
#-------------------------------------------------------------
|
149
|
+
|
150
|
+
describe 'private method tests' do
|
151
|
+
|
152
|
+
# .option_keys
|
153
|
+
describe '.option_keys' do
|
154
|
+
let(:actual) { subject.send(:option_keys).sort }
|
155
|
+
let(:expected) { [:content, :style, :align, :color, :size, :bold, :italic, :underline].sort }
|
156
|
+
|
157
|
+
it { expect(actual).to eq expected }
|
158
|
+
end
|
159
|
+
|
160
|
+
end
|
161
|
+
|
162
|
+
end
|
@@ -0,0 +1,183 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Caracal::Core::Models::RelationshipModel do
|
4
|
+
subject do
|
5
|
+
described_class.new do
|
6
|
+
id 3
|
7
|
+
target 'footer.xml'
|
8
|
+
type :footer
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
|
13
|
+
#-------------------------------------------------------------
|
14
|
+
# Configuration
|
15
|
+
#-------------------------------------------------------------
|
16
|
+
|
17
|
+
describe 'configuration tests' do
|
18
|
+
|
19
|
+
# constants
|
20
|
+
describe 'constants' do
|
21
|
+
describe 'TYPE_MAP' do
|
22
|
+
let(:keys) { described_class::TYPE_MAP.keys }
|
23
|
+
|
24
|
+
it { expect(keys.include?(:font)).to be true }
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
# accessors
|
29
|
+
describe 'accessors' do
|
30
|
+
it { expect(subject.relationship_id).to eq 3 }
|
31
|
+
it { expect(subject.relationship_type).to eq :footer }
|
32
|
+
it { expect(subject.relationship_target).to eq 'footer.xml' }
|
33
|
+
it { expect(subject.relationship_key).to eq 'footer.xml' }
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
|
38
|
+
|
39
|
+
#-------------------------------------------------------------
|
40
|
+
# Public Methods
|
41
|
+
#-------------------------------------------------------------
|
42
|
+
|
43
|
+
describe 'public method tests' do
|
44
|
+
|
45
|
+
#=================== ATTRIBUTES ==========================
|
46
|
+
|
47
|
+
# .id
|
48
|
+
describe '.id' do
|
49
|
+
before { subject.id(3) }
|
50
|
+
|
51
|
+
it { expect(subject.relationship_id).to eq 3 }
|
52
|
+
end
|
53
|
+
|
54
|
+
# .target
|
55
|
+
describe '.target' do
|
56
|
+
before do
|
57
|
+
subject.target('Dummy.XML')
|
58
|
+
end
|
59
|
+
|
60
|
+
it { expect(subject.relationship_target).to eq 'Dummy.XML' }
|
61
|
+
it { expect(subject.relationship_key).to eq 'dummy.xml' }
|
62
|
+
end
|
63
|
+
|
64
|
+
# .type
|
65
|
+
describe '.type' do
|
66
|
+
before do
|
67
|
+
subject.type('link')
|
68
|
+
end
|
69
|
+
|
70
|
+
it { expect(subject.relationship_type).to eq :link }
|
71
|
+
end
|
72
|
+
|
73
|
+
|
74
|
+
#=================== GETTERS =============================
|
75
|
+
|
76
|
+
# .formatted_id
|
77
|
+
describe '.formatted_id' do
|
78
|
+
before do
|
79
|
+
allow(subject).to receive(:relationship_id).and_return(1)
|
80
|
+
end
|
81
|
+
|
82
|
+
it { expect(subject.formatted_id).to eq 'rId1' }
|
83
|
+
end
|
84
|
+
|
85
|
+
# .formatted_target
|
86
|
+
describe '.formatted_target' do
|
87
|
+
describe 'when image' do
|
88
|
+
before do
|
89
|
+
allow(subject).to receive(:relationship_id).and_return(2)
|
90
|
+
allow(subject).to receive(:relationship_type).and_return(:image)
|
91
|
+
allow(subject).to receive(:relationship_target).and_return('https://www.google.com/images/srpr/logo11w.png')
|
92
|
+
end
|
93
|
+
|
94
|
+
it { expect(subject.formatted_target).to eq 'media/image2.png' }
|
95
|
+
end
|
96
|
+
describe 'when not image' do
|
97
|
+
before do
|
98
|
+
allow(subject).to receive(:relationship_type).and_return(:footer)
|
99
|
+
allow(subject).to receive(:relationship_target).and_return('footer.xml')
|
100
|
+
end
|
101
|
+
|
102
|
+
it { expect(subject.formatted_target).to eq 'footer.xml' }
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
# .formatted_type
|
107
|
+
describe '.formatted_type' do
|
108
|
+
it { expect(subject.formatted_type).to eq 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/footer' }
|
109
|
+
end
|
110
|
+
|
111
|
+
|
112
|
+
#=================== STATE ===============================
|
113
|
+
|
114
|
+
# .matches?
|
115
|
+
describe '.matches?' do
|
116
|
+
describe 'when search term matches key' do
|
117
|
+
let(:actual) { subject.matches?('footer.xml') }
|
118
|
+
|
119
|
+
it { expect(actual).to eq true }
|
120
|
+
end
|
121
|
+
describe 'when search term does not match key' do
|
122
|
+
let(:actual) { subject.matches?('dummy.xml') }
|
123
|
+
|
124
|
+
it { expect(actual).to eq false }
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
# .target_mode?
|
129
|
+
describe '.target_mode?' do
|
130
|
+
describe 'when key is link' do
|
131
|
+
before do
|
132
|
+
allow(subject).to receive(:relationship_type).and_return(:link)
|
133
|
+
end
|
134
|
+
|
135
|
+
it { expect(subject.target_mode?).to eq true }
|
136
|
+
end
|
137
|
+
describe 'when search term does not match key' do
|
138
|
+
before do
|
139
|
+
allow(subject).to receive(:relationship_type).and_return(:footer)
|
140
|
+
end
|
141
|
+
|
142
|
+
it { expect(subject.target_mode?).to eq false }
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
|
147
|
+
#=============== VALIDATION ===========================
|
148
|
+
|
149
|
+
describe '.valid?' do
|
150
|
+
describe 'when target and type provided' do
|
151
|
+
it { expect(subject.valid?).to eq true }
|
152
|
+
end
|
153
|
+
[:id, :target, :type].each do |prop|
|
154
|
+
describe "when #{ prop } nil" do
|
155
|
+
before do
|
156
|
+
allow(subject).to receive("relationship_#{ prop }").and_return(nil)
|
157
|
+
end
|
158
|
+
|
159
|
+
it { expect(subject.valid?).to eq false }
|
160
|
+
end
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
164
|
+
end
|
165
|
+
|
166
|
+
|
167
|
+
#-------------------------------------------------------------
|
168
|
+
# Private Methods
|
169
|
+
#-------------------------------------------------------------
|
170
|
+
|
171
|
+
describe 'private method tests' do
|
172
|
+
|
173
|
+
# .option_keys
|
174
|
+
describe '.option_keys' do
|
175
|
+
let(:actual) { subject.send(:option_keys).sort }
|
176
|
+
let(:expected) { [:id, :type, :target].sort }
|
177
|
+
|
178
|
+
it { expect(actual).to eq expected }
|
179
|
+
end
|
180
|
+
|
181
|
+
end
|
182
|
+
|
183
|
+
end
|
@@ -0,0 +1,108 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Caracal::Core::Models::RuleModel do
|
4
|
+
subject do
|
5
|
+
described_class.new do
|
6
|
+
color '666666'
|
7
|
+
size 8
|
8
|
+
spacing 2
|
9
|
+
line :double
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
#-------------------------------------------------------------
|
14
|
+
# Configuration
|
15
|
+
#-------------------------------------------------------------
|
16
|
+
|
17
|
+
describe 'configuration tests' do
|
18
|
+
|
19
|
+
# constants
|
20
|
+
describe 'inheritance' do
|
21
|
+
it { expect(subject).to be_a(Caracal::Core::Models::BorderModel) }
|
22
|
+
end
|
23
|
+
|
24
|
+
# accessors
|
25
|
+
describe 'accessors' do
|
26
|
+
it { expect(subject.rule_color).to eq '666666' }
|
27
|
+
it { expect(subject.rule_size).to eq 8 }
|
28
|
+
it { expect(subject.rule_spacing).to eq 2 }
|
29
|
+
it { expect(subject.rule_line).to eq :double }
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
|
35
|
+
#-------------------------------------------------------------
|
36
|
+
# Public Methods
|
37
|
+
#-------------------------------------------------------------
|
38
|
+
|
39
|
+
describe 'public method tests' do
|
40
|
+
|
41
|
+
#=============== SETTERS ==========================
|
42
|
+
|
43
|
+
# .color
|
44
|
+
describe '.color' do
|
45
|
+
before { subject.color('999999') }
|
46
|
+
|
47
|
+
it { expect(subject.rule_color).to eq '999999' }
|
48
|
+
end
|
49
|
+
|
50
|
+
# .line
|
51
|
+
describe '.line' do
|
52
|
+
before { subject.line(:single) }
|
53
|
+
|
54
|
+
it { expect(subject.rule_line).to eq :single }
|
55
|
+
end
|
56
|
+
|
57
|
+
# .size
|
58
|
+
describe '.size' do
|
59
|
+
before { subject.size(24) }
|
60
|
+
|
61
|
+
it { expect(subject.rule_size).to eq 24 }
|
62
|
+
end
|
63
|
+
|
64
|
+
# .spacing
|
65
|
+
describe '.spacing' do
|
66
|
+
before { subject.spacing(8) }
|
67
|
+
|
68
|
+
it { expect(subject.rule_spacing).to eq 8 }
|
69
|
+
end
|
70
|
+
|
71
|
+
|
72
|
+
#=============== VALIDATION ===========================
|
73
|
+
|
74
|
+
describe '.valid?' do
|
75
|
+
describe 'when all integers gt 0' do
|
76
|
+
it { expect(subject.valid?).to eq true }
|
77
|
+
end
|
78
|
+
[:size, :spacing].each do |d|
|
79
|
+
describe "when #{ d } lte 0" do
|
80
|
+
before do
|
81
|
+
allow(subject).to receive("border_#{ d }").and_return(0)
|
82
|
+
end
|
83
|
+
|
84
|
+
it { expect(subject.valid?).to eq false }
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
end
|
90
|
+
|
91
|
+
|
92
|
+
#-------------------------------------------------------------
|
93
|
+
# Private Methods
|
94
|
+
#-------------------------------------------------------------
|
95
|
+
|
96
|
+
describe 'private method tests' do
|
97
|
+
|
98
|
+
# .option_keys
|
99
|
+
describe '.option_keys' do
|
100
|
+
let(:actual) { subject.send(:option_keys).sort }
|
101
|
+
let(:expected) { [:color, :size, :spacing, :line, :type].sort }
|
102
|
+
|
103
|
+
it { expect(actual).to eq expected }
|
104
|
+
end
|
105
|
+
|
106
|
+
end
|
107
|
+
|
108
|
+
end
|