-
Notifications
You must be signed in to change notification settings - Fork 44
/
exceptions_test.rb
187 lines (146 loc) · 4.82 KB
/
exceptions_test.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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
require 'test_helper'
class ExceptionsTest < ActiveSupport::TestCase
test "ArgumentError" do
error = SpreadsheetArchitect::Exceptions::ArgumentError
assert_raise error do
conditional_row_styles = [{}]
SpreadsheetArchitect::Utils::XLSX.conditional_styles_for_row(conditional_row_styles, true, true)
end
assert_raise error do
conditional_row_styles = [{if: true, unless: true, styles: {}}]
SpreadsheetArchitect::Utils::XLSX.conditional_styles_for_row(conditional_row_styles, true, true)
end
assert_raise error do
conditional_row_styles = [{if: true, styles: false}]
SpreadsheetArchitect::Utils::XLSX.conditional_styles_for_row(conditional_row_styles, true, true)
end
assert_raise error do
SpreadsheetArchitect::Utils.get_options({freeze: {rows: 1}, freeze_headers: true}, SpreadsheetArchitect)
end
end
test "NoDataError" do
error = SpreadsheetArchitect::Exceptions::NoDataError
assert error.new
assert_raise error do
SpreadsheetArchitect.to_csv(foo: :bar)
end
end
test "MultipleDataSourcesError" do
error = SpreadsheetArchitect::Exceptions::MultipleDataSourcesError
assert error.new
assert_raise error do
SpreadsheetArchitect.to_csv(data: [], instances: [])
end
end
test "OptionTypeError" do
error = SpreadsheetArchitect::Exceptions::OptionTypeError
assert error.new(:foobar_option).message
assert_raise error do
SpreadsheetArchitect.to_csv(data: {})
end
assert_raise error do
SpreadsheetArchitect.to_csv(instances: :foo)
end
assert_raise error do
SpreadsheetArchitect.to_csv(headers: :foo)
end
assert_raise error do
SpreadsheetArchitect.to_csv(header_style: :foo)
end
assert_raise error do
SpreadsheetArchitect.to_csv(row_style: :foo)
end
assert_raise error do
SpreadsheetArchitect.to_csv(column_styles: :foo)
end
assert_raise error do
SpreadsheetArchitect.to_csv(range_styles: :foo)
end
assert_raise error do
SpreadsheetArchitect.to_csv(merges: :foo)
end
assert_raise error do
SpreadsheetArchitect.to_csv(borders: :foo)
end
assert_raise error do
SpreadsheetArchitect.to_csv(column_widths: :foo)
end
end
test "SpreadsheetColumnsNotDefinedError" do
error = SpreadsheetArchitect::Exceptions::SpreadsheetColumnsNotDefinedError
assert_raise ArgumentError do
error.new
end
assert error.new(SpreadsheetArchitect)
class QuickBadClass
include SpreadsheetArchitect
end
assert_raise error do
QuickBadClass.to_csv(instances: [])
end
end
test "InvalidColumnError" do
error = SpreadsheetArchitect::Exceptions::InvalidColumnError
assert_raise ArgumentError do
error.new
end
assert error.new(:foobar_column)
assert_raise error do
SpreadsheetArchitect.to_xlsx(data: [[1]], column_styles: [{columns: 999}])
end
assert_raise error do
SpreadsheetArchitect.to_xlsx(data: [[1]], column_styles: [{columns: 'ZZZ'}])
end
assert_raise error do
SpreadsheetArchitect.to_xlsx(data: [[1]], column_styles: [{columns: [999]}])
end
assert_raise error do
SpreadsheetArchitect.to_xlsx(data: [[1]], column_styles: [{columns: ('ZZX'..'ZZZ')}])
end
end
test "InvalidRangeStylesOptionError" do
error = SpreadsheetArchitect::Exceptions::InvalidRangeStylesOptionError
assert_raise ArgumentError do
error.new
end
assert error.new(:columns, :bar_opt)
assert error.new(:row, :bar_opt)
assert error.new(:foo, :bar_opt)
assert_raise error do
SpreadsheetArchitect::Utils::XLSX.range_hash_to_str({columns: :foo}, 1, 1)
end
assert_raise error do
SpreadsheetArchitect::Utils::XLSX.range_hash_to_str({rows: :foo}, 1, 1)
end
end
test "InvalidRangeError" do
error = SpreadsheetArchitect::Exceptions::InvalidRangeError
assert_raise ArgumentError do
error.new
end
errors = []
errors.push error.new(:foo_type, :bar_opt)
errors.push error.new(:columns, :bar_opt)
errors.push error.new(:rows, :bar_opt)
errors.push error.new(:format, :bar_opt)
errors.push error.new(:type, :bar_opt)
errors.push error.new(:foo_type, :bar_opt)
assert_equal errors.count, errors.uniq.count
assert error.new(:foo_type, :bar_opt)
assert_raise error do
SpreadsheetArchitect::Utils::XLSX.verify_range(:foo, 1)
end
assert_raise error do
SpreadsheetArchitect::Utils::XLSX.verify_range("foo", 1)
end
assert_raise error do
SpreadsheetArchitect::Utils::XLSX.verify_range("foo:foo", 1)
end
assert_raise error do
SpreadsheetArchitect::Utils::XLSX.verify_range("A1:A2", 1)
end
assert_raise error do
SpreadsheetArchitect::Utils::XLSX.verify_range("@1:A2", 1)
end
end
end