spreadbase 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +3 -2
- data/.rspec +1 -0
- data/.travis.yml +7 -0
- data/Gemfile +3 -0
- data/LICENSE +674 -0
- data/README.md +12 -17
- data/Rakefile +5 -0
- data/docs/STRUCTURE.md +3 -0
- data/docs/TESTING.md +11 -0
- data/lib/spreadbase/cell.rb +19 -0
- data/lib/spreadbase/codecs/open_document_12.rb +19 -41
- data/lib/spreadbase/codecs/open_document_12_modules/decoding.rb +72 -92
- data/lib/spreadbase/codecs/open_document_12_modules/encoding.rb +43 -72
- data/lib/spreadbase/document.rb +12 -33
- data/lib/spreadbase/helpers/helpers.rb +27 -61
- data/lib/spreadbase/table.rb +120 -86
- data/lib/spreadbase/version.rb +1 -3
- data/lib/spreadbase.rb +7 -28
- data/spec/codecs/open_document_12_spec.rb +42 -64
- data/spec/elements/document_spec.rb +33 -55
- data/spec/elements/table_spec.rb +186 -174
- data/spec/spec_helper.rb +100 -0
- data/spec/spec_helpers.rb +10 -30
- data/spreadbase.gemspec +14 -9
- data/utils/convert_sqlite_to_ods.rb +30 -49
- data/utils/test_ods_folder.rb +7 -26
- data/utils/test_recoding_file.rb +11 -27
- data/utils/test_recoding_from_content.rb +10 -29
- data/utils/utils_helpers.rb +19 -33
- metadata +41 -26
- data/COPYING.LESSER +0 -165
- data/utils/prettify_file.rb +0 -46
data/spec/elements/table_spec.rb
CHANGED
@@ -1,36 +1,18 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
=begin
|
4
|
-
Copyright 2012 Saverio Miroddi saverio.pub2 <a-hat!> gmail.com
|
5
|
-
|
6
|
-
This file is part of SpreadBase.
|
7
|
-
|
8
|
-
SpreadBase is free software: you can redistribute it and/or modify it under the
|
9
|
-
terms of the GNU Lesser General Public License as published by the Free Software
|
10
|
-
Foundation, either version 3 of the License, or (at your option) any later
|
11
|
-
version.
|
12
|
-
|
13
|
-
SpreadBase is distributed in the hope that it will be useful, but WITHOUT ANY
|
14
|
-
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
15
|
-
PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
16
|
-
|
17
|
-
You should have received a copy of the GNU Lesser General Public License along
|
18
|
-
with SpreadBase. If not, see <http://www.gnu.org/licenses/>.
|
19
|
-
=end
|
20
|
-
|
21
|
-
require File.expand_path( '../../../lib/spreadbase', __FILE__ )
|
22
|
-
require File.expand_path( '../../spec_helpers', __FILE__ )
|
1
|
+
require_relative '../../lib/spreadbase'
|
2
|
+
require_relative '../spec_helpers'
|
23
3
|
|
24
4
|
include SpecHelpers
|
25
5
|
|
6
|
+
include SpreadBase
|
7
|
+
|
26
8
|
describe SpreadBase::Table do
|
27
9
|
|
28
10
|
before :each do
|
29
11
|
@sample_table = SpreadBase::Table.new(
|
30
12
|
'abc', [
|
31
|
-
[
|
32
|
-
[
|
33
|
-
[
|
13
|
+
[1, 1.1, T_BIGDECIMAL],
|
14
|
+
[T_DATE, T_DATETIME, T_TIME],
|
15
|
+
[true, Cell.new('a'), nil]
|
34
16
|
]
|
35
17
|
)
|
36
18
|
end
|
@@ -39,111 +21,133 @@ describe SpreadBase::Table do
|
|
39
21
|
# this routine is called, by checking against the index (-1).
|
40
22
|
#
|
41
23
|
it "should check the row index" do
|
42
|
-
|
24
|
+
expect { @sample_table.row(4) }.to raise_error(RuntimeError, "Invalid row index (4) - allowed 0 to 2")
|
43
25
|
|
44
26
|
# called with :allow_append
|
45
|
-
|
46
|
-
|
27
|
+
expect { @sample_table.insert_row(-1, []) }.to raise_error(RuntimeError, "Invalid row index (-1) - allowed 0 to 3")
|
28
|
+
expect { @sample_table.insert_row(40, []) }.to raise_error(RuntimeError, "Invalid row index (40) - allowed 0 to 3")
|
47
29
|
end
|
48
30
|
|
49
|
-
it "should initialize with data" do
|
31
|
+
it "should initialize with data, and return the data" do
|
50
32
|
expected_data = [
|
51
|
-
[
|
52
|
-
[
|
53
|
-
[
|
33
|
+
[1, 1.1, T_BIGDECIMAL],
|
34
|
+
[T_DATE, T_DATETIME, T_TIME],
|
35
|
+
[true, 'a', nil]
|
54
36
|
]
|
55
37
|
|
56
|
-
@sample_table.data.
|
38
|
+
expect(@sample_table.data).to eq(expected_data)
|
39
|
+
end
|
40
|
+
|
41
|
+
it "return the data in cell format" do
|
42
|
+
expected_data = [
|
43
|
+
[Cell.new(1), Cell.new(1.1), Cell.new(T_BIGDECIMAL)],
|
44
|
+
[Cell.new(T_DATE), Cell.new(T_DATETIME), Cell.new(T_TIME)],
|
45
|
+
[Cell.new(true), Cell.new('a'), Cell.new(nil)]
|
46
|
+
]
|
47
|
+
|
48
|
+
expect(@sample_table.data(as_cell: true)).to eq(expected_data)
|
57
49
|
end
|
58
50
|
|
59
51
|
it "should raise an error when the initialization requirements are not met" do
|
60
|
-
|
61
|
-
|
52
|
+
expect { SpreadBase::Table.new(nil) }.to raise_error("Table name required")
|
53
|
+
expect { SpreadBase::Table.new('') }.to raise_error("Table name required")
|
62
54
|
|
63
55
|
# This is acceptable
|
64
56
|
#
|
65
|
-
SpreadBase::Table.new(
|
57
|
+
SpreadBase::Table.new(' ')
|
66
58
|
end
|
67
59
|
|
68
60
|
it "should access a cell" do
|
69
|
-
@sample_table[
|
70
|
-
@sample_table[
|
71
|
-
@sample_table[
|
72
|
-
@sample_table[
|
73
|
-
@sample_table[
|
74
|
-
@sample_table[
|
75
|
-
@sample_table[
|
76
|
-
@sample_table[
|
77
|
-
@sample_table[
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
61
|
+
expect(@sample_table['a', 0]).to eq(1)
|
62
|
+
expect(@sample_table[1, 0]).to eq(1.1)
|
63
|
+
expect(@sample_table[2, 0]).to eq(T_BIGDECIMAL)
|
64
|
+
expect(@sample_table[0, 1]).to eq(T_DATE)
|
65
|
+
expect(@sample_table['B', 1]).to eq(T_DATETIME)
|
66
|
+
expect(@sample_table[2, 1]).to eq(T_TIME)
|
67
|
+
expect(@sample_table[0, 2]).to eq(true)
|
68
|
+
expect(@sample_table[1, 2]).to eq('a')
|
69
|
+
expect(@sample_table[2, 2]).to eq(nil)
|
70
|
+
|
71
|
+
expect(@sample_table[1, 2, as_cell: true]).to eq(Cell.new('a'))
|
72
|
+
|
73
|
+
expect { @sample_table[-1, 0] }.to raise_error(RuntimeError, "Negative column indexes not allowed: -1")
|
74
|
+
expect { @sample_table[0, -1] }.to raise_error(RuntimeError, "Invalid row index (-1) - allowed 0 to 2")
|
75
|
+
expect { @sample_table[3, 0] }.to raise_error(RuntimeError, "Invalid column index (3) for the given row - allowed 0 to 2")
|
82
76
|
end
|
83
77
|
|
84
78
|
it "should set a cell value" do
|
85
|
-
@sample_table[
|
86
|
-
@sample_table[
|
79
|
+
@sample_table[0, 0] = 10
|
80
|
+
@sample_table['B', 1] = Cell.new(T_TIME)
|
87
81
|
|
88
|
-
@sample_table.data.
|
89
|
-
[
|
90
|
-
[
|
91
|
-
[
|
92
|
-
]
|
82
|
+
expect(@sample_table.data).to eq([
|
83
|
+
[10, 1.1, T_BIGDECIMAL],
|
84
|
+
[T_DATE, T_TIME, T_TIME],
|
85
|
+
[true, 'a', nil],
|
86
|
+
])
|
93
87
|
|
94
|
-
|
95
|
-
|
88
|
+
expect { @sample_table[0, -1] = 33 }.to raise_error(RuntimeError, "Invalid row index (-1) - allowed 0 to 2")
|
89
|
+
expect { @sample_table[3, 0] = 44 }.to raise_error(RuntimeError, "Invalid column index (3) for the given row - allowed 0 to 2")
|
96
90
|
end
|
97
91
|
|
98
92
|
it "should access a row" do
|
99
|
-
@sample_table.row(
|
100
|
-
@sample_table.row( 1 ).should == [ T_DATE, T_DATETIME, T_TIME ]
|
93
|
+
expect(@sample_table.row(0)).to eq([1, 1.1, T_BIGDECIMAL])
|
101
94
|
|
102
|
-
|
95
|
+
expect(@sample_table.row(1, as_cell: true)).to eq([Cell.new(T_DATE), Cell.new(T_DATETIME), Cell.new(T_TIME)])
|
96
|
+
|
97
|
+
expect { @sample_table.row(-1) }.to raise_error(RuntimeError, "Invalid row index (-1) - allowed 0 to 2")
|
103
98
|
end
|
104
99
|
|
105
100
|
it "should access a set of rows by range" do
|
106
|
-
@sample_table.row(
|
107
|
-
[
|
108
|
-
[
|
109
|
-
]
|
101
|
+
expect(@sample_table.row(0..1)).to eq([
|
102
|
+
[1, 1.1, T_BIGDECIMAL],
|
103
|
+
[T_DATE, T_DATETIME, T_TIME],
|
104
|
+
])
|
110
105
|
|
111
|
-
|
106
|
+
expect { @sample_table.row(0..5) }.to raise_error(RuntimeError, "Invalid row index (5) - allowed 0 to 2")
|
107
|
+
end
|
108
|
+
|
109
|
+
it "should access a set of rows by range (as cell)" do
|
110
|
+
expect(@sample_table.row(0..1, as_cell: true)).to eq([
|
111
|
+
[Cell.new(1), Cell.new(1.1), Cell.new(T_BIGDECIMAL)],
|
112
|
+
[Cell.new(T_DATE), Cell.new(T_DATETIME), Cell.new(T_TIME)],
|
113
|
+
])
|
114
|
+
|
115
|
+
expect { @sample_table.row(0..5) }.to raise_error(RuntimeError, "Invalid row index (5) - allowed 0 to 2")
|
112
116
|
end
|
113
117
|
|
114
118
|
it "should delete a row" do
|
115
|
-
@sample_table.delete_row(
|
119
|
+
expect(@sample_table.delete_row(1)).to eq([T_DATE, T_DATETIME, T_TIME])
|
116
120
|
|
117
|
-
@sample_table.data.
|
118
|
-
[
|
119
|
-
[
|
120
|
-
]
|
121
|
+
expect(@sample_table.data).to eq([
|
122
|
+
[1, 1.1, T_BIGDECIMAL],
|
123
|
+
[true, 'a', nil],
|
124
|
+
])
|
121
125
|
|
122
|
-
|
126
|
+
expect { @sample_table.delete_row(-1) }.to raise_error(RuntimeError, "Invalid row index (-1) - allowed 0 to 1")
|
123
127
|
end
|
124
128
|
|
125
129
|
it "should delete a set of rows by range" do
|
126
|
-
@sample_table.delete_row(
|
127
|
-
[
|
128
|
-
[
|
129
|
-
]
|
130
|
+
expect(@sample_table.delete_row(0..1)).to eq([
|
131
|
+
[1, 1.1, T_BIGDECIMAL],
|
132
|
+
[T_DATE, T_DATETIME, T_TIME],
|
133
|
+
])
|
130
134
|
|
131
|
-
@sample_table.data.
|
132
|
-
[
|
133
|
-
]
|
135
|
+
expect(@sample_table.data).to eq([
|
136
|
+
[true, 'a', nil]
|
137
|
+
])
|
134
138
|
|
135
|
-
|
139
|
+
expect { @sample_table.delete_row(0..5) }.to raise_error(RuntimeError, "Invalid row index (5) - allowed 0 to 0")
|
136
140
|
end
|
137
141
|
|
138
142
|
it "should insert a row" do
|
139
|
-
@sample_table.insert_row(
|
143
|
+
@sample_table.insert_row(1, [4, Cell.new(5), 6])
|
140
144
|
|
141
|
-
@sample_table.data.
|
142
|
-
[
|
143
|
-
[
|
144
|
-
[
|
145
|
-
[
|
146
|
-
]
|
145
|
+
expect(@sample_table.data).to eq([
|
146
|
+
[1, 1.1, T_BIGDECIMAL],
|
147
|
+
[4, 5, 6],
|
148
|
+
[T_DATE, T_DATETIME, T_TIME],
|
149
|
+
[true, 'a', nil],
|
150
|
+
])
|
147
151
|
|
148
152
|
# illegal row index tested in separate UT
|
149
153
|
end
|
@@ -151,164 +155,172 @@ describe SpreadBase::Table do
|
|
151
155
|
it "should insert a row without error if there is no data" do
|
152
156
|
@sample_table.data = []
|
153
157
|
|
154
|
-
@sample_table.insert_row(
|
158
|
+
@sample_table.insert_row(0, [4, 5])
|
155
159
|
|
156
|
-
@sample_table.data.size.
|
160
|
+
expect(@sample_table.data.size).to eq(1)
|
157
161
|
end
|
158
162
|
|
159
163
|
it "should append a row" do
|
160
|
-
@sample_table.append_row(
|
161
|
-
|
162
|
-
@sample_table.data.
|
163
|
-
[
|
164
|
-
[
|
165
|
-
[
|
166
|
-
[
|
167
|
-
]
|
164
|
+
@sample_table.append_row([4, Cell.new(5), 6])
|
165
|
+
|
166
|
+
expect(@sample_table.data).to eq([
|
167
|
+
[1, 1.1, T_BIGDECIMAL],
|
168
|
+
[T_DATE, T_DATETIME, T_TIME],
|
169
|
+
[true, 'a', nil],
|
170
|
+
[4, 5, 6],
|
171
|
+
])
|
168
172
|
end
|
169
173
|
|
170
174
|
it "should access a column" do
|
171
|
-
@sample_table.column(
|
172
|
-
@sample_table.column( 1 ).should == [ 1.1, T_DATETIME, 'a' ]
|
175
|
+
expect(@sample_table.column(0)).to eq([1, T_DATE, true])
|
173
176
|
|
174
|
-
@sample_table.column(
|
177
|
+
expect(@sample_table.column(1, as_cell: true)).to eq([Cell.new(1.1), Cell.new(T_DATETIME), Cell.new('a')])
|
178
|
+
|
179
|
+
expect(@sample_table.column(3)).to eq([nil, nil, nil])
|
175
180
|
end
|
176
181
|
|
177
182
|
it "should access a set of columns by range" do
|
178
|
-
@sample_table.column(
|
179
|
-
[
|
180
|
-
[
|
181
|
-
]
|
183
|
+
expect(@sample_table.column(0..1)).to eq([
|
184
|
+
[1, T_DATE, true],
|
185
|
+
[1.1, T_DATETIME, 'a'],
|
186
|
+
])
|
187
|
+
|
188
|
+
expect(@sample_table.column('C'..'D')).to eq([
|
189
|
+
[T_BIGDECIMAL, T_TIME, nil],
|
190
|
+
[nil, nil, nil],
|
191
|
+
])
|
192
|
+
end
|
182
193
|
|
183
|
-
|
184
|
-
|
185
|
-
[
|
186
|
-
|
194
|
+
it "should access a set of columns by range (as cell )" do
|
195
|
+
expect(@sample_table.column(0..1, as_cell: true)).to eq([
|
196
|
+
[Cell.new(1), Cell.new(T_DATE), Cell.new(true)],
|
197
|
+
[Cell.new(1.1), Cell.new(T_DATETIME), Cell.new('a')],
|
198
|
+
])
|
187
199
|
end
|
188
200
|
|
189
201
|
it "should delete a column" do
|
190
|
-
@sample_table.column_width_styles = [
|
202
|
+
@sample_table.column_width_styles = ['abc', nil, 'cde']
|
191
203
|
|
192
|
-
@sample_table.delete_column(
|
204
|
+
expect(@sample_table.delete_column(0)).to eq([1, T_DATE, true])
|
193
205
|
|
194
|
-
@sample_table.column_width_styles.
|
206
|
+
expect(@sample_table.column_width_styles).to eq([nil, 'cde'])
|
195
207
|
|
196
|
-
@sample_table.delete_column(
|
208
|
+
expect(@sample_table.delete_column(3)).to eq([nil, nil, nil])
|
197
209
|
|
198
|
-
@sample_table.column_width_styles.
|
210
|
+
expect(@sample_table.column_width_styles).to eq([nil, 'cde'])
|
199
211
|
|
200
|
-
@sample_table.data.
|
201
|
-
[
|
202
|
-
[
|
203
|
-
[
|
204
|
-
]
|
212
|
+
expect(@sample_table.data).to eq([
|
213
|
+
[1.1, T_BIGDECIMAL],
|
214
|
+
[T_DATETIME, T_TIME],
|
215
|
+
['a', nil]
|
216
|
+
])
|
205
217
|
end
|
206
218
|
|
207
219
|
it "should delete a set of columns by range" do
|
208
|
-
@sample_table.delete_column(
|
209
|
-
[
|
210
|
-
[
|
211
|
-
]
|
212
|
-
|
213
|
-
@sample_table.data.
|
214
|
-
[
|
215
|
-
[
|
216
|
-
[
|
217
|
-
]
|
220
|
+
expect(@sample_table.delete_column(0..1)).to eq([
|
221
|
+
[1, T_DATE, true],
|
222
|
+
[1.1, T_DATETIME, 'a'],
|
223
|
+
])
|
224
|
+
|
225
|
+
expect(@sample_table.data).to eq([
|
226
|
+
[T_BIGDECIMAL],
|
227
|
+
[T_TIME],
|
228
|
+
[nil],
|
229
|
+
])
|
218
230
|
end
|
219
231
|
|
220
232
|
it "should insert a column" do
|
221
233
|
# Setup/fill table
|
222
234
|
|
223
|
-
@sample_table.column_width_styles = [
|
235
|
+
@sample_table.column_width_styles = ['abc', nil, 'cde']
|
224
236
|
|
225
|
-
@sample_table.insert_column(
|
237
|
+
@sample_table.insert_column(1, [34, 'abc', Cell.new(nil)])
|
226
238
|
|
227
|
-
@sample_table.data.
|
228
|
-
[
|
229
|
-
[
|
230
|
-
[
|
231
|
-
]
|
239
|
+
expect(@sample_table.data).to eq([
|
240
|
+
[1, 34, 1.1, T_BIGDECIMAL],
|
241
|
+
[T_DATE, 'abc', T_DATETIME, T_TIME],
|
242
|
+
[true, nil, 'a', nil],
|
243
|
+
])
|
232
244
|
|
233
|
-
@sample_table.column_width_styles = [
|
245
|
+
@sample_table.column_width_styles = ['abc', nil, nil, 'cde']
|
234
246
|
|
235
247
|
# Empty table
|
236
248
|
|
237
|
-
table = SpreadBase::Table.new(
|
249
|
+
table = SpreadBase::Table.new('abc')
|
238
250
|
|
239
|
-
table.insert_column(
|
251
|
+
table.insert_column(0, [34, 'abc', 1])
|
240
252
|
|
241
|
-
table.data.
|
242
|
-
[
|
243
|
-
[
|
244
|
-
[
|
245
|
-
]
|
253
|
+
expect(table.data).to eq([
|
254
|
+
[34,],
|
255
|
+
['abc'],
|
256
|
+
[1],
|
257
|
+
])
|
246
258
|
|
247
|
-
@sample_table.column_width_styles = [
|
259
|
+
@sample_table.column_width_styles = [nil]
|
248
260
|
end
|
249
261
|
|
250
262
|
it "should not insert a column if the size is not correct" do
|
251
|
-
|
263
|
+
expect { @sample_table.insert_column(1, [34, 'abc']) }.to raise_error(RuntimeError, "Inserting column size (2) different than existing columns size (3)")
|
252
264
|
|
253
|
-
@sample_table.data.first.size.
|
265
|
+
expect(@sample_table.data.first.size).to eq(3)
|
254
266
|
end
|
255
267
|
|
256
268
|
it "should insert a column outside the row boundaries" do
|
257
|
-
@sample_table.insert_column(
|
269
|
+
@sample_table.insert_column(5, [34, 'abc', nil])
|
258
270
|
|
259
|
-
@sample_table.data.
|
260
|
-
[
|
261
|
-
[
|
262
|
-
[
|
263
|
-
]
|
271
|
+
expect(@sample_table.data).to eq([
|
272
|
+
[1, 1.1, T_BIGDECIMAL, nil, nil, 34],
|
273
|
+
[T_DATE, T_DATETIME, T_TIME, nil, nil, 'abc'],
|
274
|
+
[true, 'a', nil, nil, nil, nil],
|
275
|
+
])
|
264
276
|
end
|
265
277
|
|
266
278
|
it "should append a column" do
|
267
|
-
table = SpreadBase::Table.new(
|
279
|
+
table = SpreadBase::Table.new('abc')
|
268
280
|
|
269
|
-
table.append_column(
|
281
|
+
table.append_column([Cell.new(34), 'abc', 1])
|
270
282
|
|
271
|
-
table.data.
|
272
|
-
[
|
273
|
-
[
|
274
|
-
[
|
275
|
-
]
|
283
|
+
expect(table.data).to eq([
|
284
|
+
[34,],
|
285
|
+
['abc'],
|
286
|
+
[1],
|
287
|
+
])
|
276
288
|
|
277
|
-
table.append_column(
|
289
|
+
table.append_column(['cute', 'little', 'spielerin'])
|
278
290
|
|
279
|
-
table.data.
|
280
|
-
[
|
281
|
-
[
|
282
|
-
[
|
283
|
-
]
|
291
|
+
expect(table.data).to eq([
|
292
|
+
[34, 'cute'],
|
293
|
+
['abc', 'little'],
|
294
|
+
[1, 'spielerin'],
|
295
|
+
])
|
284
296
|
end
|
285
297
|
|
286
298
|
it "return the data as string (:to_s)" do
|
287
299
|
expected_string = "\
|
288
300
|
+------------+---------------------------+---------------------------+
|
289
|
-
| 1 | 1.1 |
|
290
|
-
| 2012-04-10 | 2012-04-
|
291
|
-
| true | a |
|
301
|
+
| 1 | 1.1 | 1.33 |
|
302
|
+
| 2012-04-10 | 2012-04-11 23:33:42 +0000 | 2012-04-11 23:33:42 +0200 |
|
303
|
+
| true | a | NIL |
|
292
304
|
+------------+---------------------------+---------------------------+
|
293
305
|
"
|
294
|
-
@sample_table.to_s.
|
306
|
+
expect(@sample_table.to_s).to eq(expected_string)
|
295
307
|
end
|
296
308
|
|
297
309
|
it "return the data as string, with headers (:to_s)" do
|
298
310
|
expected_string = "\
|
299
311
|
+------------+---------------------------+---------------------------+
|
300
|
-
| 1 | 1.1 |
|
312
|
+
| 1 | 1.1 | 1.33 |
|
301
313
|
+------------+---------------------------+---------------------------+
|
302
|
-
| 2012-04-10 | 2012-04-
|
303
|
-
| true | a |
|
314
|
+
| 2012-04-10 | 2012-04-11 23:33:42 +0000 | 2012-04-11 23:33:42 +0200 |
|
315
|
+
| true | a | NIL |
|
304
316
|
+------------+---------------------------+---------------------------+
|
305
317
|
"
|
306
318
|
|
307
|
-
@sample_table.to_s(
|
319
|
+
expect(@sample_table.to_s(with_headers: true)).to eq(expected_string)
|
308
320
|
|
309
321
|
@sample_table.data = []
|
310
322
|
|
311
|
-
@sample_table.to_s(
|
323
|
+
expect(@sample_table.to_s(with_headers: true)).to eq("")
|
312
324
|
end
|
313
325
|
|
314
326
|
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
4
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
5
|
+
# The generated `.rspec` file contains `--require spec_helper` which will cause
|
6
|
+
# this file to always be loaded, without a need to explicitly require it in any
|
7
|
+
# files.
|
8
|
+
#
|
9
|
+
# Given that it is always loaded, you are encouraged to keep this file as
|
10
|
+
# light-weight as possible. Requiring heavyweight dependencies from this file
|
11
|
+
# will add to the boot time of your test suite on EVERY test run, even for an
|
12
|
+
# individual file that may not need all of that loaded. Instead, consider making
|
13
|
+
# a separate helper file that requires the additional dependencies and performs
|
14
|
+
# the additional setup, and require it from the spec files that actually need
|
15
|
+
# it.
|
16
|
+
#
|
17
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
18
|
+
RSpec.configure do |config|
|
19
|
+
# rspec-expectations config goes here. You can use an alternate
|
20
|
+
# assertion/expectation library such as wrong or the stdlib/minitest
|
21
|
+
# assertions if you prefer.
|
22
|
+
config.expect_with :rspec do |expectations|
|
23
|
+
# This option will default to `true` in RSpec 4. It makes the `description`
|
24
|
+
# and `failure_message` of custom matchers include text for helper methods
|
25
|
+
# defined using `chain`, e.g.:
|
26
|
+
# be_bigger_than(2).and_smaller_than(4).description
|
27
|
+
# # => "be bigger than 2 and smaller than 4"
|
28
|
+
# ...rather than:
|
29
|
+
# # => "be bigger than 2"
|
30
|
+
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
31
|
+
end
|
32
|
+
|
33
|
+
# rspec-mocks config goes here. You can use an alternate test double
|
34
|
+
# library (such as bogus or mocha) by changing the `mock_with` option here.
|
35
|
+
config.mock_with :rspec do |mocks|
|
36
|
+
# Prevents you from mocking or stubbing a method that does not exist on
|
37
|
+
# a real object. This is generally recommended, and will default to
|
38
|
+
# `true` in RSpec 4.
|
39
|
+
mocks.verify_partial_doubles = true
|
40
|
+
end
|
41
|
+
|
42
|
+
# This option will default to `:apply_to_host_groups` in RSpec 4 (and will
|
43
|
+
# have no way to turn it off -- the option exists only for backwards
|
44
|
+
# compatibility in RSpec 3). It causes shared context metadata to be
|
45
|
+
# inherited by the metadata hash of host groups and examples, rather than
|
46
|
+
# triggering implicit auto-inclusion in groups with matching metadata.
|
47
|
+
config.shared_context_metadata_behavior = :apply_to_host_groups
|
48
|
+
|
49
|
+
# The settings below are suggested to provide a good initial experience
|
50
|
+
# with RSpec, but feel free to customize to your heart's content.
|
51
|
+
# This allows you to limit a spec run to individual examples or groups
|
52
|
+
# you care about by tagging them with `:focus` metadata. When nothing
|
53
|
+
# is tagged with `:focus`, all examples get run. RSpec also provides
|
54
|
+
# aliases for `it`, `describe`, and `context` that include `:focus`
|
55
|
+
# metadata: `fit`, `fdescribe` and `fcontext`, respectively.
|
56
|
+
config.filter_run_when_matching :focus
|
57
|
+
|
58
|
+
# Allows RSpec to persist some state between runs in order to support
|
59
|
+
# the `--only-failures` and `--next-failure` CLI options. We recommend
|
60
|
+
# you configure your source control system to ignore this file.
|
61
|
+
# config.example_status_persistence_file_path = "spec/examples.txt"
|
62
|
+
|
63
|
+
# Limits the available syntax to the non-monkey patched syntax that is
|
64
|
+
# recommended. For more details, see:
|
65
|
+
# - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/
|
66
|
+
# - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
|
67
|
+
# - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode
|
68
|
+
# config.disable_monkey_patching!
|
69
|
+
|
70
|
+
# This setting enables warnings. It's recommended, but in some cases may
|
71
|
+
# be too noisy due to issues in dependencies.
|
72
|
+
config.warnings = true
|
73
|
+
|
74
|
+
# Many RSpec users commonly either run the entire suite or an individual
|
75
|
+
# file, and it's useful to allow more verbose output when running an
|
76
|
+
# individual spec file.
|
77
|
+
if config.files_to_run.one?
|
78
|
+
# Use the documentation formatter for detailed output,
|
79
|
+
# unless a formatter has already been configured
|
80
|
+
# (e.g. via a command-line flag).
|
81
|
+
config.default_formatter = "doc"
|
82
|
+
end
|
83
|
+
|
84
|
+
# Print the 10 slowest examples and example groups at the
|
85
|
+
# end of the spec run, to help surface which specs are running
|
86
|
+
# particularly slow.
|
87
|
+
# config.profile_examples = 10
|
88
|
+
|
89
|
+
# Run specs in random order to surface order dependencies. If you find an
|
90
|
+
# order dependency and want to debug it, you can fix the order by providing
|
91
|
+
# the seed, which is printed after each run.
|
92
|
+
# --seed 1234
|
93
|
+
config.order = :random
|
94
|
+
|
95
|
+
# Seed global randomization in this process using the `--seed` CLI option.
|
96
|
+
# Setting this allows you to use `--seed` to deterministically reproduce
|
97
|
+
# test failures related to randomization by passing the same `--seed` value
|
98
|
+
# as the one that triggered the failure.
|
99
|
+
Kernel.srand config.seed
|
100
|
+
end
|
data/spec/spec_helpers.rb
CHANGED
@@ -1,45 +1,25 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
|
3
|
-
=begin
|
4
|
-
Copyright 2012 Saverio Miroddi saverio.pub2 <a-hat!> gmail.com
|
5
|
-
|
6
|
-
This file is part of SpreadBase.
|
7
|
-
|
8
|
-
SpreadBase is free software: you can redistribute it and/or modify it under the
|
9
|
-
terms of the GNU Lesser General Public License as published by the Free Software
|
10
|
-
Foundation, either version 3 of the License, or (at your option) any later
|
11
|
-
version.
|
12
|
-
|
13
|
-
SpreadBase is distributed in the hope that it will be useful, but WITHOUT ANY
|
14
|
-
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
15
|
-
PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
16
|
-
|
17
|
-
You should have received a copy of the GNU Lesser General Public License along
|
18
|
-
with SpreadBase. If not, see <http://www.gnu.org/licenses/>.
|
19
|
-
=end
|
20
|
-
|
21
1
|
require 'date'
|
22
2
|
require 'bigdecimal'
|
23
3
|
|
24
4
|
module SpecHelpers
|
25
5
|
|
26
|
-
T_DATE = Date.new(
|
27
|
-
T_DATETIME = DateTime.new(
|
28
|
-
T_TIME = Time.
|
29
|
-
T_BIGDECIMAL = BigDecimal
|
6
|
+
T_DATE = Date.new(2012, 4, 10)
|
7
|
+
T_DATETIME = DateTime.new(2012, 4, 11, 23, 33, 42)
|
8
|
+
T_TIME = Time.new(2012, 4, 11, 23, 33, 42, "+02:00")
|
9
|
+
T_BIGDECIMAL = BigDecimal('1.33')
|
30
10
|
|
31
11
|
# This method is cool beyond any argument about the imperfect name.
|
32
12
|
#
|
33
|
-
def assert_size(
|
34
|
-
collection.size.
|
13
|
+
def assert_size(collection, expected_size)
|
14
|
+
expect(collection.size).to eql(expected_size)
|
35
15
|
|
36
|
-
yield(
|
16
|
+
yield(*collection) if block_given?
|
37
17
|
end
|
38
18
|
|
39
|
-
def stub_initializer(
|
40
|
-
instance = klazz.new(
|
19
|
+
def stub_initializer(klazz, *args)
|
20
|
+
instance = klazz.new(*args)
|
41
21
|
|
42
|
-
klazz.
|
22
|
+
allow(klazz).to receive(:new) { instance }
|
43
23
|
|
44
24
|
instance
|
45
25
|
end
|