robust_excel_ole 0.5.1 → 0.6
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.
- data/Changelog +13 -0
- data/README.rdoc +70 -21
- data/README_detail.rdoc +60 -27
- data/examples/edit_sheets/example_access_sheets_and_cells.rb +2 -2
- data/examples/edit_sheets/example_adding_sheets.rb +2 -2
- data/examples/edit_sheets/example_concating.rb +2 -3
- data/examples/edit_sheets/example_copying.rb +2 -3
- data/examples/edit_sheets/example_expanding.rb +2 -3
- data/examples/edit_sheets/example_naming.rb +2 -3
- data/examples/edit_sheets/example_ranges.rb +2 -2
- data/examples/edit_sheets/example_saving.rb +2 -3
- data/examples/open_save_close/example_control_to_excel.rb +3 -3
- data/examples/open_save_close/example_default_excel.rb +4 -4
- data/examples/open_save_close/example_force_excel.rb +2 -2
- data/examples/open_save_close/example_if_obstructed_closeifsaved.rb +2 -2
- data/examples/open_save_close/example_if_obstructed_forget.rb +2 -2
- data/examples/open_save_close/example_if_obstructed_save.rb +2 -2
- data/examples/open_save_close/example_if_unsaved_accept.rb +2 -2
- data/examples/open_save_close/example_if_unsaved_forget.rb +2 -2
- data/examples/open_save_close/example_if_unsaved_forget_more.rb +4 -5
- data/examples/open_save_close/example_read_only.rb +2 -2
- data/examples/open_save_close/example_rename_cells.rb +3 -3
- data/examples/open_save_close/example_reuse.rb +2 -2
- data/examples/open_save_close/example_simple.rb +3 -4
- data/examples/open_save_close/example_unobtrusively.rb +2 -2
- data/lib/robust_excel_ole/book.rb +84 -78
- data/lib/robust_excel_ole/bookstore.rb +5 -1
- data/lib/robust_excel_ole/excel.rb +165 -188
- data/lib/robust_excel_ole/reo_common.rb +4 -0
- data/lib/robust_excel_ole/sheet.rb +15 -6
- data/lib/robust_excel_ole/version.rb +1 -1
- data/spec/book_spec.rb +104 -77
- data/spec/book_specs/book_close_spec.rb +9 -8
- data/spec/book_specs/book_misc_spec.rb +367 -26
- data/spec/book_specs/book_open_spec.rb +375 -94
- data/spec/book_specs/book_save_spec.rb +137 -112
- data/spec/book_specs/book_sheet_spec.rb +1 -1
- data/spec/book_specs/book_subclass_spec.rb +2 -1
- data/spec/book_specs/book_unobtr_spec.rb +87 -96
- data/spec/bookstore_spec.rb +8 -5
- data/spec/cell_spec.rb +1 -1
- data/spec/data/another_workbook.xls +0 -0
- data/spec/data/book_with_blank.xls +0 -0
- data/spec/data/workbook.xls +0 -0
- data/spec/excel_spec.rb +484 -72
- data/spec/range_spec.rb +1 -1
- data/spec/sheet_spec.rb +47 -1
- metadata +4 -5
@@ -14,7 +14,7 @@ describe Book do
|
|
14
14
|
excel = Excel.new(:reuse => true)
|
15
15
|
open_books = excel == nil ? 0 : excel.Workbooks.Count
|
16
16
|
puts "*** open books *** : #{open_books}" if open_books > 0
|
17
|
-
Excel.
|
17
|
+
Excel.kill_all
|
18
18
|
end
|
19
19
|
|
20
20
|
before do
|
@@ -27,6 +27,9 @@ describe Book do
|
|
27
27
|
@linked_file = @dir + '/workbook_linked.xlsm'
|
28
28
|
@simple_file_xlsm = @dir + '/workbook.xls'
|
29
29
|
@simple_file_xlsx = @dir + '/workbook.xlsx'
|
30
|
+
@simple_file1 = @simple_file
|
31
|
+
@simple_file_other_path1 = @simple_file_other_path
|
32
|
+
@simple_save_file1 = @simple_save_file
|
30
33
|
end
|
31
34
|
|
32
35
|
after do
|
@@ -57,6 +60,14 @@ describe Book do
|
|
57
60
|
@book.close
|
58
61
|
end
|
59
62
|
|
63
|
+
it "should raise error if workbook is not alive" do
|
64
|
+
@book = Book.open(@simple_file)
|
65
|
+
@book.close
|
66
|
+
expect{
|
67
|
+
@book.save
|
68
|
+
}.to raise_error(ExcelErrorSave, "workbook is not alive")
|
69
|
+
end
|
70
|
+
|
60
71
|
end
|
61
72
|
|
62
73
|
context "with open with read only" do
|
@@ -76,15 +87,28 @@ describe Book do
|
|
76
87
|
}
|
77
88
|
end
|
78
89
|
|
79
|
-
context "with
|
80
|
-
|
90
|
+
context "with save_as" do
|
91
|
+
|
92
|
+
it "should save to 'simple_save_file.xls'" do
|
81
93
|
Book.open(@simple_file) do |book|
|
82
|
-
book.save_as(@
|
94
|
+
book.save_as(@simple_save_file1, :if_exists => :overwrite)
|
83
95
|
end
|
96
|
+
File.exist?(@simple_save_file1).should be_true
|
97
|
+
end
|
98
|
+
|
99
|
+
it "should raise error if filename is nil" do
|
100
|
+
book = Book.open(@simple_file)
|
101
|
+
expect{
|
102
|
+
book.save_as(@wrong_name)
|
103
|
+
}.to raise_error(ExcelErrorSave, "filename is nil")
|
84
104
|
end
|
85
105
|
|
86
|
-
it "should
|
87
|
-
|
106
|
+
it "should raise error if workbook is not alive" do
|
107
|
+
book = Book.open(@simple_file)
|
108
|
+
book.close
|
109
|
+
expect{
|
110
|
+
book.save_as(@simple_save_file)
|
111
|
+
}.to raise_error(ExcelErrorSave, "workbook is not alive")
|
88
112
|
end
|
89
113
|
end
|
90
114
|
|
@@ -114,7 +138,7 @@ describe Book do
|
|
114
138
|
context "with blocked by another file" do
|
115
139
|
|
116
140
|
before do
|
117
|
-
@book = Book.open(@
|
141
|
+
@book = Book.open(@simple_file1)
|
118
142
|
@book2 = Book.open(@another_simple_file)
|
119
143
|
end
|
120
144
|
|
@@ -124,84 +148,84 @@ describe Book do
|
|
124
148
|
end
|
125
149
|
|
126
150
|
it "should raise an error with :obstructed => :raise" do
|
127
|
-
File.delete @
|
128
|
-
File.open(@
|
151
|
+
File.delete @simple_file_other_path1 rescue nil
|
152
|
+
File.open(@simple_file_other_path1,"w") do | file |
|
129
153
|
file.puts "garbage"
|
130
154
|
end
|
131
|
-
File.exist?(@
|
155
|
+
File.exist?(@simple_file_other_path1).should be_true
|
132
156
|
expect{
|
133
|
-
@book2.save_as(@
|
157
|
+
@book2.save_as(@simple_file_other_path1, :if_exists => :overwrite, :if_obstructed => :raise)
|
134
158
|
}.to raise_error(ExcelErrorSave, /blocked by another workbook/)
|
135
159
|
end
|
136
160
|
|
137
161
|
it "should close the blocking workbook without saving, and save the current workbook with :if_obstructed => :forget" do
|
138
|
-
File.delete @
|
139
|
-
File.open(@
|
162
|
+
File.delete @simple_file_other_path1 rescue nil
|
163
|
+
File.open(@simple_file_other_path1,"w") do | file |
|
140
164
|
file.puts "garbage"
|
141
165
|
end
|
142
|
-
@book2.save_as(@
|
166
|
+
@book2.save_as(@simple_file_other_path1, :if_exists => :overwrite, :if_obstructed => :forget)
|
143
167
|
@book.should_not be_alive
|
144
|
-
File.exist?(@
|
145
|
-
new_book = Book.open(@
|
168
|
+
File.exist?(@simple_file_other_path1).should be_true
|
169
|
+
new_book = Book.open(@simple_file_other_path1)
|
146
170
|
new_book.should be_a Book
|
147
171
|
new_book.close
|
148
172
|
end
|
149
173
|
|
150
174
|
it "should close the blocking workbook without saving even if it is unsaved with :if_obstructed => :forget" do
|
151
|
-
File.delete @
|
152
|
-
File.open(@
|
175
|
+
File.delete @simple_file_other_path1 rescue nil
|
176
|
+
File.open(@simple_file_other_path1,"w") do | file |
|
153
177
|
file.puts "garbage"
|
154
178
|
end
|
155
179
|
sheet = @book.sheet(1)
|
156
180
|
cell_value = sheet[1,1].value
|
157
181
|
sheet[1,1] = sheet[1,1].value == "foo" ? "bar" : "foo"
|
158
182
|
@book.Saved.should be_false
|
159
|
-
@book2.save_as(@
|
183
|
+
@book2.save_as(@simple_file_other_path1, :if_exists => :overwrite, :if_obstructed => :forget)
|
160
184
|
@book.should_not be_alive
|
161
185
|
@book2.should be_alive
|
162
|
-
File.exist?(@
|
163
|
-
new_book = Book.open(@
|
186
|
+
File.exist?(@simple_file_other_path1).should be_true
|
187
|
+
new_book = Book.open(@simple_file_other_path1)
|
164
188
|
new_book.should be_a Book
|
165
189
|
new_book.close
|
166
|
-
old_book = Book.open(@
|
190
|
+
old_book = Book.open(@simple_file1)
|
167
191
|
old_sheet = old_book.sheet(1)
|
168
192
|
old_sheet[1,1].value.should == cell_value
|
169
193
|
old_book.close
|
170
194
|
end
|
171
195
|
|
172
196
|
it "should save and close the blocking workbook, and save the current workbook with :if_obstructed => :save" do
|
173
|
-
File.delete @
|
174
|
-
File.open(@
|
197
|
+
File.delete @simple_file_other_path1 rescue nil
|
198
|
+
File.open(@simple_file_other_path1,"w") do | file |
|
175
199
|
file.puts "garbage"
|
176
200
|
end
|
177
201
|
sheet = @book.sheet(1)
|
178
202
|
cell_value = sheet[1,1].value
|
179
203
|
sheet[1,1] = sheet[1,1].value == "foo" ? "bar" : "foo"
|
180
204
|
@book.Saved.should be_false
|
181
|
-
@book2.save_as(@
|
205
|
+
@book2.save_as(@simple_file_other_path1, :if_exists => :overwrite, :if_obstructed => :save)
|
182
206
|
@book.should_not be_alive
|
183
207
|
@book2.should be_alive
|
184
|
-
File.exist?(@
|
185
|
-
new_book = Book.open(@
|
208
|
+
File.exist?(@simple_file_other_path1).should be_true
|
209
|
+
new_book = Book.open(@simple_file_other_path1)
|
186
210
|
new_book.should be_a Book
|
187
211
|
new_book.close
|
188
|
-
old_book = Book.open(@
|
212
|
+
old_book = Book.open(@simple_file1)
|
189
213
|
old_sheet = old_book.sheet(1)
|
190
214
|
old_sheet[1,1].value.should_not == cell_value
|
191
215
|
old_book.close
|
192
216
|
end
|
193
217
|
|
194
218
|
it "should close the blocking workbook if it was saved, and save the current workbook with :if_obstructed => :close_if_saved" do
|
195
|
-
File.delete @
|
196
|
-
File.open(@
|
219
|
+
File.delete @simple_file_other_path1 rescue nil
|
220
|
+
File.open(@simple_file_other_path1,"w") do | file |
|
197
221
|
file.puts "garbage"
|
198
222
|
end
|
199
223
|
@book.Saved.should be_true
|
200
|
-
@book2.save_as(@
|
224
|
+
@book2.save_as(@simple_file_other_path1, :if_exists => :overwrite, :if_obstructed => :close_if_saved)
|
201
225
|
@book.should_not be_alive
|
202
226
|
@book2.should be_alive
|
203
|
-
File.exist?(@
|
204
|
-
new_book = Book.open(@
|
227
|
+
File.exist?(@simple_file_other_path1).should be_true
|
228
|
+
new_book = Book.open(@simple_file_other_path1)
|
205
229
|
new_book.should be_a Book
|
206
230
|
new_book.close
|
207
231
|
end
|
@@ -212,48 +236,48 @@ describe Book do
|
|
212
236
|
sheet[1,1] = sheet[1,1].value == "foo" ? "bar" : "foo"
|
213
237
|
@book.Saved.should be_false
|
214
238
|
expect{
|
215
|
-
@book2.save_as(@
|
239
|
+
@book2.save_as(@simple_file_other_path1, :if_exists => :overwrite, :if_obstructed => :close_if_saved)
|
216
240
|
}.to raise_error(ExcelErrorSave, /blocking workbook is unsaved: "workbook.xls"/)
|
217
241
|
end
|
218
242
|
|
219
243
|
it "should raise an error with an invalid option" do
|
220
|
-
File.delete @
|
221
|
-
File.open(@
|
244
|
+
File.delete @simple_file_other_path1 rescue nil
|
245
|
+
File.open(@simple_file_other_path1,"w") do | file |
|
222
246
|
file.puts "garbage"
|
223
247
|
end
|
224
|
-
File.exist?(@
|
248
|
+
File.exist?(@simple_file_other_path1).should be_true
|
225
249
|
expect{
|
226
|
-
@book2.save_as(@
|
250
|
+
@book2.save_as(@simple_file_other_path1, :if_exists => :overwrite, :if_obstructed => :invalid)
|
227
251
|
}.to raise_error(ExcelErrorSave, ":if_obstructed: invalid option: :invalid")
|
228
252
|
end
|
229
253
|
|
230
254
|
it "should raise an error by default" do
|
231
|
-
File.delete @
|
232
|
-
File.open(@
|
255
|
+
File.delete @simple_file_other_path1 rescue nil
|
256
|
+
File.open(@simple_file_other_path1,"w") do | file |
|
233
257
|
file.puts "garbage"
|
234
258
|
end
|
235
|
-
File.exist?(@
|
259
|
+
File.exist?(@simple_file_other_path1).should be_true
|
236
260
|
expect{
|
237
|
-
@book2.save_as(@
|
261
|
+
@book2.save_as(@simple_file_other_path1, :if_exists => :overwrite)
|
238
262
|
}.to raise_error(ExcelErrorSave, /blocked by another workbook/)
|
239
263
|
end
|
240
264
|
|
241
265
|
it "should raise an error if the file does not exist and an workbook with the same name and other path exists" do
|
242
|
-
File.delete @
|
243
|
-
File.exist?(@
|
266
|
+
File.delete @simple_file_other_path1 rescue nil
|
267
|
+
File.exist?(@simple_file_other_path1).should be_false
|
244
268
|
expect{
|
245
|
-
@book2.save_as(@
|
269
|
+
@book2.save_as(@simple_file_other_path1, :if_exists => :overwrite, :if_obstructed => :raise)
|
246
270
|
}.to raise_error(ExcelErrorSave, /blocked by another workbook/)
|
247
271
|
end
|
248
272
|
|
249
273
|
it "should raise an error if the file exists and an workbook with the same name and other path exists" do
|
250
|
-
File.delete @
|
251
|
-
File.open(@
|
274
|
+
File.delete @simple_file_other_path1 rescue nil
|
275
|
+
File.open(@simple_file_other_path1,"w") do | file |
|
252
276
|
file.puts "garbage"
|
253
277
|
end
|
254
|
-
File.exist?(@
|
278
|
+
File.exist?(@simple_file_other_path1).should be_true
|
255
279
|
expect{
|
256
|
-
@book.save_as(@
|
280
|
+
@book.save_as(@simple_file_other_path1, :if_exists => :raise, :if_obstructed => :raise)
|
257
281
|
}.to raise_error(ExcelErrorSave, /file already exists: "workbook.xls"/)
|
258
282
|
end
|
259
283
|
|
@@ -265,7 +289,8 @@ describe Book do
|
|
265
289
|
possible_displayalerts.each do |displayalert_value|
|
266
290
|
context "with displayalerts=#{displayalert_value}" do
|
267
291
|
before do
|
268
|
-
@book = Book.open(@simple_file
|
292
|
+
@book = Book.open(@simple_file)
|
293
|
+
@book.excel.displayalerts = displayalert_value
|
269
294
|
end
|
270
295
|
|
271
296
|
after do
|
@@ -273,23 +298,23 @@ describe Book do
|
|
273
298
|
end
|
274
299
|
|
275
300
|
it "should raise an error if the book is open" do
|
276
|
-
File.delete @
|
277
|
-
FileUtils.copy @simple_file, @
|
278
|
-
book_save = Book.open(@
|
301
|
+
File.delete @simple_save_file1 rescue nil
|
302
|
+
FileUtils.copy @simple_file, @simple_save_file1
|
303
|
+
book_save = Book.open(@simple_save_file1, :excel => :new)
|
279
304
|
expect{
|
280
|
-
@book.save_as(@
|
305
|
+
@book.save_as(@simple_save_file1, :if_exists => :overwrite)
|
281
306
|
}.to raise_error(ExcelErrorSave, "workbook is open and used in Excel")
|
282
307
|
book_save.close
|
283
308
|
end
|
284
309
|
|
285
310
|
it "should save to simple_save_file.xls with :if_exists => :overwrite" do
|
286
|
-
File.delete @
|
287
|
-
File.open(@
|
311
|
+
File.delete @simple_save_file1 rescue nil
|
312
|
+
File.open(@simple_save_file1,"w") do | file |
|
288
313
|
file.puts "garbage"
|
289
314
|
end
|
290
|
-
@book.save_as(@
|
291
|
-
File.exist?(@
|
292
|
-
new_book = Book.open(@
|
315
|
+
@book.save_as(@simple_save_file1, :if_exists => :overwrite)
|
316
|
+
File.exist?(@simple_save_file1).should be_true
|
317
|
+
new_book = Book.open(@simple_save_file1)
|
293
318
|
new_book.should be_a Book
|
294
319
|
new_book.close
|
295
320
|
end
|
@@ -298,8 +323,8 @@ describe Book do
|
|
298
323
|
sheet = @book.sheet(1)
|
299
324
|
sheet[1,1] = sheet[1,1].value == "foo" ? "bar" : "foo"
|
300
325
|
new_value = sheet[1,1].value
|
301
|
-
@book.save_as(@
|
302
|
-
new_book = Book.open(@
|
326
|
+
@book.save_as(@simple_file1, :if_exists => :overwrite)
|
327
|
+
new_book = Book.open(@simple_file1)
|
303
328
|
new_sheet = new_book.sheet(1)
|
304
329
|
new_sheet[1,1].value.should == new_value
|
305
330
|
new_book.close
|
@@ -307,26 +332,26 @@ describe Book do
|
|
307
332
|
|
308
333
|
it "should save to 'simple_save_file.xls' with :if_exists => :raise" do
|
309
334
|
dirname, basename = File.split(@simple_save_file)
|
310
|
-
File.delete @
|
311
|
-
File.open(@
|
335
|
+
File.delete @simple_save_file1 rescue nil
|
336
|
+
File.open(@simple_save_file1,"w") do | file |
|
312
337
|
file.puts "garbage"
|
313
338
|
end
|
314
|
-
File.exist?(@
|
315
|
-
booklength = File.size?(@
|
339
|
+
File.exist?(@simple_save_file1).should be_true
|
340
|
+
booklength = File.size?(@simple_save_file1)
|
316
341
|
expect {
|
317
|
-
@book.save_as(@
|
342
|
+
@book.save_as(@simple_save_file1, :if_exists => :raise)
|
318
343
|
}.to raise_error(ExcelErrorSave, /file already exists: "workbook_save.xls"/)
|
319
|
-
File.exist?(@
|
320
|
-
File.size?(@
|
344
|
+
File.exist?(@simple_save_file1).should be_true
|
345
|
+
File.size?(@simple_save_file1).should == booklength
|
321
346
|
end
|
322
347
|
|
323
348
|
context "with :if_exists => :alert" do
|
324
349
|
before do
|
325
|
-
File.delete @
|
326
|
-
File.open(@
|
350
|
+
File.delete @simple_save_file1 rescue nil
|
351
|
+
File.open(@simple_save_file1,"w") do | file |
|
327
352
|
file.puts "garbage"
|
328
353
|
end
|
329
|
-
@garbage_length = File.size?(@
|
354
|
+
@garbage_length = File.size?(@simple_save_file1)
|
330
355
|
@key_sender = IO.popen 'ruby "' + File.join(File.dirname(__FILE__), '../helpers/key_sender.rb') + '" "Microsoft Excel" ' , "w"
|
331
356
|
end
|
332
357
|
|
@@ -337,11 +362,11 @@ describe Book do
|
|
337
362
|
it "should save if user answers 'yes'" do
|
338
363
|
# "Yes" is to the left of "No", which is the default. --> language independent
|
339
364
|
@key_sender.puts "{left}{enter}" #, :initial_wait => 0.2, :if_target_missing=>"Excel window not found")
|
340
|
-
@book.save_as(@
|
341
|
-
File.exist?(@
|
342
|
-
File.size?(@
|
365
|
+
@book.save_as(@simple_save_file1, :if_exists => :alert)
|
366
|
+
File.exist?(@simple_save_file1).should be_true
|
367
|
+
File.size?(@simple_save_file1).should > @garbage_length
|
343
368
|
@book.excel.DisplayAlerts.should == displayalert_value
|
344
|
-
new_book = Book.open(@
|
369
|
+
new_book = Book.open(@simple_save_file1, :excel => :new)
|
345
370
|
new_book.should be_a Book
|
346
371
|
new_book.close
|
347
372
|
@book.excel.DisplayAlerts.should == displayalert_value
|
@@ -355,10 +380,10 @@ describe Book do
|
|
355
380
|
@key_sender.puts "{enter}"
|
356
381
|
#@key_sender.puts "%{n}" #, :initial_wait => 0.2, :if_target_missing=>"Excel window not found")
|
357
382
|
expect{
|
358
|
-
@book.save_as(@
|
383
|
+
@book.save_as(@simple_save_file1, :if_exists => :alert)
|
359
384
|
}.to raise_error(ExcelErrorSave, "not saved or canceled by user")
|
360
|
-
File.exist?(@
|
361
|
-
File.size?(@
|
385
|
+
File.exist?(@simple_save_file1).should be_true
|
386
|
+
File.size?(@simple_save_file1).should == @garbage_length
|
362
387
|
@book.excel.DisplayAlerts.should == displayalert_value
|
363
388
|
end
|
364
389
|
|
@@ -370,10 +395,10 @@ describe Book do
|
|
370
395
|
@key_sender.puts "{right}{enter}"
|
371
396
|
#@key_sender.puts "%{n}" #, :initial_wait => 0.2, :if_target_missing=>"Excel window not found")
|
372
397
|
expect{
|
373
|
-
@book.save_as(@
|
398
|
+
@book.save_as(@simple_save_file1, :if_exists => :alert)
|
374
399
|
}.to raise_error(ExcelErrorSave, "not saved or canceled by user")
|
375
|
-
File.exist?(@
|
376
|
-
File.size?(@
|
400
|
+
File.exist?(@simple_save_file1).should be_true
|
401
|
+
File.size?(@simple_save_file1).should == @garbage_length
|
377
402
|
@book.excel.DisplayAlerts.should == displayalert_value
|
378
403
|
end
|
379
404
|
|
@@ -381,10 +406,10 @@ describe Book do
|
|
381
406
|
#@key_sender.puts "{left}{enter}" #, :initial_wait => 0.2, :if_target_missing=>"Excel window not found")
|
382
407
|
@book.ole_workbook.Close
|
383
408
|
expect{
|
384
|
-
@book.save_as(@
|
385
|
-
}.to raise_error(ExcelErrorSave, "
|
386
|
-
File.exist?(@
|
387
|
-
File.size?(@
|
409
|
+
@book.save_as(@simple_save_file1, :if_exists => :alert)
|
410
|
+
}.to raise_error(ExcelErrorSave, "workbook is not alive")
|
411
|
+
File.exist?(@simple_save_file1).should be_true
|
412
|
+
File.size?(@simple_save_file1).should == @garbage_length
|
388
413
|
@book.excel.DisplayAlerts.should == displayalert_value
|
389
414
|
end
|
390
415
|
|
@@ -392,8 +417,8 @@ describe Book do
|
|
392
417
|
|
393
418
|
context "with :if_exists => :excel" do
|
394
419
|
before do
|
395
|
-
File.delete @
|
396
|
-
File.open(@
|
420
|
+
File.delete @simple_save_file1 rescue nil
|
421
|
+
File.open(@simple_save_file1,"w") do | file |
|
397
422
|
file.puts "garbage"
|
398
423
|
end
|
399
424
|
@garbage_length = File.size?(@simple_save_file)
|
@@ -407,11 +432,11 @@ describe Book do
|
|
407
432
|
it "should save if user answers 'yes'" do
|
408
433
|
# "Yes" is to the left of "No", which is the default. --> language independent
|
409
434
|
@key_sender.puts "{left}{enter}" #, :initial_wait => 0.2, :if_target_missing=>"Excel window not found")
|
410
|
-
@book.save_as(@
|
411
|
-
File.exist?(@
|
412
|
-
File.size?(@
|
435
|
+
@book.save_as(@simple_save_file1, :if_exists => :excel)
|
436
|
+
File.exist?(@simple_save_file1).should be_true
|
437
|
+
File.size?(@simple_save_file1).should > @garbage_length
|
413
438
|
@book.excel.DisplayAlerts.should == displayalert_value
|
414
|
-
new_book = Book.open(@
|
439
|
+
new_book = Book.open(@simple_save_file1, :excel => :new)
|
415
440
|
new_book.should be_a Book
|
416
441
|
new_book.close
|
417
442
|
@book.excel.DisplayAlerts.should == displayalert_value
|
@@ -425,10 +450,10 @@ describe Book do
|
|
425
450
|
@key_sender.puts "{enter}"
|
426
451
|
#@key_sender.puts "%{n}" #, :initial_wait => 0.2, :if_target_missing=>"Excel window not found")
|
427
452
|
expect{
|
428
|
-
@book.save_as(@
|
453
|
+
@book.save_as(@simple_save_file1, :if_exists => :excel)
|
429
454
|
}.to raise_error(ExcelErrorSave, "not saved or canceled by user")
|
430
|
-
File.exist?(@
|
431
|
-
File.size?(@
|
455
|
+
File.exist?(@simple_save_file1).should be_true
|
456
|
+
File.size?(@simple_save_file1).should == @garbage_length
|
432
457
|
@book.excel.DisplayAlerts.should == displayalert_value
|
433
458
|
end
|
434
459
|
|
@@ -440,10 +465,10 @@ describe Book do
|
|
440
465
|
@key_sender.puts "{right}{enter}"
|
441
466
|
#@key_sender.puts "%{n}" #, :initial_wait => 0.2, :if_target_missing=>"Excel window not found")
|
442
467
|
expect{
|
443
|
-
@book.save_as(@
|
468
|
+
@book.save_as(@simple_save_file1, :if_exists => :excel)
|
444
469
|
}.to raise_error(ExcelErrorSave, "not saved or canceled by user")
|
445
|
-
File.exist?(@
|
446
|
-
File.size?(@
|
470
|
+
File.exist?(@simple_save_file1).should be_true
|
471
|
+
File.size?(@simple_save_file1).should == @garbage_length
|
447
472
|
@book.excel.DisplayAlerts.should == displayalert_value
|
448
473
|
end
|
449
474
|
|
@@ -451,35 +476,35 @@ describe Book do
|
|
451
476
|
#@key_sender.puts "{left}{enter}" #, :initial_wait => 0.2, :if_target_missing=>"Excel window not found")
|
452
477
|
@book.ole_workbook.Close
|
453
478
|
expect{
|
454
|
-
@book.save_as(@
|
455
|
-
}.to raise_error(ExcelErrorSave, "
|
456
|
-
File.exist?(@
|
457
|
-
File.size?(@
|
479
|
+
@book.save_as(@simple_save_file1, :if_exists => :excel)
|
480
|
+
}.to raise_error(ExcelErrorSave, "workbook is not alive")
|
481
|
+
File.exist?(@simple_save_file1).should be_true
|
482
|
+
File.size?(@simple_save_file1).should == @garbage_length
|
458
483
|
@book.excel.DisplayAlerts.should == displayalert_value
|
459
484
|
end
|
460
485
|
|
461
486
|
end
|
462
487
|
|
463
488
|
it "should save to 'simple_save_file.xls' with :if_exists => nil" do
|
464
|
-
dirname, basename = File.split(@
|
465
|
-
File.delete @
|
466
|
-
File.open(@
|
489
|
+
dirname, basename = File.split(@simple_save_file1)
|
490
|
+
File.delete @simple_save_file1 rescue nil
|
491
|
+
File.open(@simple_save_file1,"w") do | file |
|
467
492
|
file.puts "garbage"
|
468
493
|
end
|
469
|
-
File.exist?(@
|
470
|
-
booklength = File.size?(@
|
494
|
+
File.exist?(@simple_save_file1).should be_true
|
495
|
+
booklength = File.size?(@simple_save_file1)
|
471
496
|
expect {
|
472
|
-
@book.save_as(@
|
497
|
+
@book.save_as(@simple_save_file1)
|
473
498
|
}.to raise_error(ExcelErrorSave, /file already exists: "workbook_save.xls"/)
|
474
|
-
File.exist?(@
|
475
|
-
File.size?(@
|
499
|
+
File.exist?(@simple_save_file1).should be_true
|
500
|
+
File.size?(@simple_save_file1).should == booklength
|
476
501
|
end
|
477
502
|
|
478
503
|
it "should save to 'simple_save_file.xls' with :if_exists => :invalid" do
|
479
|
-
File.delete @
|
480
|
-
@book.save_as(@
|
504
|
+
File.delete @simple_save_file1 rescue nil
|
505
|
+
@book.save_as(@simple_save_file1)
|
481
506
|
expect {
|
482
|
-
@book.save_as(@
|
507
|
+
@book.save_as(@simple_save_file1, :if_exists => :invalid)
|
483
508
|
}.to raise_error(ExcelErrorSave, ':if_exists: invalid option: :invalid')
|
484
509
|
end
|
485
510
|
end
|