robust_excel_ole 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +53 -116
- data/README_detail.rdoc +510 -0
- data/TodoList.md +21 -11
- data/examples/open_save_close/example_control_to_excel.rb +1 -1
- data/examples/open_save_close/example_default_excel.rb +1 -1
- data/examples/open_save_close/example_force_excel.rb +2 -2
- data/examples/open_save_close/example_if_unsaved_forget.rb +1 -1
- data/examples/open_save_close/example_if_unsaved_forget_more.rb +2 -2
- data/examples/open_save_close/example_rename_cells.rb +1 -1
- data/examples/open_save_close/example_reuse.rb +1 -1
- data/examples/open_save_close/example_simple.rb +1 -1
- data/lib/robust_excel_ole/book.rb +77 -75
- data/lib/robust_excel_ole/book_store.rb +51 -27
- data/lib/robust_excel_ole/excel.rb +0 -1
- data/lib/robust_excel_ole/version.rb +1 -1
- data/robust_excel_ole.gemspec +2 -7
- data/spec/book_spec.rb +382 -95
- data/spec/book_store_spec.rb +179 -25
- data/spec/excel_spec.rb +1 -4
- metadata +9 -88
data/spec/book_store_spec.rb
CHANGED
@@ -13,6 +13,7 @@ end
|
|
13
13
|
$VERBOSE = nil
|
14
14
|
|
15
15
|
include RobustExcelOle
|
16
|
+
|
16
17
|
module RobustExcelOle
|
17
18
|
class MockBookstore
|
18
19
|
def fetch(filename, options = { })
|
@@ -86,7 +87,7 @@ describe BookStore do
|
|
86
87
|
end
|
87
88
|
|
88
89
|
after do
|
89
|
-
@book.close
|
90
|
+
@book.close rescue nil
|
90
91
|
end
|
91
92
|
|
92
93
|
it "should do simple store and fetch" do
|
@@ -118,6 +119,14 @@ describe BookStore do
|
|
118
119
|
new_book.should == nil
|
119
120
|
end
|
120
121
|
|
122
|
+
it "should fetch a closed book" do
|
123
|
+
@bookstore.store(@book)
|
124
|
+
@book.close
|
125
|
+
book1 = @bookstore.fetch(@simple_file)
|
126
|
+
book1.should be_a Book
|
127
|
+
book1.should_not be_alive
|
128
|
+
end
|
129
|
+
|
121
130
|
it "should fetch nothing when fetching a different book" do
|
122
131
|
@bookstore.store(@book)
|
123
132
|
new_book = @bookstore.fetch(@different_file)
|
@@ -171,20 +180,49 @@ describe BookStore do
|
|
171
180
|
new_book.close
|
172
181
|
end
|
173
182
|
|
174
|
-
it "should fetch the
|
183
|
+
it "should fetch the last book with :prefer_writeable => false" do
|
175
184
|
@book2 = Book.open(@simple_file, :force_excel => :new)
|
176
|
-
sheet = @book2[0]
|
177
185
|
@bookstore.store(@book2)
|
178
|
-
sheet[0,0] = sheet[0,0].value == "simple" ? "complex" : "simple"
|
179
186
|
@book.ReadOnly.should be_false
|
180
187
|
@book2.ReadOnly.should be_true
|
181
|
-
@
|
182
|
-
new_book
|
183
|
-
new_book.should == @
|
184
|
-
new_book.should_not == @book2
|
188
|
+
new_book = @bookstore.fetch(@simple_file, :prefer_writable => false)
|
189
|
+
new_book.should_not == @book
|
190
|
+
new_book.should == @book2
|
185
191
|
new_book.close
|
186
192
|
end
|
187
193
|
|
194
|
+
it "should fetch the second, open book, if the first book is closed" do
|
195
|
+
@book2 = Book.open(@simple_file, :force_excel => :new)
|
196
|
+
@bookstore.store(@book2)
|
197
|
+
@book.ReadOnly.should be_false
|
198
|
+
@book2.ReadOnly.should be_true
|
199
|
+
@book.close
|
200
|
+
new_book = @bookstore.fetch(@simple_file, :prefer_writable => false)
|
201
|
+
new_book2 = @bookstore.fetch(@simple_file)
|
202
|
+
new_book.should_not == @book
|
203
|
+
new_book2.should_not == @book
|
204
|
+
new_book.should == @book2
|
205
|
+
new_book2.should == @book2
|
206
|
+
new_book.close
|
207
|
+
new_book2.close
|
208
|
+
end
|
209
|
+
|
210
|
+
it "should fetch the first, open book, if the second book is closed, even with :prefer_writeable => false" do
|
211
|
+
@book2 = Book.open(@simple_file, :force_excel => :new)
|
212
|
+
@bookstore.store(@book2)
|
213
|
+
@book.ReadOnly.should be_false
|
214
|
+
@book2.ReadOnly.should be_true
|
215
|
+
@book2.close
|
216
|
+
new_book = @bookstore.fetch(@simple_file, :prefer_writable => false)
|
217
|
+
new_book2 = @bookstore.fetch(@simple_file)
|
218
|
+
new_book.should_not == @book2
|
219
|
+
new_book2.should_not == @book2
|
220
|
+
new_book.should == @book
|
221
|
+
new_book2.should == @book
|
222
|
+
new_book.close
|
223
|
+
new_book2.close
|
224
|
+
end
|
225
|
+
|
188
226
|
end
|
189
227
|
|
190
228
|
context "with readonly book" do
|
@@ -205,9 +243,17 @@ describe BookStore do
|
|
205
243
|
@book.ReadOnly.should be_true
|
206
244
|
@book2.ReadOnly.should be_false
|
207
245
|
new_book = @bookstore.fetch(@simple_file)
|
246
|
+
new_book2 = @bookstore.fetch(@simple_file, :prefer_writable => true)
|
247
|
+
new_book3 = @bookstore.fetch(@simple_file, :prefer_writable => false)
|
208
248
|
new_book.should == @book2
|
249
|
+
new_book2.should == @book2
|
250
|
+
new_book3.should == @book2
|
209
251
|
new_book.should_not == @book
|
252
|
+
new_book2.should_not == @book
|
253
|
+
new_book3.should_not == @book
|
210
254
|
new_book.close
|
255
|
+
new_book2.close
|
256
|
+
new_book3.close
|
211
257
|
end
|
212
258
|
|
213
259
|
it "should fetch the recent readonly book when there are only readonly books" do
|
@@ -221,20 +267,6 @@ describe BookStore do
|
|
221
267
|
new_book.close
|
222
268
|
end
|
223
269
|
|
224
|
-
it "should fetch the second readonly book with unsaved changes" do
|
225
|
-
@book2 = Book.open(@simple_file, :force_excel => :new, :read_only => true)
|
226
|
-
sheet = @book2[0]
|
227
|
-
@bookstore.store(@book2)
|
228
|
-
sheet[0,0] = sheet[0,0].value == "simple" ? "complex" : "simple"
|
229
|
-
@book.ReadOnly.should be_true
|
230
|
-
@book2.ReadOnly.should be_true
|
231
|
-
@book2.Saved.should be_false
|
232
|
-
new_book = @bookstore.fetch(@simple_file)
|
233
|
-
new_book.should == @book2
|
234
|
-
new_book.should_not == @book
|
235
|
-
new_book.close
|
236
|
-
end
|
237
|
-
|
238
270
|
it "should fetch the second, writable book, if a writable, a readonly and an unsaved readonly book exist" do
|
239
271
|
@book2 = Book.open(@simple_file, :force_excel => :new)
|
240
272
|
@book3 = Book.open(@simple_file, :force_excel => :new)
|
@@ -247,19 +279,44 @@ describe BookStore do
|
|
247
279
|
@book3.ReadOnly.should be_true
|
248
280
|
@book3.Saved.should be_false
|
249
281
|
new_book = @bookstore.fetch(@simple_file)
|
282
|
+
new_book2 = @bookstore.fetch(@simple_file, :prefer_writable => false)
|
250
283
|
new_book.should == @book2
|
284
|
+
new_book2.should == @book3
|
251
285
|
new_book.should_not == @book
|
252
|
-
new_book.should_not == @book3
|
286
|
+
new_book.should_not == @book3
|
287
|
+
new_book2.should_not == @book
|
288
|
+
new_book2.should_not == @book2
|
253
289
|
new_book.close
|
290
|
+
new_book2.close
|
254
291
|
end
|
255
292
|
end
|
256
293
|
|
294
|
+
context "with several closed books" do
|
295
|
+
|
296
|
+
before do
|
297
|
+
@book = Book.open(@simple_file)
|
298
|
+
@bookstore.store(@book)
|
299
|
+
@book2 = Book.open(@simple_file, :force_excel => :new)
|
300
|
+
@bookstore.store(@book2)
|
301
|
+
@book.close
|
302
|
+
@book2.close
|
303
|
+
end
|
304
|
+
|
305
|
+
it "should fetch the recent closed book" do
|
306
|
+
new_book = @bookstore.fetch(@simple_file)
|
307
|
+
new_book.should == @book2
|
308
|
+
new_book.should_not == @book
|
309
|
+
end
|
310
|
+
|
311
|
+
end
|
312
|
+
|
257
313
|
context "with changing file name" do
|
258
314
|
|
259
315
|
before do
|
260
316
|
@book = Book.open(@simple_file)
|
261
317
|
@book.save_as(@simple_save_file, :if_exists => :overwrite)
|
262
|
-
@bookstore
|
318
|
+
@bookstore.store(@book)
|
319
|
+
#@bookstore = @book.book_store
|
263
320
|
end
|
264
321
|
|
265
322
|
after do
|
@@ -277,6 +334,7 @@ describe BookStore do
|
|
277
334
|
end
|
278
335
|
end
|
279
336
|
|
337
|
+
|
280
338
|
context "with given excel instance and fetching readonly" do
|
281
339
|
|
282
340
|
before do
|
@@ -293,14 +351,110 @@ describe BookStore do
|
|
293
351
|
it "should fetch the book in the given excel instance" do
|
294
352
|
@book.ReadOnly.should be_false
|
295
353
|
@book2.ReadOnly.should be_true
|
296
|
-
book_new = @bookstore.fetch(@simple_file, :
|
354
|
+
book_new = @bookstore.fetch(@simple_file, :prefer_excel => @book2.excel)
|
297
355
|
book_new.should be_a Book
|
298
356
|
book_new.should be_alive
|
299
357
|
book_new.should == @book2
|
300
358
|
end
|
359
|
+
end
|
360
|
+
end
|
361
|
+
|
362
|
+
describe "book life cycle" do
|
363
|
+
|
364
|
+
context "with an open book" do
|
365
|
+
|
366
|
+
before do
|
367
|
+
@book = Book.open(@simple_file)
|
368
|
+
@bookstore.store(@book)
|
369
|
+
end
|
370
|
+
|
371
|
+
after do
|
372
|
+
@book.close rescue nil
|
373
|
+
end
|
374
|
+
|
375
|
+
it "should find the book if the book has astill got a reference" do
|
376
|
+
GC.start
|
377
|
+
@bookstore.fetch(@simple_file).should == @book
|
378
|
+
end
|
379
|
+
|
380
|
+
it "should have forgotten the book if there is no reference anymore" do
|
381
|
+
@book = nil
|
382
|
+
GC.start
|
383
|
+
@bookstore.fetch(@simple_file).should == nil
|
384
|
+
end
|
301
385
|
|
386
|
+
it "should have forgotten some books if they have no reference anymore" do
|
387
|
+
book_new = Book.open(@different_file)
|
388
|
+
@bookstore.store(book_new)
|
389
|
+
@book = nil
|
390
|
+
GC.start
|
391
|
+
@bookstore.fetch(@simple_file).should == nil
|
392
|
+
@bookstore.fetch(@different_file).should == book_new
|
393
|
+
end
|
302
394
|
end
|
395
|
+
end
|
396
|
+
|
397
|
+
describe "excel_list" do
|
398
|
+
|
399
|
+
context "with no books" do
|
400
|
+
|
401
|
+
it "should yield nil" do
|
402
|
+
@bookstore.excel_list.should == {}
|
403
|
+
end
|
404
|
+
|
405
|
+
end
|
406
|
+
|
407
|
+
context "with open books" do
|
408
|
+
|
409
|
+
before do
|
410
|
+
@book = Book.open(@simple_file)
|
411
|
+
@bookstore.store(@book)
|
412
|
+
end
|
303
413
|
|
414
|
+
after do
|
415
|
+
@book.close
|
416
|
+
end
|
304
417
|
|
418
|
+
it "should yield an excel and the workbook" do
|
419
|
+
excels = @bookstore.excel_list
|
420
|
+
excels.size.should == 1
|
421
|
+
excels.each do |excel,workbooks|
|
422
|
+
excel.should be_a Excel
|
423
|
+
workbooks.size.should == 1
|
424
|
+
workbooks.each do |workbook|
|
425
|
+
workbook.should == @book.workbook
|
426
|
+
end
|
427
|
+
end
|
428
|
+
end
|
429
|
+
|
430
|
+
it "should yield an excel with two books" do
|
431
|
+
book1 = Book.open(@different_file)
|
432
|
+
@bookstore.store(book1)
|
433
|
+
excels = @bookstore.excel_list
|
434
|
+
excels.size.should == 1
|
435
|
+
excels.each do |excel,workbooks|
|
436
|
+
excel.should be_a Excel
|
437
|
+
workbooks.size.should == 2
|
438
|
+
#workbooks[0].should == @book.workbook
|
439
|
+
#workbooks[1].should == book1.workbook
|
440
|
+
end
|
441
|
+
end
|
442
|
+
|
443
|
+
it "should yield two excels and two books" do
|
444
|
+
e = Excel.create
|
445
|
+
book1 = Book.open(@simple_file, :force_excel => :new)
|
446
|
+
@bookstore.store(book1)
|
447
|
+
excels = @bookstore.excel_list
|
448
|
+
excels.size.should == 2
|
449
|
+
num = 0
|
450
|
+
excels.each do |excel,workbooks|
|
451
|
+
num = num + 1
|
452
|
+
excel.should be_a Excel
|
453
|
+
workbooks.size.should == 1
|
454
|
+
#workbooks[0].should == @book.workbook if num == 1
|
455
|
+
#workbooks[0].should == book1.workbook if num == 2
|
456
|
+
end
|
457
|
+
end
|
458
|
+
end
|
305
459
|
end
|
306
460
|
end
|
data/spec/excel_spec.rb
CHANGED
@@ -60,6 +60,7 @@ module RobustExcelOle
|
|
60
60
|
|
61
61
|
it "should reuse existing excel with default options for 'new'" do
|
62
62
|
excel2 = Excel.new
|
63
|
+
excel2.should be_a Excel
|
63
64
|
#puts "@excel1 #{@excel1.Hwnd}"
|
64
65
|
#puts "excel2 #{excel2.Hwnd}"
|
65
66
|
excel2.Hwnd.should == @excel1.Hwnd
|
@@ -226,8 +227,6 @@ module RobustExcelOle
|
|
226
227
|
end
|
227
228
|
end
|
228
229
|
|
229
|
-
|
230
|
-
|
231
230
|
describe "RobustExcelOle" do
|
232
231
|
context "#absolute_path" do
|
233
232
|
it "should work" do
|
@@ -242,9 +241,7 @@ module RobustExcelOle
|
|
242
241
|
RobustExcelOle::absolute_path(@filename).gsub("\\","/").should == @filename
|
243
242
|
end
|
244
243
|
end
|
245
|
-
|
246
244
|
end
|
247
|
-
|
248
245
|
end
|
249
246
|
|
250
247
|
class TestError < RuntimeError
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: robust_excel_ole
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 17
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 3
|
9
|
-
-
|
10
|
-
version: 0.3.
|
9
|
+
- 1
|
10
|
+
version: 0.3.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- traths
|
@@ -15,29 +15,13 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2015-
|
18
|
+
date: 2015-05-09 00:00:00 +02:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
|
-
- !ruby/object:Gem::Dependency
|
22
|
-
name: rake
|
23
|
-
prerelease: false
|
24
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
|
-
requirements:
|
27
|
-
- - ">="
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
hash: 63
|
30
|
-
segments:
|
31
|
-
- 0
|
32
|
-
- 9
|
33
|
-
- 2
|
34
|
-
version: 0.9.2
|
35
|
-
type: :development
|
36
|
-
version_requirements: *id001
|
37
21
|
- !ruby/object:Gem::Dependency
|
38
22
|
name: rspec
|
39
23
|
prerelease: false
|
40
|
-
requirement: &
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
41
25
|
none: false
|
42
26
|
requirements:
|
43
27
|
- - ">="
|
@@ -49,72 +33,8 @@ dependencies:
|
|
49
33
|
- 0
|
50
34
|
version: 2.6.0
|
51
35
|
type: :development
|
52
|
-
version_requirements: *
|
53
|
-
|
54
|
-
name: rb-fchange
|
55
|
-
prerelease: false
|
56
|
-
requirement: &id003 !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
|
-
requirements:
|
59
|
-
- - ">="
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
hash: 21
|
62
|
-
segments:
|
63
|
-
- 0
|
64
|
-
- 0
|
65
|
-
- 5
|
66
|
-
version: 0.0.5
|
67
|
-
type: :development
|
68
|
-
version_requirements: *id003
|
69
|
-
- !ruby/object:Gem::Dependency
|
70
|
-
name: wdm
|
71
|
-
prerelease: false
|
72
|
-
requirement: &id004 !ruby/object:Gem::Requirement
|
73
|
-
none: false
|
74
|
-
requirements:
|
75
|
-
- - ">="
|
76
|
-
- !ruby/object:Gem::Version
|
77
|
-
hash: 25
|
78
|
-
segments:
|
79
|
-
- 0
|
80
|
-
- 0
|
81
|
-
- 3
|
82
|
-
version: 0.0.3
|
83
|
-
type: :development
|
84
|
-
version_requirements: *id004
|
85
|
-
- !ruby/object:Gem::Dependency
|
86
|
-
name: win32console
|
87
|
-
prerelease: false
|
88
|
-
requirement: &id005 !ruby/object:Gem::Requirement
|
89
|
-
none: false
|
90
|
-
requirements:
|
91
|
-
- - ">="
|
92
|
-
- !ruby/object:Gem::Version
|
93
|
-
hash: 31
|
94
|
-
segments:
|
95
|
-
- 1
|
96
|
-
- 3
|
97
|
-
- 2
|
98
|
-
version: 1.3.2
|
99
|
-
type: :development
|
100
|
-
version_requirements: *id005
|
101
|
-
- !ruby/object:Gem::Dependency
|
102
|
-
name: guard-rspec
|
103
|
-
prerelease: false
|
104
|
-
requirement: &id006 !ruby/object:Gem::Requirement
|
105
|
-
none: false
|
106
|
-
requirements:
|
107
|
-
- - ">="
|
108
|
-
- !ruby/object:Gem::Version
|
109
|
-
hash: 9
|
110
|
-
segments:
|
111
|
-
- 2
|
112
|
-
- 1
|
113
|
-
- 1
|
114
|
-
version: 2.1.1
|
115
|
-
type: :development
|
116
|
-
version_requirements: *id006
|
117
|
-
description: RobustExcelOle wraps the win32ole library, and allows to perform various operation in Excel with ruby in a reliable way. Detailed description please see the README.
|
36
|
+
version_requirements: *id001
|
37
|
+
description: RobustExcelOle processes Excel files, provides all win32ole operations, convenient methods for opening, saving and closing, and implements an Excel file management system.
|
118
38
|
email:
|
119
39
|
- Thomas.Raths@gmx.net
|
120
40
|
executables: []
|
@@ -130,6 +50,7 @@ files:
|
|
130
50
|
- Guardfile
|
131
51
|
- LICENSE
|
132
52
|
- README.rdoc
|
53
|
+
- README_detail.rdoc
|
133
54
|
- Rakefile
|
134
55
|
- TodoList.md
|
135
56
|
- examples/edit_sheets/example_access_sheets_and_cells.rb
|
@@ -221,6 +142,6 @@ rubyforge_project: robust_excel_ole
|
|
221
142
|
rubygems_version: 1.3.7
|
222
143
|
signing_key:
|
223
144
|
specification_version: 3
|
224
|
-
summary: RobustExcelOle
|
145
|
+
summary: RobustExcelOle processes Excel files and wraps the win32ole library.
|
225
146
|
test_files: []
|
226
147
|
|