robust_excel_ole 1.0.2 → 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/Changelog CHANGED
@@ -1,6 +1,8 @@
1
1
  # Change Log
2
2
  All notable changes to this project will be documented in this file.
3
3
 
4
+ ## [1.0.3] - 2017-08-27
5
+
4
6
  ## [1.0.2] - 2017-07-26
5
7
 
6
8
  ### Added
@@ -9,6 +9,7 @@ It supports Excel 2010.
9
9
 
10
10
  RobustExcelOle works by sending VBA methods via Win32OLE.
11
11
  Moreover, it implements a management system and keeps track of Excel files and Excel instances.
12
+ The tool is optimised with help of rcov.
12
13
 
13
14
  == Requirements
14
15
 
@@ -9,6 +9,7 @@ It supports Excel 2010.
9
9
 
10
10
  RobustExcelOle works by sending VBA methods via Win32OLE.
11
11
  Moreover, it implements a management system and keeps track of Excel files and Excel instances.
12
+ The tool is optimised with help of rcov.
12
13
 
13
14
  == Requirements
14
15
 
@@ -126,8 +126,9 @@ module RobustExcelOle
126
126
  return book
127
127
  end
128
128
  end
129
+ else
130
+ super
129
131
  end
130
- super
131
132
  end
132
133
 
133
134
  # creates a new Book object, if a file name is given
@@ -343,7 +344,7 @@ module RobustExcelOle
343
344
  # for Excel2007: for option :if_unsaved => :alert and user cancels: this error appears?
344
345
  # if yes: distinguish these events
345
346
  #raise
346
- trace "WIN32OLERuntimeError: #{msg.message}"
347
+ # trace "WIN32OLERuntimeError: #{msg.message}"
347
348
  end
348
349
  begin
349
350
  # workaround for bug in Excel 2010: workbook.Open does not always return the workbook when given file name
@@ -437,8 +438,8 @@ module RobustExcelOle
437
438
  else
438
439
  close_workbook
439
440
  end
440
- trace "close: canceled by user" if alive? &&
441
- (opts[:if_unsaved] == :alert || opts[:if_unsaved] == :excel) && (not @ole_workbook.Saved)
441
+ #trace "close: canceled by user" if alive? &&
442
+ # (opts[:if_unsaved] == :alert || opts[:if_unsaved] == :excel) && (not @ole_workbook.Saved)
442
443
  end
443
444
 
444
445
  private
@@ -645,7 +646,7 @@ module RobustExcelOle
645
646
  bookstore.store(self)
646
647
  rescue WIN32OLERuntimeError => msg
647
648
  if msg.message =~ /SaveAs/ and msg.message =~ /Workbook/ then
648
- trace "save: canceled by user" if options[:if_exists] == :alert || options[:if_exists] == :excel
649
+ # trace "save: canceled by user" if options[:if_exists] == :alert || options[:if_exists] == :excel
649
650
  # another possible semantics. raise WorkbookError, "could not save Workbook"
650
651
  else
651
652
  raise UnexpectedError, "unknown WIN32OELERuntimeError:\n#{msg.message}"
@@ -686,11 +687,7 @@ module RobustExcelOle
686
687
  after_or_before, base_sheet = opts.to_a.first || [:after, last_sheet]
687
688
  sheet.Copy({ after_or_before.to_s => base_sheet.worksheet })
688
689
  new_sheet = sheet_class.new(@excel.Activesheet)
689
- begin
690
- new_sheet.name = new_sheet_name if new_sheet_name
691
- rescue WIN32OLERuntimeError => msg
692
- msg.message =~ /800A03EC/ ? raise(NameAlreadyExists, "sheet name already exists") : raise(UnexpectedError)
693
- end
690
+ new_sheet.name = new_sheet_name if new_sheet_name
694
691
  new_sheet
695
692
  end
696
693
 
@@ -707,11 +704,7 @@ module RobustExcelOle
707
704
  after_or_before, base_sheet = opts.to_a.first || [:after, last_sheet]
708
705
  @ole_workbook.Worksheets.Add({ after_or_before.to_s => base_sheet.worksheet })
709
706
  new_sheet = sheet_class.new(@excel.Activesheet)
710
- begin
711
- new_sheet.name = new_sheet_name if new_sheet_name
712
- rescue WIN32OLERuntimeError => msg
713
- msg.message =~ /800A03EC/ ? raise(NameAlreadyExists, "sheet name already exists") : raise(UnexpectedError)
714
- end
707
+ new_sheet.name = new_sheet_name if new_sheet_name
715
708
  new_sheet
716
709
  end
717
710
 
@@ -909,10 +902,6 @@ module RobustExcelOle
909
902
  self.class.bookstore
910
903
  end
911
904
 
912
- def self.all_books # :nodoc: #
913
- bookstore.books
914
- end
915
-
916
905
  def to_s # :nodoc: #
917
906
  "#{self.filename}"
918
907
  end
@@ -100,6 +100,8 @@ module RobustExcelOle
100
100
  @hidden_excel_instance.__getobj__ if (@hidden_excel_instance && @hidden_excel_instance.weakref_alive? && @hidden_excel_instance.__getobj__.alive?)
101
101
  end
102
102
 
103
+ public
104
+
103
105
  # prints the book store
104
106
  def print # :nodoc: #
105
107
  trace "@filename2books:"
@@ -113,7 +115,7 @@ module RobustExcelOle
113
115
  books.each do |book|
114
116
  if book.weakref_alive?
115
117
  trace "#{book}"
116
- else
118
+ else # this should never happen
117
119
  trace "weakref not alive"
118
120
  end
119
121
  end
@@ -94,8 +94,6 @@ module RobustExcelOle
94
94
  result.calculation = options[:calculation] unless options[:calculation].nil?
95
95
  result.screenupdating = options[:screenupdating] unless options[:screenupdating].nil?
96
96
  result.created = !reused
97
- rescue WIN32OLERuntimeError
98
- raise ExcelError, "cannot access Excel"
99
97
  end
100
98
  end
101
99
  result
@@ -104,10 +102,6 @@ module RobustExcelOle
104
102
  def initialize(options= {}) # :nodoc: #
105
103
  end
106
104
 
107
- def excel
108
- self
109
- end
110
-
111
105
  # reopens a closed Excel instance
112
106
  # @param [Hash] opts the options
113
107
  # @option opts [Boolean] :reopen_workbooks
@@ -177,15 +171,10 @@ module RobustExcelOle
177
171
  end
178
172
 
179
173
  def self.contains_unsaved_workbooks?
180
- excel = begin
181
- Excel.current
182
- rescue
183
- return false
184
- end
185
- not excel.unsaved_workbooks.empty?
174
+ not Excel.current.unsaved_workbooks.empty?
186
175
  end
187
176
 
188
- # returns unsaved workbooks
177
+ # returns unsaved workbooks (win32ole objects)
189
178
  def unsaved_workbooks
190
179
  unsaved_workbooks = []
191
180
  begin
@@ -470,7 +459,7 @@ module RobustExcelOle
470
459
 
471
460
 
472
461
  # returns unsaved workbooks in known (not opened by user) Excel instances
473
- def self.unsaved_known_workbooks
462
+ def self.unsaved_known_workbooks # :nodoc: #
474
463
  result = []
475
464
  @@hwnd2excel.each do |hwnd,wr_excel|
476
465
  excel = wr_excel.__getobj__ if wr_excel.weakref_alive?
@@ -479,12 +468,12 @@ module RobustExcelOle
479
468
  result
480
469
  end
481
470
 
482
- def print_workbooks
471
+ def print_workbooks # :nodoc: #
483
472
  self.Workbooks.each {|w| trace "#{w.Name} #{w}"}
484
473
  end
485
474
 
486
475
  # generates, saves, and closes empty workbook
487
- def generate_workbook file_name
476
+ def generate_workbook file_name # :nodoc: #
488
477
  raise FileNameNotGiven, "filename is nil" if file_name.nil?
489
478
  self.Workbooks.Add
490
479
  empty_workbook = self.Workbooks.Item(self.Workbooks.Count)
@@ -14,10 +14,6 @@ class REOCommon
14
14
  (self.methods - Object.methods).sort
15
15
  end
16
16
 
17
- def trace(text)
18
- self.class.trace(text)
19
- end
20
-
21
17
  def self.tr1(text)
22
18
  puts :text
23
19
  end
@@ -39,10 +35,6 @@ class REOCommon
39
35
  end
40
36
  end
41
37
 
42
- def puts_hash(hash)
43
- self.class.puts_hash(hash)
44
- end
45
-
46
38
  def self.puts_hash(hash)
47
39
  hash.each do |e|
48
40
  if e[1].is_a?(Hash)
@@ -230,19 +230,11 @@ module RobustExcelOle
230
230
  self.Names.Add("Name" => name, "RefersToR1C1" => "=" + address)
231
231
  end
232
232
  rescue WIN32OLERuntimeError => msg
233
- trace "WIN32OLERuntimeError: #{msg.message}"
233
+ #trace "WIN32OLERuntimeError: #{msg.message}"
234
234
  raise RangeNotEvaluatable, "cannot add name #{name.inspect} to cell with row #{row.inspect} and column #{column.inspect}"
235
235
  end
236
236
  end
237
237
 
238
- def respond_to?(name, include_private = false) # :nodoc: #
239
- super
240
- end
241
-
242
- def methods # :nodoc: #
243
- super
244
- end
245
-
246
238
  def self.book_class # :nodoc: #
247
239
  @book_class ||= begin
248
240
  module_name = self.parent_name
@@ -1,3 +1,3 @@
1
1
  module RobustExcelOle
2
- VERSION = "1.0.2"
2
+ VERSION = "1.0.3"
3
3
  end
@@ -47,6 +47,37 @@ describe Book do
47
47
  end
48
48
  end
49
49
 
50
+ describe "excel_of" do
51
+
52
+ before do
53
+ @book = Book.open(@simple_file)
54
+ end
55
+
56
+ after do
57
+ @book.close
58
+ end
59
+
60
+ it "should access the excel" do
61
+ workbook = @book.ole_workbook
62
+ excel = Book.excel_of(workbook)
63
+ excel.should be_a Excel
64
+ excel.should == @book.excel
65
+ end
66
+
67
+ it "should access the Excel of the ole_excel" do
68
+ excel = Book.excel_of(@book.excel.ole_excel)
69
+ excel.should be_a Excel
70
+ excel.should == @book.excel
71
+ end
72
+
73
+ it "should access the Excel of a Book" do
74
+ excel = Book.excel_of(@book)
75
+ excel.should be_a Excel
76
+ excel.should == @book.excel
77
+ end
78
+
79
+ end
80
+
50
81
  describe "with retain_saved" do
51
82
 
52
83
  before do
@@ -1364,6 +1364,12 @@ describe Book do
1364
1364
  old_book.close
1365
1365
  end
1366
1366
 
1367
+ it "should close the old book and open the new book, if :if_obstructed is :close_if_saved" do
1368
+ @book.close(:if_unsaved => :forget)
1369
+ book = Book.open(@simple_file_other_path)
1370
+ Book.open(@simple_file1, :if_obstructed => :close_if_saved)
1371
+ end
1372
+
1367
1373
  it "should open the book in a new excel instance, if :if_obstructed is :new_excel" do
1368
1374
  @new_book = Book.open(@simple_file1, :if_obstructed => :new_excel)
1369
1375
  @book.should be_alive
@@ -1630,6 +1636,12 @@ describe Book do
1630
1636
  book.should be_a Book
1631
1637
  end
1632
1638
  end
1639
+ it 'block parameter should be instance of Book for new' do
1640
+ Book.new(@simple_file) do |book|
1641
+ book.should be_a Book
1642
+ end
1643
+ end
1644
+
1633
1645
  end
1634
1646
 
1635
1647
  context "with WIN32OLE#GetAbsolutePathName" do
@@ -51,6 +51,8 @@ describe Bookstore do
51
51
  @simple_save_file = @dir + '/workbook_save.xls'
52
52
  @different_file = @dir + '/different_workbook.xls'
53
53
  @simple_file_other_path = @dir + '/more_data/workbook.xls'
54
+ @simple_file1 = @simple_file
55
+ @different_file1 = @different_file
54
56
  end
55
57
 
56
58
  after do
@@ -78,8 +80,8 @@ describe Bookstore do
78
80
 
79
81
  describe "Mock-Test" do
80
82
  it "should never store any book" do
81
- b1 = Book.open(@simple_file)
82
- b2 = Book.open(@simple_file)
83
+ b1 = Book.open(@simple_file1)
84
+ b2 = Book.open(@simple_file1)
83
85
  b2.object_id.should_not == b1.object_id
84
86
  end
85
87
  end
@@ -108,8 +110,8 @@ describe Bookstore do
108
110
 
109
111
  it "should fetch one book several times" do
110
112
  @bookstore.store(@book)
111
- book1 = @bookstore.fetch(@simple_file)
112
- book2 = @bookstore.fetch(@simple_file)
113
+ book1 = @bookstore.fetch(@simple_file1)
114
+ book2 = @bookstore.fetch(@simple_file1)
113
115
  expect(book1).to be_a Book
114
116
  book1.should be_alive
115
117
  book1.should == @book
@@ -161,10 +163,10 @@ describe Bookstore do
161
163
  end
162
164
 
163
165
  it "should store and open two different books" do
164
- @book2 = Book.open(@different_file)
166
+ @book2 = Book.open(@different_file1)
165
167
  @bookstore.store(@book2)
166
168
  new_book = @bookstore.fetch(@simple_file)
167
- new_book2 = @bookstore.fetch(@different_file)
169
+ new_book2 = @bookstore.fetch(@different_file1)
168
170
  new_book.should be_a Book
169
171
  new_book.should be_alive
170
172
  new_book.should == @book
@@ -177,35 +179,35 @@ describe Bookstore do
177
179
  end
178
180
 
179
181
  it "should fetch the first, writable book" do
180
- @book2 = Book.open(@simple_file, :force_excel => :new)
182
+ @book2 = Book.open(@simple_file1, :force_excel => :new)
181
183
  @bookstore.store(@book2)
182
184
  @book.ReadOnly.should be_false
183
185
  @book2.ReadOnly.should be_true
184
- new_book = @bookstore.fetch(@simple_file)
186
+ new_book = @bookstore.fetch(@simple_file1)
185
187
  new_book.should == @book
186
188
  new_book.should_not == @book2
187
189
  new_book.close
188
190
  end
189
191
 
190
192
  it "should fetch the last book with :prefer_writeable => false" do
191
- @book2 = Book.open(@simple_file, :force_excel => :new)
193
+ @book2 = Book.open(@simple_file1, :force_excel => :new)
192
194
  @bookstore.store(@book2)
193
195
  @book.ReadOnly.should be_false
194
196
  @book2.ReadOnly.should be_true
195
- new_book = @bookstore.fetch(@simple_file, :prefer_writable => false)
197
+ new_book = @bookstore.fetch(@simple_file1, :prefer_writable => false)
196
198
  new_book.should_not == @book
197
199
  new_book.should == @book2
198
200
  new_book.close
199
201
  end
200
202
 
201
203
  it "should fetch the second, open book, if the first book is closed" do
202
- @book2 = Book.open(@simple_file, :force_excel => :new)
204
+ @book2 = Book.open(@simple_file1, :force_excel => :new)
203
205
  @bookstore.store(@book2)
204
206
  @book.ReadOnly.should be_false
205
207
  @book2.ReadOnly.should be_true
206
208
  @book.close
207
- new_book = @bookstore.fetch(@simple_file, :prefer_writable => false)
208
- new_book2 = @bookstore.fetch(@simple_file)
209
+ new_book = @bookstore.fetch(@simple_file1, :prefer_writable => false)
210
+ new_book2 = @bookstore.fetch(@simple_file1)
209
211
  new_book.should_not == @book
210
212
  new_book2.should_not == @book
211
213
  new_book.should == @book2
@@ -215,13 +217,13 @@ describe Bookstore do
215
217
  end
216
218
 
217
219
  it "should fetch the first, open book, if the second book is closed, even with :prefer_writeable => false" do
218
- @book2 = Book.open(@simple_file, :force_excel => :new)
220
+ @book2 = Book.open(@simple_file1, :force_excel => :new)
219
221
  @bookstore.store(@book2)
220
222
  @book.ReadOnly.should be_false
221
223
  @book2.ReadOnly.should be_true
222
224
  @book2.close
223
- new_book = @bookstore.fetch(@simple_file, :prefer_writable => false)
224
- new_book2 = @bookstore.fetch(@simple_file)
225
+ new_book = @bookstore.fetch(@simple_file1, :prefer_writable => false)
226
+ new_book2 = @bookstore.fetch(@simple_file1)
225
227
  new_book.should_not == @book2
226
228
  new_book2.should_not == @book2
227
229
  new_book.should == @book
@@ -245,13 +247,13 @@ describe Bookstore do
245
247
  end
246
248
 
247
249
  it "should fetch the second, writable book" do
248
- @book2 = Book.open(@simple_file, :force_excel => :new)
250
+ @book2 = Book.open(@simple_file1, :force_excel => :new)
249
251
  @bookstore.store(@book2)
250
252
  @book.ReadOnly.should be_true
251
253
  @book2.ReadOnly.should be_false
252
- new_book = @bookstore.fetch(@simple_file)
253
- new_book2 = @bookstore.fetch(@simple_file, :prefer_writable => true)
254
- new_book3 = @bookstore.fetch(@simple_file, :prefer_writable => false)
254
+ new_book = @bookstore.fetch(@simple_file1)
255
+ new_book2 = @bookstore.fetch(@simple_file1, :prefer_writable => true)
256
+ new_book3 = @bookstore.fetch(@simple_file1, :prefer_writable => false)
255
257
  new_book.should == @book2
256
258
  new_book2.should == @book2
257
259
  new_book3.should == @book2
@@ -264,19 +266,19 @@ describe Bookstore do
264
266
  end
265
267
 
266
268
  it "should fetch the recent readonly book when there are only readonly books" do
267
- @book2 = Book.open(@simple_file, :force_excel => :new, :read_only => true)
269
+ @book2 = Book.open(@simple_file1, :force_excel => :new, :read_only => true)
268
270
  @bookstore.store(@book2)
269
271
  @book.ReadOnly.should be_true
270
272
  @book2.ReadOnly.should be_true
271
- new_book = @bookstore.fetch(@simple_file)
273
+ new_book = @bookstore.fetch(@simple_file1)
272
274
  new_book.should == @book2
273
275
  new_book.should_not == @book
274
276
  new_book.close
275
277
  end
276
278
 
277
279
  it "should fetch the second, writable book, if a writable, a readonly and an unsaved readonly book exist" do
278
- @book2 = Book.open(@simple_file, :force_excel => :new)
279
- @book3 = Book.open(@simple_file, :force_excel => :new)
280
+ @book2 = Book.open(@simple_file1, :force_excel => :new)
281
+ @book3 = Book.open(@simple_file1, :force_excel => :new)
280
282
  @bookstore.store(@book2)
281
283
  @bookstore.store(@book3)
282
284
  sheet = @book3.sheet(1)
@@ -285,8 +287,8 @@ describe Bookstore do
285
287
  @book2.ReadOnly.should be_false
286
288
  @book3.ReadOnly.should be_true
287
289
  @book3.Saved.should be_false
288
- new_book = @bookstore.fetch(@simple_file)
289
- new_book2 = @bookstore.fetch(@simple_file, :prefer_writable => false)
290
+ new_book = @bookstore.fetch(@simple_file1)
291
+ new_book2 = @bookstore.fetch(@simple_file1, :prefer_writable => false)
290
292
  new_book.should == @book2
291
293
  new_book2.should == @book3
292
294
  new_book.should_not == @book
@@ -301,9 +303,10 @@ describe Bookstore do
301
303
  context "with several closed books" do
302
304
 
303
305
  before do
304
- @book = Book.open(@simple_file)
306
+ @book = Book.open(@simple_file1)
307
+ @bookstore.store(@book)
305
308
  @bookstore.store(@book)
306
- @book2 = Book.open(@simple_file, :force_excel => :new)
309
+ @book2 = Book.open(@simple_file1, :force_excel => :new)
307
310
  @bookstore.store(@book2)
308
311
  @book.close
309
312
  @book2.close
@@ -341,13 +344,12 @@ describe Bookstore do
341
344
  end
342
345
  end
343
346
 
344
-
345
347
  context "with given excel instance and fetching readonly" do
346
348
 
347
349
  before do
348
- @book = Book.open(@simple_file)
350
+ @book = Book.open(@simple_file1)
349
351
  @bookstore.store(@book)
350
- @book2 = Book.open(@simple_file, :force_excel => :new)
352
+ @book2 = Book.open(@simple_file1, :force_excel => :new)
351
353
  @bookstore.store(@book2)
352
354
  end
353
355
 
@@ -391,23 +393,64 @@ describe Bookstore do
391
393
  end
392
394
 
393
395
  it "should have forgotten some books if they have no reference anymore" do
394
- different_file1 = @different_file
395
- simple_file1 = @simple_file
396
- book_new = Book.open(different_file1)
396
+ book_new = Book.open(@different_file1)
397
397
  @bookstore.store(book_new)
398
398
  @book = nil
399
399
  @book = "Bla"
400
- @book = Book.open(simple_file1)
400
+ @book = Book.open(@simple_file1)
401
401
  @bookstore.store(@book)
402
402
  @book = nil
403
403
  GC.start
404
404
  sleep 1
405
405
  #@bookstore.fetch(simple_file1).should == nil
406
- @bookstore.fetch(different_file1).should == book_new
406
+ @bookstore.fetch(@different_file1).should == book_new
407
407
  end
408
408
  end
409
409
  end
410
410
 
411
+ describe "books" do
412
+
413
+ before do
414
+ @book = Book.open(@simple_file)
415
+ @bookstore.store(@book)
416
+ @book2 = Book.open(@different_file)
417
+ @bookstore.store(@book2)
418
+ end
419
+
420
+ after do
421
+ @book.close
422
+ @book2.close
423
+ end
424
+
425
+ it "should show books" do
426
+ expect{
427
+ @bookstore.books}.to_not raise_error
428
+ end
429
+
430
+ end
431
+
432
+ describe "print" do
433
+
434
+ before do
435
+ @book = Book.open(@simple_file)
436
+ @bookstore.store(@book)
437
+ @book2 = Book.open(@different_file)
438
+ @bookstore.store(@book2)
439
+ end
440
+
441
+ after do
442
+ @book.close
443
+ @book2.close
444
+ end
445
+
446
+ it "should print books" do
447
+ @bookstore.print
448
+ end
449
+
450
+ end
451
+
452
+
453
+
411
454
  describe "hidden_excel" do
412
455
 
413
456
  context "with some open book" do
Binary file
@@ -839,6 +839,94 @@ module RobustExcelOle
839
839
  end
840
840
  end
841
841
 
842
+ describe "unsaved_known_workbooks" do
843
+
844
+ it "should return empty list" do
845
+ Excel.unsaved_known_workbooks.should be_empty
846
+ end
847
+
848
+ it "should return empty list for first Excel instance" do
849
+ book = Book.open(@simple_file)
850
+ Excel.unsaved_known_workbooks.should == [[]]
851
+ book.close
852
+ end
853
+
854
+ it "should return one unsaved book" do
855
+ book = Book.open(@simple_file)
856
+ sheet = book.sheet(1)
857
+ sheet[1,1] = sheet[1,1].value == "foo" ? "bar" : "foo"
858
+ # Excel.unsaved_known_workbooks.should == [[book.ole_workbook]]
859
+ unsaved_known_wbs = Excel.unsaved_known_workbooks
860
+ unsaved_known_wbs.size.should == 1
861
+ unsaved_known_wbs.each do |ole_wb_list|
862
+ ole_wb_list.size.should == 1
863
+ ole_wb_list.each do |ole_workbook|
864
+ ole_workbook.Fullname.tr('\\','/').should == @simple_file
865
+ end
866
+ end
867
+ book2 = Book.open(@another_simple_file)
868
+ # Excel.unsaved_known_workbooks.should == [[book.ole_workbook]]
869
+ unsaved_known_wbs = Excel.unsaved_known_workbooks
870
+ unsaved_known_wbs.size.should == 1
871
+ unsaved_known_wbs.each do |ole_wb_list|
872
+ ole_wb_list.size.should == 1
873
+ ole_wb_list.each do |ole_workbook|
874
+ ole_workbook.Fullname.tr('\\','/').should == @simple_file
875
+ end
876
+ end
877
+ book2.close
878
+ book.close(:if_unsaved => :forget)
879
+ end
880
+
881
+ it "should return two unsaved books" do
882
+ book = Book.open(@simple_file)
883
+ sheet = book.sheet(1)
884
+ sheet[1,1] = sheet[1,1].value == "foo" ? "bar" : "foo"
885
+ book2 = Book.open(@another_simple_file)
886
+ sheet2 = book2.sheet(1)
887
+ sheet2[1,1] = sheet2[1,1].value == "foo" ? "bar" : "foo"
888
+ #Excel.unsaved_known_workbooks.should == [[book.ole_workbook, book2.ole_workbook]]
889
+ unsaved_known_wbs = Excel.unsaved_known_workbooks
890
+ unsaved_known_wbs.size.should == 1
891
+ unsaved_known_wbs.each do |ole_wb_list|
892
+ ole_wb_list.size.should == 2
893
+ ole_workbook1, ole_workbook2 = ole_wb_list
894
+ ole_workbook1.Fullname.tr('\\','/').should == @simple_file
895
+ ole_workbook2.Fullname.tr('\\','/').should == @another_simple_file
896
+ end
897
+ book2.close(:if_unsaved => :forget)
898
+ book.close(:if_unsaved => :forget)
899
+ end
900
+
901
+ it "should return two unsaved books" do
902
+ book = Book.open(@simple_file)
903
+ sheet = book.sheet(1)
904
+ sheet[1,1] = sheet[1,1].value == "foo" ? "bar" : "foo"
905
+ book2 = Book.open(@another_simple_file, :force_excel => :new)
906
+ sheet2 = book2.sheet(1)
907
+ sheet2[1,1] = sheet2[1,1].value == "foo" ? "bar" : "foo"
908
+ #Excel.unsaved_known_workbooks.should == [[book.ole_workbook], [book2.ole_workbook]]
909
+ unsaved_known_wbs = Excel.unsaved_known_workbooks
910
+ unsaved_known_wbs.size.should == 2
911
+ ole_wb_list1, ole_wb_list2 = unsaved_known_wbs
912
+ ole_wb_list1.each do |ole_wb_list|
913
+ ole_wb_list1.size.should == 1
914
+ ole_wb_list1.each do |ole_workbook|
915
+ ole_workbook.Fullname.tr('\\','/').should == @simple_file
916
+ end
917
+ end
918
+ ole_wb_list2.each do |ole_wb_list|
919
+ ole_wb_list2.size.should == 1
920
+ ole_wb_list2.each do |ole_workbook|
921
+ ole_workbook.Fullname.tr('\\','/').should == @another_simple_file
922
+ end
923
+ end
924
+ book2.close(:if_unsaved => :forget)
925
+ book.close(:if_unsaved => :forget)
926
+ end
927
+
928
+ end
929
+
842
930
  describe "alive" do
843
931
 
844
932
  it "should yield alive" do
@@ -1450,6 +1538,45 @@ module RobustExcelOle
1450
1538
 
1451
1539
  end
1452
1540
 
1541
+ describe "set_options" do
1542
+
1543
+ before do
1544
+ @excel = Excel.new(:reuse => false)
1545
+ end
1546
+
1547
+ it "should set options" do
1548
+ @excel.set_options(:displayalerts => true, :visible => true, :screenupdating => true, :calculaiton => :manual)
1549
+ @excel.DisplayAlerts.should be_true
1550
+ @excel.Visible.should be_true
1551
+ @excel.ScreenUpdating.should be_true
1552
+ book = Book.open(@simple_file)
1553
+ @excel.Calculation.should == -4135
1554
+ book.close
1555
+ end
1556
+
1557
+ end
1558
+
1559
+ describe "excel_processes" do
1560
+
1561
+ it "should return empty list" do
1562
+ Excel.excel_processes.should be_empty
1563
+ end
1564
+
1565
+ it "should return list of one Excel process" do
1566
+ excel = Excel.new
1567
+ Excel.excel_processes.should == [excel]
1568
+ excel.close
1569
+ end
1570
+
1571
+ it "should return list of two Excel processes" do
1572
+ excel1 = Excel.new
1573
+ excel2 = Excel.current
1574
+ excel3 = Excel.create
1575
+ Excel.excel_processes.should == [excel1,excel3]
1576
+ end
1577
+
1578
+ end
1579
+
1453
1580
  context "with hwnd and hwnd2excel" do
1454
1581
 
1455
1582
  before do
@@ -49,7 +49,13 @@ module RobustExcelOle
49
49
  ["ActiveCell", "ActiveSheet", "ActiveWorkbook", "Application", "Calculate", "Cells", "Columns",
50
50
  "DisplayAlerts", "Evaluate", "Hwnd", "Name", "Names", "Quit", "Range", "Ready", "Save",
51
51
  "Sheets", "UserName", "Value", "Visible", "Workbooks", "Worksheets"]
52
- @excel_methods = ["alive?", "book_class", "close", "displayalerts", "recreate", "visible", "with_displayalerts"]
52
+ @excel_methods = ["alive?", "book_class", "close", "displayalerts", "recreate", "visible",
53
+ "with_displayalerts"]
54
+ @ole_sheet_methods = []
55
+ # ["Activate", "Calculate", "Copy", "Name", "Select", "Evaluate", "Protect", "Unprotect"]
56
+ @sheet_methods = ["book_class", "col_range", "each", "each_column", "each_column_with_index",
57
+ "each_row", "each_row_with_index", "nameval", "rangeval",
58
+ "set_rangeval", "row_range", "set_nameval"]
53
59
  end
54
60
 
55
61
  after do
@@ -84,6 +90,20 @@ module RobustExcelOle
84
90
  @excel_methods.each{|m| @book1.excel.respond_to?(m).should be_true}
85
91
  end
86
92
 
93
+ it "should do methods for sheet" do
94
+ ((@ole_sheet_methods + @sheet_methods) - @book1.sheet(1).methods).should be_empty
95
+ (Object.instance_methods.select{|m| m =~ /^(?!\_)/} - @book1.sheet(1).methods).sort.should be_empty
96
+ end
97
+
98
+ it "should do own_methods with popular ole_excel and excel methods" do
99
+ ((@ole_sheet_methods + @sheet_methods) - @book1.sheet(1).own_methods).should == [] #be_empty
100
+ (Object.instance_methods - @book1.sheet(1).own_methods).should == Object.instance_methods
101
+ end
102
+
103
+ it "should respond to popular sheet methods" do
104
+ @sheet_methods.each{|m| @book1.sheet(1).respond_to?(m).should be_true}
105
+ end
106
+
87
107
  end
88
108
 
89
109
  describe "#absolute_path" do
@@ -157,6 +177,20 @@ module RobustExcelOle
157
177
  end
158
178
  end
159
179
 
180
+ describe "path" do
181
+
182
+ it "should create a path" do
183
+ path1 = "this" / "is" / "a" / "path"
184
+ path1.should == "this/is/a/path"
185
+ path2 = "this" / "is" / "a" / "path" /
186
+ #path2.should == "this/is/a/path/"
187
+ path3 = "this" /
188
+ #path3.should == "this/"
189
+ path4 = "this" / nil
190
+ path4.should == "this"
191
+ end
192
+ end
193
+
160
194
  describe "Object methods" do
161
195
 
162
196
  before do
@@ -104,5 +104,27 @@ module RobustExcelOle
104
104
  end
105
105
 
106
106
  end
107
+
108
+ describe "misc" do
109
+
110
+ LOG_TO_STDOUT = true
111
+ REOCommon::trace "foo"
112
+
113
+ LOG_TO_STDOUT = false
114
+ REOCommon::trace "foo"
115
+
116
+ REO_LOG_DIR = ""
117
+ REOCommon::trace "foo"
118
+
119
+ REO_LOG_DIR = "C:"
120
+ REOCommon::trace "foo"
121
+
122
+ REOCommon::tr1 "foo"
123
+
124
+ h = {:a => {:c => 4}, :b => 2}
125
+ REOCommon::puts_hash(h)
126
+
127
+ end
128
+
107
129
  end
108
130
  end
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: 19
4
+ hash: 17
5
5
  prerelease: false
6
6
  segments:
7
7
  - 1
8
8
  - 0
9
- - 2
10
- version: 1.0.2
9
+ - 3
10
+ version: 1.0.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - traths
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2017-07-26 00:00:00 +02:00
18
+ date: 2017-08-27 00:00:00 +02:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency