spreadbase 0.1.3 → 0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,36 +1,18 @@
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
- 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
- [ 1, 1.1, T_BIGDECIMAL ],
32
- [ T_DATE, T_DATETIME, T_TIME ],
33
- [ true, 'a', nil ]
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
- lambda { @sample_table.row( 4 ) }.should raise_error( RuntimeError, "Invalid row index (4) - allowed 0 to 2" )
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
- lambda { @sample_table.insert_row( -1, [] ) }.should raise_error( RuntimeError, "Invalid row index (-1) - allowed 0 to 3" )
46
- lambda { @sample_table.insert_row( 40, [] ) }.should raise_error( RuntimeError, "Invalid row index (40) - allowed 0 to 3" )
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
- [ 1, 1.1, T_BIGDECIMAL ],
52
- [ T_DATE, T_DATETIME, T_TIME ],
53
- [ true, 'a', nil ]
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.should == expected_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
- lambda { SpreadBase::Table.new( nil ) }.should raise_error( "Table name required" )
61
- lambda { SpreadBase::Table.new( '' ) }.should raise_error( "Table name required" )
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[ 'a', 0 ].should == 1
70
- @sample_table[ 1, 0 ].should == 1.1
71
- @sample_table[ 2, 0 ].should == T_BIGDECIMAL
72
- @sample_table[ 0, 1 ].should == T_DATE
73
- @sample_table[ 'B', 1 ].should == T_DATETIME
74
- @sample_table[ 2, 1 ].should == T_TIME
75
- @sample_table[ 0, 2 ].should == true
76
- @sample_table[ 1, 2 ].should == 'a'
77
- @sample_table[ 2, 2 ].should == nil
78
-
79
- lambda { @sample_table[ -1, 0 ] }.should raise_error( RuntimeError, "Negative column indexes not allowed: -1" )
80
- lambda { @sample_table[ 0, -1 ] }.should raise_error( RuntimeError, "Invalid row index (-1) - allowed 0 to 2" )
81
- lambda { @sample_table[ 3, 0 ] }.should raise_error( RuntimeError, "Invalid column index (3) for the given row - allowed 0 to 2" )
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[ 0, 0 ] = 10
86
- @sample_table[ 'B', 1 ] = T_TIME
79
+ @sample_table[0, 0] = 10
80
+ @sample_table['B', 1] = Cell.new(T_TIME)
87
81
 
88
- @sample_table.data.should == [
89
- [ 10, 1.1, T_BIGDECIMAL ],
90
- [ T_DATE, T_TIME, T_TIME ],
91
- [ true, 'a', nil ],
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
- lambda { @sample_table[ 0, -1 ] = 33 }.should raise_error( RuntimeError, "Invalid row index (-1) - allowed 0 to 2" )
95
- lambda { @sample_table[ 3, 0 ] = 44 }.should raise_error( RuntimeError, "Invalid column index (3) for the given row - allowed 0 to 2" )
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( 0 ).should == [ 1, 1.1, T_BIGDECIMAL ]
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
- lambda { @sample_table.row( -1 ) }.should raise_error( RuntimeError, "Invalid row index (-1) - allowed 0 to 2" )
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( ( 0 .. 1 ) ).should == [
107
- [ 1, 1.1, T_BIGDECIMAL ],
108
- [ T_DATE, T_DATETIME, T_TIME ],
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
- lambda { @sample_table.row( ( 0 .. 5 ) ) }.should raise_error( RuntimeError, "Invalid row index (5) - allowed 0 to 2" )
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( 1 ).should == [ T_DATE, T_DATETIME, T_TIME ]
119
+ expect(@sample_table.delete_row(1)).to eq([T_DATE, T_DATETIME, T_TIME])
116
120
 
117
- @sample_table.data.should == [
118
- [ 1, 1.1, T_BIGDECIMAL ],
119
- [ true, 'a', nil ],
120
- ]
121
+ expect(@sample_table.data).to eq([
122
+ [1, 1.1, T_BIGDECIMAL],
123
+ [true, 'a', nil],
124
+ ])
121
125
 
122
- lambda { @sample_table.delete_row( -1 ) }.should raise_error( RuntimeError, "Invalid row index (-1) - allowed 0 to 1" )
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( ( 0 .. 1 ) ).should == [
127
- [ 1, 1.1, T_BIGDECIMAL ],
128
- [ T_DATE, T_DATETIME, T_TIME ],
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.should == [
132
- [ true, 'a', nil ]
133
- ]
135
+ expect(@sample_table.data).to eq([
136
+ [true, 'a', nil]
137
+ ])
134
138
 
135
- lambda { @sample_table.delete_row( ( 0 .. 5 ) ) }.should raise_error( RuntimeError, "Invalid row index (5) - allowed 0 to 0" )
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( 1, [ 4, 5, 6 ] )
143
+ @sample_table.insert_row(1, [4, Cell.new(5), 6])
140
144
 
141
- @sample_table.data.should == [
142
- [ 1, 1.1, T_BIGDECIMAL ],
143
- [ 4, 5, 6 ],
144
- [ T_DATE, T_DATETIME, T_TIME ],
145
- [ true, 'a', nil ],
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( 0, [ 4, 5 ] )
158
+ @sample_table.insert_row(0, [4, 5])
155
159
 
156
- @sample_table.data.size.should == 1
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( [ 4, 5, 6 ] )
161
-
162
- @sample_table.data.should == [
163
- [ 1, 1.1, T_BIGDECIMAL ],
164
- [ T_DATE, T_DATETIME, T_TIME ],
165
- [ true, 'a', nil ],
166
- [ 4, 5, 6 ],
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( 0 ).should == [ 1, T_DATE, true ]
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( 3 ).should == [ nil, nil, nil ]
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( ( 0 .. 1 ) ).should == [
179
- [ 1, T_DATE, true ],
180
- [ 1.1, T_DATETIME, 'a' ],
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
- @sample_table.column( ( 'C' .. 'D' ) ).should == [
184
- [ T_BIGDECIMAL, T_TIME, nil ],
185
- [ nil, nil, nil ],
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 = [ 'abc', nil, 'cde' ]
202
+ @sample_table.column_width_styles = ['abc', nil, 'cde']
191
203
 
192
- @sample_table.delete_column( 0 ).should == [ 1, T_DATE, true ]
204
+ expect(@sample_table.delete_column(0)).to eq([1, T_DATE, true])
193
205
 
194
- @sample_table.column_width_styles.should == [ nil, 'cde' ]
206
+ expect(@sample_table.column_width_styles).to eq([nil, 'cde'])
195
207
 
196
- @sample_table.delete_column( 3 ).should == [ nil, nil, nil ]
208
+ expect(@sample_table.delete_column(3)).to eq([nil, nil, nil])
197
209
 
198
- @sample_table.column_width_styles.should == [ nil, 'cde' ]
210
+ expect(@sample_table.column_width_styles).to eq([nil, 'cde'])
199
211
 
200
- @sample_table.data.should == [
201
- [ 1.1, T_BIGDECIMAL ],
202
- [ T_DATETIME, T_TIME ],
203
- [ 'a', nil ]
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( ( 0 .. 1 ) ).should == [
209
- [ 1, T_DATE, true ],
210
- [ 1.1, T_DATETIME, 'a' ],
211
- ]
212
-
213
- @sample_table.data.should == [
214
- [ T_BIGDECIMAL ],
215
- [ T_TIME ],
216
- [ nil ],
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 = [ 'abc', nil, 'cde' ]
235
+ @sample_table.column_width_styles = ['abc', nil, 'cde']
224
236
 
225
- @sample_table.insert_column( 1, [ 34, 'abc', nil ] )
237
+ @sample_table.insert_column(1, [34, 'abc', Cell.new(nil)])
226
238
 
227
- @sample_table.data.should == [
228
- [ 1, 34, 1.1, T_BIGDECIMAL ],
229
- [ T_DATE, 'abc', T_DATETIME, T_TIME ],
230
- [ true, nil, 'a', nil ],
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 = [ 'abc', nil, nil, 'cde' ]
245
+ @sample_table.column_width_styles = ['abc', nil, nil, 'cde']
234
246
 
235
247
  # Empty table
236
248
 
237
- table = SpreadBase::Table.new( 'abc' )
249
+ table = SpreadBase::Table.new('abc')
238
250
 
239
- table.insert_column( 0, [ 34, 'abc', 1 ] )
251
+ table.insert_column(0, [34, 'abc', 1])
240
252
 
241
- table.data.should == [
242
- [ 34, ],
243
- [ 'abc' ],
244
- [ 1 ],
245
- ]
253
+ expect(table.data).to eq([
254
+ [34,],
255
+ ['abc'],
256
+ [1],
257
+ ])
246
258
 
247
- @sample_table.column_width_styles = [ nil ]
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
- lambda { @sample_table.insert_column( 1, [ 34, 'abc' ] ) }.should raise_error( RuntimeError, "Inserting column size (2) different than existing columns size (3)" )
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.should == 3
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( 5, [ 34, 'abc', nil ] )
269
+ @sample_table.insert_column(5, [34, 'abc', nil])
258
270
 
259
- @sample_table.data.should == [
260
- [ 1, 1.1, T_BIGDECIMAL, nil, nil, 34 ],
261
- [ T_DATE, T_DATETIME, T_TIME, nil, nil, 'abc' ],
262
- [ true, 'a', nil, nil, nil, nil ],
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( 'abc' )
279
+ table = SpreadBase::Table.new('abc')
268
280
 
269
- table.append_column( [ 34, 'abc', 1 ] )
281
+ table.append_column([Cell.new(34), 'abc', 1])
270
282
 
271
- table.data.should == [
272
- [ 34, ],
273
- [ 'abc' ],
274
- [ 1 ],
275
- ]
283
+ expect(table.data).to eq([
284
+ [34,],
285
+ ['abc'],
286
+ [1],
287
+ ])
276
288
 
277
- table.append_column( [ 'cute', 'little', 'spielerin' ] )
289
+ table.append_column(['cute', 'little', 'spielerin'])
278
290
 
279
- table.data.should == [
280
- [ 34, 'cute' ],
281
- [ 'abc', 'little' ],
282
- [ 1, 'spielerin' ],
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 | 0.133E1 |
290
- | 2012-04-10 | 2012-04-11T23:33:42+00:00 | 2012-04-11 23:33:42 +0200 |
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.should == expected_string
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 | 0.133E1 |
312
+ | 1 | 1.1 | 1.33 |
301
313
  +------------+---------------------------+---------------------------+
302
- | 2012-04-10 | 2012-04-11T23:33:42+00:00 | 2012-04-11 23:33:42 +0200 |
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( :with_headers => true ).should == expected_string
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( :with_headers => true ).should == ""
323
+ expect(@sample_table.to_s(with_headers: true)).to eq("")
312
324
  end
313
325
 
314
326
  end
@@ -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( 2012, 4, 10 )
27
- T_DATETIME = DateTime.new( 2012, 4, 11, 23, 33, 42 )
28
- T_TIME = Time.local( 2012, 4, 11, 23, 33, 42 )
29
- T_BIGDECIMAL = BigDecimal.new( '1.33' )
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( collection, expected_size )
34
- collection.size.should == expected_size
13
+ def assert_size(collection, expected_size)
14
+ expect(collection.size).to eql(expected_size)
35
15
 
36
- yield( *collection ) if block_given?
16
+ yield(*collection) if block_given?
37
17
  end
38
18
 
39
- def stub_initializer( klazz, *args )
40
- instance = klazz.new( *args )
19
+ def stub_initializer(klazz, *args)
20
+ instance = klazz.new(*args)
41
21
 
42
- klazz.stub!( :new ).and_return( instance )
22
+ allow(klazz).to receive(:new) { instance }
43
23
 
44
24
  instance
45
25
  end