robust_excel_ole 1.1.5 → 1.1.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Changelog +6 -0
- data/README.rdoc +2 -2
- data/docs/README_excel.rdoc +2 -3
- data/docs/README_open.rdoc +8 -12
- data/docs/README_ranges.rdoc +21 -9
- data/docs/README_sheet.rdoc +1 -1
- data/lib/robust_excel_ole/book.rb +3 -23
- data/lib/robust_excel_ole/excel.rb +2 -15
- data/lib/robust_excel_ole/reo_common.rb +11 -7
- data/lib/robust_excel_ole/sheet.rb +36 -15
- data/lib/robust_excel_ole/version.rb +1 -1
- data/robust_excel_ole.gemspec +1 -1
- data/spec/book_spec.rb +1 -1
- data/spec/book_specs/book_close_spec.rb +3 -3
- data/spec/book_specs/book_misc_spec.rb +25 -1
- data/spec/book_specs/book_open_spec.rb +299 -5
- data/spec/book_specs/book_sheet_spec.rb +1 -1
- data/spec/book_specs/book_unobtr_spec.rb +275 -35
- data/spec/data/another_workbook.xls +0 -0
- data/spec/data/different_workbook.xls +0 -0
- data/spec/data/workbook.xls +0 -0
- data/spec/excel_spec.rb +118 -5
- data/spec/helpers/key_sender.rb +2 -2
- data/spec/reo_common_spec.rb +0 -4
- data/spec/sheet_spec.rb +32 -0
- data/spec/spec_helper.rb +3 -0
- metadata +3 -21
- data/spec/ruby1.8.6_rspec2.14/book_spec.rb +0 -1421
- data/spec/ruby1.8.6_rspec2.14/book_specs/book_all_spec.rb +0 -22
- data/spec/ruby1.8.6_rspec2.14/book_specs/book_close_spec.rb +0 -252
- data/spec/ruby1.8.6_rspec2.14/book_specs/book_misc_spec.rb +0 -1070
- data/spec/ruby1.8.6_rspec2.14/book_specs/book_open_spec.rb +0 -1855
- data/spec/ruby1.8.6_rspec2.14/book_specs/book_save_spec.rb +0 -514
- data/spec/ruby1.8.6_rspec2.14/book_specs/book_sheet_spec.rb +0 -395
- data/spec/ruby1.8.6_rspec2.14/book_specs/book_subclass_spec.rb +0 -51
- data/spec/ruby1.8.6_rspec2.14/book_specs/book_unobtr_spec.rb +0 -1737
- data/spec/ruby1.8.6_rspec2.14/bookstore_spec.rb +0 -495
- data/spec/ruby1.8.6_rspec2.14/cell_spec.rb +0 -76
- data/spec/ruby1.8.6_rspec2.14/cygwin_spec.rb +0 -42
- data/spec/ruby1.8.6_rspec2.14/excel_spec.rb +0 -1820
- data/spec/ruby1.8.6_rspec2.14/general_spec.rb +0 -212
- data/spec/ruby1.8.6_rspec2.14/range_spec.rb +0 -131
- data/spec/ruby1.8.6_rspec2.14/reo_common_spec.rb +0 -130
- data/spec/ruby1.8.6_rspec2.14/sheet_spec.rb +0 -663
- data/spec/ruby1.8.6_rspec2.14/spec_helper.rb +0 -35
@@ -1,514 +0,0 @@
|
|
1
|
-
# -*- coding: utf-8 -*-
|
2
|
-
|
3
|
-
require File.join(File.dirname(__FILE__), './../spec_helper')
|
4
|
-
|
5
|
-
|
6
|
-
$VERBOSE = nil
|
7
|
-
|
8
|
-
include RobustExcelOle
|
9
|
-
include General
|
10
|
-
|
11
|
-
describe Book do
|
12
|
-
|
13
|
-
before(:all) do
|
14
|
-
excel = Excel.new(:reuse => true)
|
15
|
-
open_books = excel == nil ? 0 : excel.Workbooks.Count
|
16
|
-
puts "*** open books *** : #{open_books}" if open_books > 0
|
17
|
-
Excel.kill_all
|
18
|
-
end
|
19
|
-
|
20
|
-
before do
|
21
|
-
@dir = create_tmpdir
|
22
|
-
@simple_file = @dir + '/workbook.xls'
|
23
|
-
@simple_save_file = @dir + '/workbook_save.xls'
|
24
|
-
@different_file = @dir + '/different_workbook.xls'
|
25
|
-
@simple_file_other_path = @dir + '/more_data/workbook.xls'
|
26
|
-
@another_simple_file_other_path = @dir + '/more_data/another_workbook.xls'
|
27
|
-
@another_simple_file = @dir + '/another_workbook.xls'
|
28
|
-
@linked_file = @dir + '/workbook_linked.xlsm'
|
29
|
-
@simple_file_xlsm = @dir + '/workbook.xls'
|
30
|
-
@simple_file_xlsx = @dir + '/workbook.xlsx'
|
31
|
-
@simple_file1 = @simple_file
|
32
|
-
@simple_file_other_path1 = @simple_file_other_path
|
33
|
-
@another_simple_file_other_path1 = @another_simple_file_other_path
|
34
|
-
@simple_save_file1 = @simple_save_file
|
35
|
-
end
|
36
|
-
|
37
|
-
after do
|
38
|
-
Excel.kill_all
|
39
|
-
# rm_tmp(@dir)
|
40
|
-
end
|
41
|
-
|
42
|
-
describe "save" do
|
43
|
-
|
44
|
-
context "with simple save" do
|
45
|
-
|
46
|
-
it "should save for a file opened without :read_only" do
|
47
|
-
@book = Book.open(@simple_file)
|
48
|
-
@book.add_sheet(@sheet, :as => 'a_name')
|
49
|
-
@new_sheet_count = @book.ole_workbook.Worksheets.Count
|
50
|
-
expect {
|
51
|
-
@book.save
|
52
|
-
}.to_not raise_error
|
53
|
-
@book.ole_workbook.Worksheets.Count.should == @new_sheet_count
|
54
|
-
@book.close
|
55
|
-
end
|
56
|
-
|
57
|
-
it "should raise error with read_only" do
|
58
|
-
@book = Book.open(@simple_file, :read_only => true)
|
59
|
-
expect {
|
60
|
-
@book.save
|
61
|
-
}.to raise_error(WorkbookReadOnly, "Not opened for writing (opened with :read_only option)")
|
62
|
-
@book.close
|
63
|
-
end
|
64
|
-
|
65
|
-
it "should raise error if workbook is not alive" do
|
66
|
-
@book = Book.open(@simple_file)
|
67
|
-
@book.close
|
68
|
-
expect{
|
69
|
-
@book.save
|
70
|
-
}.to raise_error(ObjectNotAlive, "workbook is not alive")
|
71
|
-
end
|
72
|
-
|
73
|
-
end
|
74
|
-
|
75
|
-
context "with open with read only" do
|
76
|
-
before do
|
77
|
-
@book = Book.open(@simple_file, :read_only => true)
|
78
|
-
end
|
79
|
-
|
80
|
-
after do
|
81
|
-
@book.close
|
82
|
-
end
|
83
|
-
|
84
|
-
it {
|
85
|
-
expect {
|
86
|
-
@book.save_as(@simple_file)
|
87
|
-
}.to raise_error(WorkbookReadOnly,
|
88
|
-
"Not opened for writing (opened with :read_only option)")
|
89
|
-
}
|
90
|
-
end
|
91
|
-
|
92
|
-
context "with save_as" do
|
93
|
-
|
94
|
-
it "should save to 'simple_save_file.xls'" do
|
95
|
-
Book.open(@simple_file) do |book|
|
96
|
-
book.save_as(@simple_save_file1, :if_exists => :overwrite)
|
97
|
-
end
|
98
|
-
File.exist?(@simple_save_file1).should be_true
|
99
|
-
end
|
100
|
-
|
101
|
-
it "should raise error if filename is nil" do
|
102
|
-
book = Book.open(@simple_file)
|
103
|
-
expect{
|
104
|
-
book.save_as(@wrong_name)
|
105
|
-
}.to raise_error(FileNameNotGiven, "filename is nil")
|
106
|
-
end
|
107
|
-
|
108
|
-
it "should raise error if workbook is not alive" do
|
109
|
-
book = Book.open(@simple_file)
|
110
|
-
book.close
|
111
|
-
expect{
|
112
|
-
book.save_as(@simple_save_file)
|
113
|
-
}.to raise_error(ObjectNotAlive, "workbook is not alive")
|
114
|
-
end
|
115
|
-
end
|
116
|
-
|
117
|
-
context "with different extensions" do
|
118
|
-
before do
|
119
|
-
@book = Book.open(@simple_file)
|
120
|
-
end
|
121
|
-
|
122
|
-
after do
|
123
|
-
@book.close
|
124
|
-
end
|
125
|
-
|
126
|
-
possible_extensions = ['xls', 'xlsm', 'xlsx']
|
127
|
-
possible_extensions.each do |extensions_value|
|
128
|
-
it "should save to 'simple_save_file.#{extensions_value}'" do
|
129
|
-
simple_save_file = @dir + '/simple_save_file.' + extensions_value
|
130
|
-
File.delete simple_save_file rescue nil
|
131
|
-
@book.save_as(simple_save_file, :if_exists => :overwrite)
|
132
|
-
File.exist?(simple_save_file).should be_true
|
133
|
-
new_book = Book.open(simple_save_file)
|
134
|
-
new_book.should be_a Book
|
135
|
-
new_book.close
|
136
|
-
end
|
137
|
-
end
|
138
|
-
end
|
139
|
-
|
140
|
-
context "with saving with the same name in another directory" do
|
141
|
-
|
142
|
-
before do
|
143
|
-
@book = Book.open(@simple_file1)
|
144
|
-
end
|
145
|
-
|
146
|
-
it "should save with the same name in another directory" do
|
147
|
-
File.delete @simple_file_other_path1 rescue nil
|
148
|
-
File.open(@simple_file_other_path1,"w") do | file |
|
149
|
-
file.puts "garbage"
|
150
|
-
end
|
151
|
-
File.exist?(@simple_file_other_path1).should be_true
|
152
|
-
@book.save_as(@simple_file_other_path1, :if_exists => :overwrite, :if_obstructed => :forget)
|
153
|
-
end
|
154
|
-
|
155
|
-
end
|
156
|
-
|
157
|
-
context "with blocked by another file" do
|
158
|
-
|
159
|
-
before do
|
160
|
-
@book = Book.open(@simple_file1)
|
161
|
-
@book2 = Book.open(@another_simple_file)
|
162
|
-
end
|
163
|
-
|
164
|
-
after do
|
165
|
-
@book.close(:if_unsaved => :forget)
|
166
|
-
@book2.close(:if_unsaved => :forget)
|
167
|
-
end
|
168
|
-
|
169
|
-
it "should raise an error with :obstructed => :raise" do
|
170
|
-
File.delete @simple_file_other_path1 rescue nil
|
171
|
-
File.open(@simple_file_other_path1,"w") do | file |
|
172
|
-
file.puts "garbage"
|
173
|
-
end
|
174
|
-
File.exist?(@simple_file_other_path1).should be_true
|
175
|
-
expect{
|
176
|
-
@book2.save_as(@simple_file_other_path1, :if_exists => :overwrite, :if_obstructed => :raise)
|
177
|
-
}.to raise_error(WorkbookBlocked, /blocked by another workbook/)
|
178
|
-
end
|
179
|
-
|
180
|
-
it "should close the blocking workbook without saving, and save the current workbook with :if_obstructed => :forget" do
|
181
|
-
File.delete @simple_file_other_path1 rescue nil
|
182
|
-
File.open(@simple_file_other_path1,"w") do | file |
|
183
|
-
file.puts "garbage"
|
184
|
-
end
|
185
|
-
@book2.save_as(@simple_file_other_path1, :if_exists => :overwrite, :if_obstructed => :forget)
|
186
|
-
@book.should_not be_alive
|
187
|
-
File.exist?(@simple_file_other_path1).should be_true
|
188
|
-
new_book = Book.open(@simple_file_other_path1)
|
189
|
-
new_book.should be_a Book
|
190
|
-
new_book.close
|
191
|
-
end
|
192
|
-
|
193
|
-
it "should close the blocking workbook without saving even if it is unsaved with :if_obstructed => :forget" do
|
194
|
-
File.delete @simple_file_other_path1 rescue nil
|
195
|
-
File.open(@simple_file_other_path1,"w") do | file |
|
196
|
-
file.puts "garbage"
|
197
|
-
end
|
198
|
-
sheet = @book.sheet(1)
|
199
|
-
cell_value = sheet[1,1].value
|
200
|
-
sheet[1,1] = sheet[1,1].value == "foo" ? "bar" : "foo"
|
201
|
-
@book.Saved.should be_false
|
202
|
-
@book2.save_as(@simple_file_other_path1, :if_exists => :overwrite, :if_obstructed => :forget)
|
203
|
-
@book.should_not be_alive
|
204
|
-
@book2.should be_alive
|
205
|
-
File.exist?(@simple_file_other_path1).should be_true
|
206
|
-
new_book = Book.open(@simple_file_other_path1)
|
207
|
-
new_book.should be_a Book
|
208
|
-
new_book.close
|
209
|
-
old_book = Book.open(@simple_file1)
|
210
|
-
old_sheet = old_book.sheet(1)
|
211
|
-
old_sheet[1,1].value.should == cell_value
|
212
|
-
old_book.close
|
213
|
-
end
|
214
|
-
|
215
|
-
it "should save and close the blocking workbook, and save the current workbook with :if_obstructed => :save" do
|
216
|
-
File.delete @simple_file_other_path1 rescue nil
|
217
|
-
File.open(@simple_file_other_path1,"w") do | file |
|
218
|
-
file.puts "garbage"
|
219
|
-
end
|
220
|
-
sheet = @book.sheet(1)
|
221
|
-
cell_value = sheet[1,1].value
|
222
|
-
sheet[1,1] = sheet[1,1].value == "foo" ? "bar" : "foo"
|
223
|
-
@book.Saved.should be_false
|
224
|
-
@book2.save_as(@simple_file_other_path1, :if_exists => :overwrite, :if_obstructed => :save)
|
225
|
-
@book.should_not be_alive
|
226
|
-
@book2.should be_alive
|
227
|
-
File.exist?(@simple_file_other_path1).should be_true
|
228
|
-
new_book = Book.open(@simple_file_other_path1)
|
229
|
-
new_book.should be_a Book
|
230
|
-
new_book.close
|
231
|
-
old_book = Book.open(@simple_file1)
|
232
|
-
old_sheet = old_book.sheet(1)
|
233
|
-
old_sheet[1,1].value.should_not == cell_value
|
234
|
-
old_book.close
|
235
|
-
end
|
236
|
-
|
237
|
-
it "should close the blocking workbook if it was saved, and save the current workbook with :if_obstructed => :close_if_saved" do
|
238
|
-
File.delete @simple_file_other_path1 rescue nil
|
239
|
-
File.open(@simple_file_other_path1,"w") do | file |
|
240
|
-
file.puts "garbage"
|
241
|
-
end
|
242
|
-
@book.Saved.should be_true
|
243
|
-
@book2.save_as(@simple_file_other_path1, :if_exists => :overwrite, :if_obstructed => :close_if_saved)
|
244
|
-
@book.should_not be_alive
|
245
|
-
@book2.should be_alive
|
246
|
-
File.exist?(@simple_file_other_path1).should be_true
|
247
|
-
new_book = Book.open(@simple_file_other_path1)
|
248
|
-
new_book.should be_a Book
|
249
|
-
new_book.close
|
250
|
-
end
|
251
|
-
|
252
|
-
it "should raise an error if the blocking workbook was unsaved with :if_obstructed => :close_if_saved" do
|
253
|
-
sheet = @book.sheet(1)
|
254
|
-
cell_value = sheet[1,1].value
|
255
|
-
sheet[1,1] = sheet[1,1].value == "foo" ? "bar" : "foo"
|
256
|
-
@book.Saved.should be_false
|
257
|
-
expect{
|
258
|
-
@book2.save_as(@simple_file_other_path1, :if_exists => :overwrite, :if_obstructed => :close_if_saved)
|
259
|
-
}.to raise_error(WorkbookBlocked, /blocking workbook is unsaved: "workbook.xls"/)
|
260
|
-
end
|
261
|
-
|
262
|
-
it "should raise an error with an invalid option" do
|
263
|
-
File.delete @simple_file_other_path1 rescue nil
|
264
|
-
File.open(@simple_file_other_path1,"w") do | file |
|
265
|
-
file.puts "garbage"
|
266
|
-
end
|
267
|
-
File.exist?(@simple_file_other_path1).should be_true
|
268
|
-
expect{
|
269
|
-
@book2.save_as(@simple_file_other_path1, :if_exists => :overwrite, :if_obstructed => :invalid)
|
270
|
-
}.to raise_error(OptionInvalid, ":if_obstructed: invalid option: :invalid")
|
271
|
-
end
|
272
|
-
|
273
|
-
it "should raise an error by default" do
|
274
|
-
File.delete @simple_file_other_path1 rescue nil
|
275
|
-
File.open(@simple_file_other_path1,"w") do | file |
|
276
|
-
file.puts "garbage"
|
277
|
-
end
|
278
|
-
File.exist?(@simple_file_other_path1).should be_true
|
279
|
-
expect{
|
280
|
-
@book2.save_as(@simple_file_other_path1, :if_exists => :overwrite)
|
281
|
-
}.to raise_error(WorkbookBlocked, /blocked by another workbook/)
|
282
|
-
end
|
283
|
-
|
284
|
-
it "should raise an error if the file does not exist and an workbook with the same name and other path exists" do
|
285
|
-
File.delete @simple_file_other_path1 rescue nil
|
286
|
-
File.exist?(@simple_file_other_path1).should be_false
|
287
|
-
expect{
|
288
|
-
@book2.save_as(@simple_file_other_path1, :if_exists => :overwrite, :if_obstructed => :raise)
|
289
|
-
}.to raise_error(WorkbookBlocked, /blocked by another workbook/)
|
290
|
-
end
|
291
|
-
|
292
|
-
it "should raise an error if the file exists and an workbook with the same name and other path exists" do
|
293
|
-
File.delete @simple_file_other_path1 rescue nil
|
294
|
-
File.open(@simple_file_other_path1,"w") do | file |
|
295
|
-
file.puts "garbage"
|
296
|
-
end
|
297
|
-
File.exist?(@simple_file_other_path1).should be_true
|
298
|
-
expect{
|
299
|
-
@book.save_as(@simple_file_other_path1, :if_exists => :raise, :if_obstructed => :raise)
|
300
|
-
}.to raise_error(FileAlreadyExists, /file already exists: "workbook.xls"/)
|
301
|
-
end
|
302
|
-
|
303
|
-
end
|
304
|
-
|
305
|
-
|
306
|
-
# options :overwrite, :raise, :excel, no option, invalid option
|
307
|
-
possible_displayalerts = [true, false]
|
308
|
-
possible_displayalerts.each do |displayalert_value|
|
309
|
-
context "with displayalerts=#{displayalert_value}" do
|
310
|
-
before do
|
311
|
-
@book = Book.open(@simple_file)
|
312
|
-
@book.excel.displayalerts = displayalert_value
|
313
|
-
end
|
314
|
-
|
315
|
-
after do
|
316
|
-
@book.close
|
317
|
-
end
|
318
|
-
|
319
|
-
it "should raise an error if the book is open" do
|
320
|
-
File.delete @simple_save_file1 rescue nil
|
321
|
-
FileUtils.copy @simple_file, @simple_save_file1
|
322
|
-
book_save = Book.open(@simple_save_file1, :excel => :new)
|
323
|
-
expect{
|
324
|
-
@book.save_as(@simple_save_file1, :if_exists => :overwrite)
|
325
|
-
}.to raise_error(WorkbookBeingUsed, "workbook is open and used in Excel")
|
326
|
-
book_save.close
|
327
|
-
end
|
328
|
-
|
329
|
-
it "should save to simple_save_file.xls with :if_exists => :overwrite" do
|
330
|
-
File.delete @simple_save_file1 rescue nil
|
331
|
-
File.open(@simple_save_file1,"w") do | file |
|
332
|
-
file.puts "garbage"
|
333
|
-
end
|
334
|
-
@book.save_as(@simple_save_file1, :if_exists => :overwrite)
|
335
|
-
File.exist?(@simple_save_file1).should be_true
|
336
|
-
new_book = Book.open(@simple_save_file1)
|
337
|
-
new_book.should be_a Book
|
338
|
-
new_book.close
|
339
|
-
end
|
340
|
-
|
341
|
-
it "should simple save if file name is equal to the old one with :if_exists => :overwrite" do
|
342
|
-
sheet = @book.sheet(1)
|
343
|
-
sheet[1,1] = sheet[1,1].value == "foo" ? "bar" : "foo"
|
344
|
-
new_value = sheet[1,1].value
|
345
|
-
@book.save_as(@simple_file1, :if_exists => :overwrite)
|
346
|
-
new_book = Book.open(@simple_file1)
|
347
|
-
new_sheet = new_book.sheet(1)
|
348
|
-
new_sheet[1,1].value.should == new_value
|
349
|
-
new_book.close
|
350
|
-
end
|
351
|
-
|
352
|
-
it "should save to 'simple_save_file.xls' with :if_exists => :raise" do
|
353
|
-
dirname, basename = File.split(@simple_save_file)
|
354
|
-
File.delete @simple_save_file1 rescue nil
|
355
|
-
File.open(@simple_save_file1,"w") do | file |
|
356
|
-
file.puts "garbage"
|
357
|
-
end
|
358
|
-
File.exist?(@simple_save_file1).should be_true
|
359
|
-
booklength = File.size?(@simple_save_file1)
|
360
|
-
expect {
|
361
|
-
@book.save_as(@simple_save_file1, :if_exists => :raise)
|
362
|
-
}.to raise_error(FileAlreadyExists, /file already exists: "workbook_save.xls"/)
|
363
|
-
File.exist?(@simple_save_file1).should be_true
|
364
|
-
File.size?(@simple_save_file1).should == booklength
|
365
|
-
end
|
366
|
-
|
367
|
-
context "with :if_exists => :alert" do
|
368
|
-
before do
|
369
|
-
File.delete @simple_save_file1 rescue nil
|
370
|
-
File.open(@simple_save_file1,"w") do | file |
|
371
|
-
file.puts "garbage"
|
372
|
-
end
|
373
|
-
@garbage_length = File.size?(@simple_save_file1)
|
374
|
-
@key_sender = IO.popen 'ruby "' + File.join(File.dirname(__FILE__), '../helpers/key_sender.rb') + '" "Microsoft Excel" ' , "w"
|
375
|
-
end
|
376
|
-
|
377
|
-
after do
|
378
|
-
@key_sender.close
|
379
|
-
end
|
380
|
-
|
381
|
-
it "should save if user answers 'yes'" do
|
382
|
-
# "Yes" is to the left of "No", which is the default. --> language independent
|
383
|
-
@key_sender.puts "{left}{enter}" #, :initial_wait => 0.2, :if_target_missing=>"Excel window not found")
|
384
|
-
@book.save_as(@simple_save_file1, :if_exists => :alert)
|
385
|
-
File.exist?(@simple_save_file1).should be_true
|
386
|
-
File.size?(@simple_save_file1).should > @garbage_length
|
387
|
-
@book.excel.DisplayAlerts.should == displayalert_value
|
388
|
-
new_book = Book.open(@simple_save_file1, :excel => :new)
|
389
|
-
new_book.should be_a Book
|
390
|
-
new_book.close
|
391
|
-
@book.excel.DisplayAlerts.should == displayalert_value
|
392
|
-
end
|
393
|
-
|
394
|
-
it "should not save if user answers 'no'" do
|
395
|
-
# Just give the "Enter" key, because "No" is the default. --> language independent
|
396
|
-
# strangely, in the "no" case, the question will sometimes be repeated three times
|
397
|
-
@key_sender.puts "{enter}"
|
398
|
-
@key_sender.puts "{enter}"
|
399
|
-
@key_sender.puts "{enter}"
|
400
|
-
#@key_sender.puts "%{n}" #, :initial_wait => 0.2, :if_target_missing=>"Excel window not found")
|
401
|
-
@book.save_as(@simple_save_file1, :if_exists => :alert)
|
402
|
-
File.exist?(@simple_save_file1).should be_true
|
403
|
-
File.size?(@simple_save_file1).should == @garbage_length
|
404
|
-
@book.excel.DisplayAlerts.should == displayalert_value
|
405
|
-
end
|
406
|
-
|
407
|
-
it "should not save if user answers 'cancel'" do
|
408
|
-
# 'Cancel' is right from 'yes'
|
409
|
-
# strangely, in the "no" case, the question will sometimes be repeated three times
|
410
|
-
@key_sender.puts "{right}{enter}"
|
411
|
-
@key_sender.puts "{right}{enter}"
|
412
|
-
@key_sender.puts "{right}{enter}"
|
413
|
-
#@key_sender.puts "%{n}" #, :initial_wait => 0.2, :if_target_missing=>"Excel window not found")
|
414
|
-
@book.save_as(@simple_save_file1, :if_exists => :alert)
|
415
|
-
File.exist?(@simple_save_file1).should be_true
|
416
|
-
File.size?(@simple_save_file1).should == @garbage_length
|
417
|
-
@book.excel.DisplayAlerts.should == displayalert_value
|
418
|
-
end
|
419
|
-
|
420
|
-
end
|
421
|
-
|
422
|
-
context "with :if_exists => :excel" do
|
423
|
-
before do
|
424
|
-
File.delete @simple_save_file1 rescue nil
|
425
|
-
File.open(@simple_save_file1,"w") do | file |
|
426
|
-
file.puts "garbage"
|
427
|
-
end
|
428
|
-
@garbage_length = File.size?(@simple_save_file)
|
429
|
-
@key_sender = IO.popen 'ruby "' + File.join(File.dirname(__FILE__), '../helpers/key_sender.rb') + '" "Microsoft Excel" ' , "w"
|
430
|
-
end
|
431
|
-
|
432
|
-
after do
|
433
|
-
@key_sender.close
|
434
|
-
end
|
435
|
-
|
436
|
-
it "should save if user answers 'yes'" do
|
437
|
-
# "Yes" is to the left of "No", which is the default. --> language independent
|
438
|
-
@key_sender.puts "{left}{enter}" #, :initial_wait => 0.2, :if_target_missing=>"Excel window not found")
|
439
|
-
@book.save_as(@simple_save_file1, :if_exists => :excel)
|
440
|
-
File.exist?(@simple_save_file1).should be_true
|
441
|
-
File.size?(@simple_save_file1).should > @garbage_length
|
442
|
-
@book.excel.DisplayAlerts.should == displayalert_value
|
443
|
-
new_book = Book.open(@simple_save_file1, :excel => :new)
|
444
|
-
new_book.should be_a Book
|
445
|
-
new_book.close
|
446
|
-
@book.excel.DisplayAlerts.should == displayalert_value
|
447
|
-
end
|
448
|
-
|
449
|
-
it "should not save if user answers 'no'" do
|
450
|
-
# Just give the "Enter" key, because "No" is the default. --> language independent
|
451
|
-
# strangely, in the "no" case, the question will sometimes be repeated three times
|
452
|
-
@key_sender.puts "{enter}"
|
453
|
-
@key_sender.puts "{enter}"
|
454
|
-
@key_sender.puts "{enter}"
|
455
|
-
#@key_sender.puts "%{n}" #, :initial_wait => 0.2, :if_target_missing=>"Excel window not found")
|
456
|
-
@book.save_as(@simple_save_file1, :if_exists => :excel)
|
457
|
-
File.exist?(@simple_save_file1).should be_true
|
458
|
-
File.size?(@simple_save_file1).should == @garbage_length
|
459
|
-
@book.excel.DisplayAlerts.should == displayalert_value
|
460
|
-
end
|
461
|
-
|
462
|
-
it "should not save if user answers 'cancel'" do
|
463
|
-
# 'Cancel' is right from 'yes'
|
464
|
-
# strangely, in the "no" case, the question will sometimes be repeated three times
|
465
|
-
@key_sender.puts "{right}{enter}"
|
466
|
-
@key_sender.puts "{right}{enter}"
|
467
|
-
@key_sender.puts "{right}{enter}"
|
468
|
-
#@key_sender.puts "%{n}" #, :initial_wait => 0.2, :if_target_missing=>"Excel window not found")
|
469
|
-
@book.save_as(@simple_save_file1, :if_exists => :excel)
|
470
|
-
File.exist?(@simple_save_file1).should be_true
|
471
|
-
File.size?(@simple_save_file1).should == @garbage_length
|
472
|
-
@book.excel.DisplayAlerts.should == displayalert_value
|
473
|
-
end
|
474
|
-
|
475
|
-
it "should report save errors and leave DisplayAlerts unchanged" do
|
476
|
-
#@key_sender.puts "{left}{enter}" #, :initial_wait => 0.2, :if_target_missing=>"Excel window not found")
|
477
|
-
@book.ole_workbook.Close
|
478
|
-
expect{
|
479
|
-
@book.save_as(@simple_save_file1, :if_exists => :excel)
|
480
|
-
}.to raise_error(ObjectNotAlive, "workbook is not alive")
|
481
|
-
File.exist?(@simple_save_file1).should be_true
|
482
|
-
File.size?(@simple_save_file1).should == @garbage_length
|
483
|
-
@book.excel.DisplayAlerts.should == displayalert_value
|
484
|
-
end
|
485
|
-
|
486
|
-
end
|
487
|
-
|
488
|
-
it "should save to 'simple_save_file.xls' with :if_exists => nil" do
|
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 |
|
492
|
-
file.puts "garbage"
|
493
|
-
end
|
494
|
-
File.exist?(@simple_save_file1).should be_true
|
495
|
-
booklength = File.size?(@simple_save_file1)
|
496
|
-
expect {
|
497
|
-
@book.save_as(@simple_save_file1)
|
498
|
-
}.to raise_error(FileAlreadyExists, /file already exists: "workbook_save.xls"/)
|
499
|
-
File.exist?(@simple_save_file1).should be_true
|
500
|
-
File.size?(@simple_save_file1).should == booklength
|
501
|
-
end
|
502
|
-
|
503
|
-
it "should save to 'simple_save_file.xls' with :if_exists => :invalid" do
|
504
|
-
File.delete @simple_save_file1 rescue nil
|
505
|
-
@book.save_as(@simple_save_file1)
|
506
|
-
expect {
|
507
|
-
@book.save_as(@simple_save_file1, :if_exists => :invalid)
|
508
|
-
}.to raise_error(OptionInvalid, ':if_exists: invalid option: :invalid')
|
509
|
-
end
|
510
|
-
end
|
511
|
-
end
|
512
|
-
end
|
513
|
-
end
|
514
|
-
|