robust_excel_ole 0.3.8 → 0.3.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. data/.yardopts +1 -0
  2. data/examples/edit_sheets/example_access_sheets_and_cells.rb +1 -1
  3. data/examples/edit_sheets/example_adding_sheets.rb +1 -1
  4. data/examples/edit_sheets/example_concating.rb +2 -2
  5. data/examples/edit_sheets/example_copying.rb +2 -2
  6. data/examples/edit_sheets/example_expanding.rb +2 -2
  7. data/examples/edit_sheets/example_naming.rb +2 -2
  8. data/examples/edit_sheets/example_ranges.rb +1 -1
  9. data/examples/edit_sheets/example_saving.rb +2 -2
  10. data/examples/open_save_close/example_control_to_excel.rb +1 -1
  11. data/examples/open_save_close/example_default_excel.rb +1 -1
  12. data/examples/open_save_close/example_force_excel.rb +1 -1
  13. data/examples/open_save_close/example_if_obstructed_closeifsaved.rb +1 -1
  14. data/examples/open_save_close/example_if_obstructed_forget.rb +1 -1
  15. data/examples/open_save_close/example_if_obstructed_save.rb +1 -1
  16. data/examples/open_save_close/example_if_unsaved_accept.rb +1 -1
  17. data/examples/open_save_close/example_if_unsaved_forget.rb +1 -1
  18. data/examples/open_save_close/example_if_unsaved_forget_more.rb +1 -1
  19. data/examples/open_save_close/example_read_only.rb +1 -1
  20. data/examples/open_save_close/example_rename_cells.rb +2 -2
  21. data/examples/open_save_close/example_reuse.rb +1 -1
  22. data/examples/open_save_close/example_simple.rb +1 -1
  23. data/examples/open_save_close/example_unobtrusively.rb +1 -1
  24. data/lib/reo_console.rb +2 -2
  25. data/lib/robust_excel_ole.rb +1 -174
  26. data/lib/robust_excel_ole/book.rb +47 -63
  27. data/lib/robust_excel_ole/bookstore.rb +4 -4
  28. data/lib/robust_excel_ole/excel.rb +12 -18
  29. data/lib/robust_excel_ole/general.rb +188 -0
  30. data/lib/robust_excel_ole/sheet.rb +1 -1
  31. data/lib/robust_excel_ole/utilities.rb +1 -1
  32. data/lib/robust_excel_ole/version.rb +1 -1
  33. data/spec/{book_specs/book_spec.rb → book_spec.rb} +26 -24
  34. data/spec/book_specs/book_all_spec.rb +1 -1
  35. data/spec/book_specs/book_close_spec.rb +16 -15
  36. data/spec/book_specs/book_misc_spec.rb +4 -3
  37. data/spec/book_specs/book_open_spec.rb +10 -9
  38. data/spec/book_specs/book_save_spec.rb +4 -3
  39. data/spec/book_specs/book_sheet_spec.rb +7 -6
  40. data/spec/book_specs/book_unobtr_spec.rb +2 -1
  41. data/spec/data/different_workbook.xls +0 -0
  42. data/spec/data/workbook.xls +0 -0
  43. data/spec/excel_spec.rb +9 -11
  44. data/spec/general_spec.rb +193 -0
  45. data/spec/range_spec.rb +3 -2
  46. data/spec/sheet_spec.rb +27 -19
  47. metadata +8 -6
  48. data/spec/robust_excel_ole_spec.rb +0 -113
@@ -5,7 +5,7 @@ require File.join(File.dirname(__FILE__), './../spec_helper')
5
5
 
6
6
  $VERBOSE = nil
7
7
 
8
- include RobustExcelOle
8
+ include General
9
9
 
10
10
  unless Object.method_defined?(:require_relative)
11
11
  def require_relative path
@@ -6,6 +6,7 @@ require File.join(File.dirname(__FILE__), './../spec_helper')
6
6
  $VERBOSE = nil
7
7
 
8
8
  include RobustExcelOle
9
+ include General
9
10
 
10
11
  describe Book do
11
12
 
@@ -51,7 +52,7 @@ describe Book do
51
52
  context "with unsaved read_only book" do
52
53
  before do
53
54
  @book = Book.open(@simple_file, :read_only => true)
54
- @sheet_count = @book.workbook.Worksheets.Count
55
+ @sheet_count = @book.ole_workbook.Worksheets.Count
55
56
  @book.add_sheet(@sheet, :as => 'a_name')
56
57
  end
57
58
 
@@ -60,7 +61,7 @@ describe Book do
60
61
  @book.close
61
62
  }.to_not raise_error
62
63
  new_book = Book.open(@simple_file)
63
- new_book.workbook.Worksheets.Count.should == @sheet_count
64
+ new_book.ole_workbook.Worksheets.Count.should == @sheet_count
64
65
  new_book.close
65
66
  end
66
67
  end
@@ -68,7 +69,7 @@ describe Book do
68
69
  context "with unsaved book" do
69
70
  before do
70
71
  @book = Book.open(@simple_file)
71
- @sheet_count = @book.workbook.Worksheets.Count
72
+ @sheet_count = @book.ole_workbook.Worksheets.Count
72
73
  @book.add_sheet(@sheet, :as => 'a_name')
73
74
  @sheet = @book[0]
74
75
  end
@@ -90,7 +91,7 @@ describe Book do
90
91
  end
91
92
 
92
93
  it "should keep the book open" do
93
- ole_workbook = @book.workbook
94
+ ole_workbook = @book.ole_workbook
94
95
  excel = @book.excel
95
96
  excel.Workbooks.Count.should == 1
96
97
  @book.close(:if_unsaved => :keep_open)
@@ -99,18 +100,18 @@ describe Book do
99
100
  end
100
101
 
101
102
  it "should close the book and leave its file untouched with option :forget" do
102
- ole_workbook = @book.workbook
103
+ ole_workbook = @book.ole_workbook
103
104
  excel = @book.excel
104
105
  excel.Workbooks.Count.should == 1
105
106
  @book.close(:if_unsaved => :forget)
106
107
  excel.Workbooks.Count.should == 0
107
- @book.workbook.should == nil
108
+ @book.ole_workbook.should == nil
108
109
  @book.should_not be_alive
109
110
  expect{
110
111
  ole_workbook.Name}.to raise_error(WIN32OLERuntimeError)
111
112
  new_book = Book.open(@simple_file)
112
113
  begin
113
- new_book.workbook.Worksheets.Count.should == @sheet_count
114
+ new_book.ole_workbook.Worksheets.Count.should == @sheet_count
114
115
  ensure
115
116
  new_book.close
116
117
  end
@@ -124,18 +125,18 @@ describe Book do
124
125
 
125
126
 
126
127
  it "should save the book before close with option :save" do
127
- ole_workbook = @book.workbook
128
+ ole_workbook = @book.ole_workbook
128
129
  excel = @book.excel
129
130
  excel.Workbooks.Count.should == 1
130
131
  @book.close(:if_unsaved => :save)
131
132
  excel.Workbooks.Count.should == 0
132
- @book.workbook.should == nil
133
+ @book.ole_workbook.should == nil
133
134
  @book.should_not be_alive
134
135
  expect{
135
136
  ole_workbook.Name}.to raise_error(WIN32OLERuntimeError)
136
137
  new_book = Book.open(@simple_file)
137
138
  begin
138
- new_book.workbook.Worksheets.Count.should == @sheet_count + 1
139
+ new_book.ole_workbook.Worksheets.Count.should == @sheet_count + 1
139
140
  ensure
140
141
  new_book.close
141
142
  end
@@ -155,27 +156,27 @@ describe Book do
155
156
  it "should" + (answer == :yes ? "" : " not") + " the unsaved book and" + (answer == :cancel ? " not" : "") + " close it" + "if user answers '#{answer}'" do
156
157
  # "Yes" is the default. "No" is right of "Yes", "Cancel" is right of "No" --> language independent
157
158
  @key_sender.puts "{right}" * position + "{enter}"
158
- ole_workbook = @book.workbook
159
+ ole_workbook = @book.ole_workbook
159
160
  excel = @book.excel
160
161
  displayalert_value = @book.excel.DisplayAlerts
161
162
  if answer == :cancel then
162
163
  expect {
163
164
  @book.close(:if_unsaved => :alert)
164
165
  }.to raise_error(ExcelUserCanceled, "close: canceled by user")
165
- @book.workbook.Saved.should be_false
166
- @book.workbook.should_not == nil
166
+ @book.ole_workbook.Saved.should be_false
167
+ @book.ole_workbook.should_not == nil
167
168
  @book.should be_alive
168
169
  else
169
170
  @book.excel.Workbooks.Count.should == 1
170
171
  @book.close(:if_unsaved => :alert)
171
172
  @book.excel.Workbooks.Count.should == 0
172
- @book.workbook.should == nil
173
+ @book.ole_workbook.should == nil
173
174
  @book.should_not be_alive
174
175
  expect{ole_workbook.Name}.to raise_error(WIN32OLERuntimeError)
175
176
  end
176
177
  new_book = Book.open(@simple_file, :if_unsaved => :forget)
177
178
  begin
178
- new_book.workbook.Worksheets.Count.should == @sheet_count + (answer==:yes ? 1 : 0)
179
+ new_book.ole_workbook.Worksheets.Count.should == @sheet_count + (answer==:yes ? 1 : 0)
179
180
  new_book.excel.DisplayAlerts.should == displayalert_value
180
181
  ensure
181
182
  new_book.close
@@ -6,6 +6,7 @@ require File.join(File.dirname(__FILE__), './../spec_helper')
6
6
  $VERBOSE = nil
7
7
 
8
8
  include RobustExcelOle
9
+ include General
9
10
 
10
11
  describe Book do
11
12
 
@@ -323,15 +324,15 @@ describe Book do
323
324
  @book.excel.visible = true
324
325
  @book.excel.visible.should be_true
325
326
  @book.visible.should be_true
326
- @book.excel.Windows(@book.workbook.Name).Visible.should be_true
327
+ @book.excel.Windows(@book.ole_workbook.Name).Visible.should be_true
327
328
  @book.visible = false
328
329
  @book.excel.visible.should be_true
329
330
  @book.visible.should be_false
330
- @book.excel.Windows(@book.workbook.Name).Visible.should be_false
331
+ @book.excel.Windows(@book.ole_workbook.Name).Visible.should be_false
331
332
  @book.visible = true
332
333
  @book.excel.visible.should be_true
333
334
  @book.visible.should be_true
334
- @book.excel.Windows(@book.workbook.Name).Visible.should be_true
335
+ @book.excel.Windows(@book.ole_workbook.Name).Visible.should be_true
335
336
  end
336
337
 
337
338
  end
@@ -6,6 +6,7 @@ require File.join(File.dirname(__FILE__), './../spec_helper')
6
6
  $VERBOSE = nil
7
7
 
8
8
  include RobustExcelOle
9
+ include General
9
10
 
10
11
  describe Book do
11
12
 
@@ -68,7 +69,7 @@ describe Book do
68
69
  end
69
70
 
70
71
  it "should fetch the workbook" do
71
- workbook = @book.workbook
72
+ workbook = @book.ole_workbook
72
73
  new_book = Book.new(workbook)
73
74
  new_book.should be_a Book
74
75
  new_book.should be_alive
@@ -82,7 +83,7 @@ describe Book do
82
83
  end
83
84
 
84
85
  it "should fetch the workbook" do
85
- workbook = @book.workbook
86
+ workbook = @book.ole_workbook
86
87
  new_book = Book.new(workbook, :visible => true)
87
88
  new_book.should be_a Book
88
89
  new_book.should be_alive
@@ -96,7 +97,7 @@ describe Book do
96
97
  end
97
98
 
98
99
  it "should yield an identical Book and set visible and displayalerts values" do
99
- workbook = @book.workbook
100
+ workbook = @book.ole_workbook
100
101
  new_book = Book.new(workbook, :visible => true, :displayalerts => true)
101
102
  new_book.should be_a Book
102
103
  new_book.should be_alive
@@ -232,9 +233,9 @@ describe Book do
232
233
  book4.excel.should === @book.excel
233
234
  book3.close
234
235
  book4.close
235
- book5 = Book.open(@simple_file, :force_excel => book2.workbook)
236
+ book5 = Book.open(@simple_file, :force_excel => book2.ole_workbook)
236
237
  book5.excel.should === book2.excel
237
- win32ole_excel1 = WIN32OLE.connect(@book.workbook.Fullname).Application
238
+ win32ole_excel1 = WIN32OLE.connect(@book.ole_workbook.Fullname).Application
238
239
  book6 = Book.open(@simple_file, :force_excel => win32ole_excel1)
239
240
  book6.excel.should === @book.excel
240
241
  end
@@ -570,7 +571,7 @@ describe Book do
570
571
  book_before.close
571
572
  end
572
573
  @book = Book.open(@simple_file_other_path)
573
- @sheet_count = @book.workbook.Worksheets.Count
574
+ @sheet_count = @book.ole_workbook.Worksheets.Count
574
575
  @sheet = @book[0]
575
576
  @book.add_sheet(@sheet, :as => 'a_name')
576
577
  end
@@ -599,7 +600,7 @@ describe Book do
599
600
  @new_book.should be_alive
600
601
  @new_book.filename.downcase.should == @simple_file.downcase
601
602
  old_book = Book.open(@simple_file_other_path, :if_obstructed => :forget)
602
- old_book.workbook.Worksheets.Count.should == @sheet_count + 1
603
+ old_book.ole_workbook.Worksheets.Count.should == @sheet_count + 1
603
604
  old_book.close
604
605
  end
605
606
 
@@ -614,7 +615,7 @@ describe Book do
614
615
  @new_book.should be_alive
615
616
  @new_book.filename.downcase.should == @simple_file.downcase
616
617
  old_book = Book.open(@simple_file_other_path, :if_obstructed => :forget)
617
- old_book.workbook.Worksheets.Count.should == @sheet_count + 1
618
+ old_book.ole_workbook.Worksheets.Count.should == @sheet_count + 1
618
619
  old_book.close
619
620
  end
620
621
 
@@ -893,7 +894,7 @@ describe Book do
893
894
  end
894
895
 
895
896
  it "should uplift a workbook to a book with an open book" do
896
- workbook = @book.workbook
897
+ workbook = @book.ole_workbook
897
898
  book1 = Book.new(workbook)
898
899
  book1.should be_a Book
899
900
  book1.should be_alive
@@ -6,6 +6,7 @@ require File.join(File.dirname(__FILE__), './../spec_helper')
6
6
  $VERBOSE = nil
7
7
 
8
8
  include RobustExcelOle
9
+ include General
9
10
 
10
11
  describe Book do
11
12
 
@@ -40,11 +41,11 @@ describe Book do
40
41
  it "should save for a file opened without :read_only" do
41
42
  @book = Book.open(@simple_file)
42
43
  @book.add_sheet(@sheet, :as => 'a_name')
43
- @new_sheet_count = @book.workbook.Worksheets.Count
44
+ @new_sheet_count = @book.ole_workbook.Worksheets.Count
44
45
  expect {
45
46
  @book.save
46
47
  }.to_not raise_error
47
- @book.workbook.Worksheets.Count.should == @new_sheet_count
48
+ @book.ole_workbook.Worksheets.Count.should == @new_sheet_count
48
49
  @book.close
49
50
  end
50
51
 
@@ -378,7 +379,7 @@ describe Book do
378
379
 
379
380
  it "should report save errors and leave DisplayAlerts unchanged" do
380
381
  #@key_sender.puts "{left}{enter}" #, :initial_wait => 0.2, :if_target_missing=>"Excel window not found")
381
- @book.workbook.Close
382
+ @book.ole_workbook.Close
382
383
  expect{
383
384
  @book.save_as(@simple_save_file, :if_exists => :alert)
384
385
  }.to raise_error(ExcelErrorSave, "Workbook is not alive")
@@ -6,6 +6,7 @@ require File.join(File.dirname(__FILE__), './../spec_helper')
6
6
  $VERBOSE = nil
7
7
 
8
8
  include RobustExcelOle
9
+ include General
9
10
 
10
11
  describe Book do
11
12
 
@@ -45,14 +46,14 @@ describe Book do
45
46
 
46
47
  context "only first argument" do
47
48
  it "should add worksheet" do
48
- @book.workbook.Worksheets.Count == 3
49
+ @book.ole_workbook.Worksheets.Count == 3
49
50
  @book.add_sheet @sheet
50
- @book.workbook.Worksheets.Count == 4
51
+ @book.ole_workbook.Worksheets.Count == 4
51
52
  end
52
53
 
53
54
  it "should return copyed sheet" do
54
55
  sheet = @book.add_sheet @sheet
55
- copyed_sheet = @book.workbook.Worksheets.Item(@book.workbook.Worksheets.Count)
56
+ copyed_sheet = @book.ole_workbook.Worksheets.Item(@book.ole_workbook.Worksheets.Count)
56
57
  sheet.name.should eq copyed_sheet.name
57
58
  end
58
59
  end
@@ -106,14 +107,14 @@ describe Book do
106
107
 
107
108
  context "without argument" do
108
109
  it "should add empty sheet" do
109
- @book.workbook.Worksheets.Count.should == 3
110
+ @book.ole_workbook.Worksheets.Count.should == 3
110
111
  @book.add_sheet
111
- @book.workbook.Worksheets.Count.should == 4
112
+ @book.ole_workbook.Worksheets.Count.should == 4
112
113
  end
113
114
 
114
115
  it "should return copyed sheet" do
115
116
  sheet = @book.add_sheet
116
- copyed_sheet = @book.workbook.Worksheets.Item(@book.workbook.Worksheets.Count)
117
+ copyed_sheet = @book.ole_workbook.Worksheets.Item(@book.ole_workbook.Worksheets.Count)
117
118
  sheet.name.should eq copyed_sheet.name
118
119
  end
119
120
  end
@@ -6,6 +6,7 @@ require File.join(File.dirname(__FILE__), './../spec_helper')
6
6
  $VERBOSE = nil
7
7
 
8
8
  include RobustExcelOle
9
+ include General
9
10
 
10
11
  describe Book do
11
12
 
@@ -301,7 +302,7 @@ describe Book do
301
302
  old_cell_value = sheet[1,1].value
302
303
  @book.close
303
304
  @book.should_not be_alive
304
- Excel.close_all
305
+ Excel.kill_all
305
306
  Book.unobtrusively(@simple_file, :keep_open => true) do |book|
306
307
  book.should be_a Book
307
308
  book.excel.should == @book.excel
Binary file
Binary file
data/spec/excel_spec.rb CHANGED
@@ -4,7 +4,7 @@ require File.join(File.dirname(__FILE__), './spec_helper')
4
4
 
5
5
  $VERBOSE = nil
6
6
 
7
- include RobustExcelOle
7
+ include General
8
8
 
9
9
  module RobustExcelOle
10
10
 
@@ -16,7 +16,6 @@ module RobustExcelOle
16
16
 
17
17
  before do
18
18
  @dir = create_tmpdir
19
- #print "tmpdir: "; p @dir
20
19
  @simple_file = @dir + '/workbook.xls'
21
20
  @another_simple_file = @dir + '/another_workbook.xls'
22
21
  @different_file = @dir + '/different_workbook.xls'
@@ -81,7 +80,7 @@ module RobustExcelOle
81
80
  end
82
81
 
83
82
  it "lifts an Excel instance given as WIN32Ole object" do
84
- win32ole_excel = WIN32OLE.connect(@book.workbook.Fullname).Application
83
+ win32ole_excel = WIN32OLE.connect(@book.ole_workbook.Fullname).Application
85
84
  excel = Excel.new(win32ole_excel)
86
85
  excel.should be_a Excel
87
86
  excel.should be_alive
@@ -91,7 +90,7 @@ module RobustExcelOle
91
90
  it "lifts an Excel instance given as WIN32Ole object with options" do
92
91
  @excel.Visible = true
93
92
  @excel.DisplayAlerts = true
94
- win32ole_excel = WIN32OLE.connect(@book.workbook.Fullname).Application
93
+ win32ole_excel = WIN32OLE.connect(@book.ole_workbook.Fullname).Application
95
94
  excel = Excel.new(win32ole_excel)
96
95
  excel.should be_a Excel
97
96
  excel.should be_alive
@@ -403,7 +402,6 @@ module RobustExcelOle
403
402
  @key_sender.close
404
403
  end
405
404
 
406
-
407
405
  it "should save if user answers 'yes'" do
408
406
  @key_sender.puts "{enter}"
409
407
  Excel.close_all(:if_unsaved => :alert)
@@ -807,7 +805,7 @@ module RobustExcelOle
807
805
  # unsaved_workbooks yields different WIN32OLE objects than book.workbook
808
806
  uw_names = []
809
807
  excel.unsaved_workbooks.each {|uw| uw_names << uw.Name}
810
- uw_names.should == [@book.workbook.Name]
808
+ uw_names.should == [@book.ole_workbook.Name]
811
809
  end
812
810
 
813
811
  it "should list all unsaved workbooks" do
@@ -817,8 +815,8 @@ module RobustExcelOle
817
815
  unsaved_workbooks.each {|uw| uw_names << uw.Name}
818
816
  result << uw_names
819
817
  end
820
- result.include?([@book.workbook.Name]).should be_true
821
- result.include?([@book2.workbook.Name]).should be_true
818
+ result.include?([@book.ole_workbook.Name]).should be_true
819
+ result.include?([@book2.ole_workbook.Name]).should be_true
822
820
  end
823
821
 
824
822
  end
@@ -837,7 +835,7 @@ module RobustExcelOle
837
835
  workbook = @excel1.generate_workbook(@file_name)
838
836
  workbook.should be_a WIN32OLE
839
837
  workbook.Name.should == File.basename(@file_name)
840
- workbook.FullName.should == RobustExcelOle::absolute_path(@file_name)
838
+ workbook.FullName.should == General::absolute_path(@file_name)
841
839
  workbook.Saved.should be_true
842
840
  workbook.ReadOnly.should be_false
843
841
  workbook.Sheets.Count.should == 3
@@ -849,7 +847,7 @@ module RobustExcelOle
849
847
  workbook = @excel1.generate_workbook(@file_name)
850
848
  workbook.should be_a WIN32OLE
851
849
  workbook.Name.should == File.basename(@file_name)
852
- workbook.FullName.should == RobustExcelOle::absolute_path(@file_name)
850
+ workbook.FullName.should == General::absolute_path(@file_name)
853
851
  workbook.Saved.should be_true
854
852
  workbook.ReadOnly.should be_false
855
853
  workbook.Sheets.Count.should == 3
@@ -866,7 +864,7 @@ module RobustExcelOle
866
864
  workbook = @excel1.generate_workbook(@file_name)
867
865
  workbook.should be_a WIN32OLE
868
866
  workbook.Name.should == File.basename(@file_name)
869
- workbook.FullName.should == RobustExcelOle::absolute_path(@file_name)
867
+ workbook.FullName.should == General::absolute_path(@file_name)
870
868
  workbook.Saved.should be_true
871
869
  workbook.ReadOnly.should be_false
872
870
  workbook.Sheets.Count.should == 3
@@ -0,0 +1,193 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ require File.join(File.dirname(__FILE__), './spec_helper')
4
+
5
+ $VERBOSE = nil
6
+
7
+ include General
8
+ include RobustExcelOle
9
+
10
+ module RobustExcelOle
11
+
12
+ describe General do
13
+
14
+ before(:all) do
15
+ excel = Excel.new(:reuse => true)
16
+ open_books = excel == nil ? 0 : excel.Workbooks.Count
17
+ puts "*** open books *** : #{open_books}" if open_books > 0
18
+ Excel.kill_all
19
+ end
20
+
21
+ before do
22
+ @dir = create_tmpdir
23
+ @simple_file = @dir + '/workbook.xls'
24
+ @simple_save_file = @dir + '/workbook_save.xls'
25
+ @different_file = @dir + '/different_workbook.xls'
26
+ @simple_file_other_path = @dir + '/more_data/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
+ end
32
+
33
+ after do
34
+ Excel.kill_all
35
+ rm_tmp(@dir)
36
+ end
37
+
38
+ describe "methods, own_methods, respond_to?" do
39
+
40
+ before do
41
+ @book1 = Book.open(@simple_file)
42
+ @ole_workbook_methods =
43
+ ["Activate", "ActiveSheet", "Application", "Close", "FullName", "HasPassword", "Name", "Names",
44
+ "Password", "Protect", "ProtectSharing", "ProtectStructure", "Protect", "ReadOnly", "Save",
45
+ "SaveAs", "Saved", "Sheets", "Unprotect"]
46
+ @book_methods = ["activate", "add_sheet", "alive?", "close", "filename", "nvalue", "ole_object",
47
+ "ole_workbook", "reopen", "save", "save_as", "saved", "set_nvalue"]
48
+ @ole_excel_methods =
49
+ ["ActiveCell", "ActiveSheet", "ActiveWorkbook", "Application", "Calculate", "Cells", "Columns",
50
+ "DisplayAlerts", "Evaluate", "Hwnd", "Name", "Names", "Quit", "Range", "Ready", "Save",
51
+ "Sheets", "UserName", "Value", "Visible", "Workbooks", "Worksheets"]
52
+ @excel_methods = ["alive?", "book_class", "close", "displayalerts", "recreate", "visible", "with_displayalerts"]
53
+ end
54
+
55
+ after do
56
+ @book1.close
57
+ end
58
+
59
+ it "should do methods for book" do
60
+ ((@ole_workbook_methods + @book_methods) - @book1.methods).should be_empty
61
+ (Object.instance_methods.select{|m| m =~ /^(?!\_)/} - @book1.methods).should be_empty
62
+ end
63
+
64
+ it "should do own_methods with popular ole_workbook and workbook methods" do
65
+ ((@ole_workbook_methods + @book_methods) - @book1.own_methods).should be_empty
66
+ (Object.instance_methods - @book1.own_methods).should == Object.instance_methods
67
+ end
68
+
69
+ it "should respond to popular workbook methods" do
70
+ @book_methods.each{|m| @book1.respond_to?(m).should be_true}
71
+ end
72
+
73
+ it "should do methods for excel" do
74
+ ((@ole_excel_methods + @excel_methods) - @book1.excel.methods).should be_empty
75
+ (Object.instance_methods.select{|m| m =~ /^(?!\_)/} - @book1.excel.methods).sort.should be_empty
76
+ end
77
+
78
+ it "should do own_methods with popular ole_excel and excel methods" do
79
+ ((@ole_excel_methods + @excel_methods) - @book1.excel.own_methods).should be_empty
80
+ (Object.instance_methods - @book1.excel.own_methods).should == Object.instance_methods
81
+ end
82
+
83
+ it "should respond to popular excel methods" do
84
+ @excel_methods.each{|m| @book1.excel.respond_to?(m).should be_true}
85
+ end
86
+
87
+ end
88
+
89
+ describe "#absolute_path" do
90
+
91
+ context "with standard" do
92
+
93
+ before do
94
+ @previous_dir = Dir.getwd
95
+ end
96
+
97
+ after do
98
+ Dir.chdir @previous_dir
99
+ end
100
+
101
+ it "should return the right absolute paths" do
102
+ absolute_path("C:/abc").should == "C:\\abc"
103
+ absolute_path("C:\\abc").should == "C:\\abc"
104
+ Dir.chdir "C:/windows"
105
+ absolute_path("C:abc").downcase.should == Dir.pwd.gsub("/","\\").downcase + "\\abc"
106
+ absolute_path("C:abc").upcase.should == File.expand_path("abc").gsub("/","\\").upcase
107
+ end
108
+
109
+ it "should return right absolute path name" do
110
+ filename = 'C:/Dokumente und Einstellungen/Zauberthomas/Eigene Dateien/robust_excel_ole/spec/book_spec.rb'
111
+ absolute_path(filename).gsub("\\","/").should == filename
112
+ end
113
+ end
114
+ end
115
+
116
+ describe "canonize" do
117
+
118
+ context "with standard" do
119
+
120
+ it "should reduce slash at the end" do
121
+ normalize("hallo/").should == "hallo"
122
+ normalize("/this/is/the/Path/").should == "/this/is/the/Path"
123
+ end
124
+
125
+ it "should save capital letters" do
126
+ normalize("HALLO/").should == "HALLO"
127
+ normalize("/This/IS/tHe/patH/").should == "/This/IS/tHe/patH"
128
+ end
129
+
130
+ it "should reduce multiple shlashes" do
131
+ normalize("/this/is//the/path").should == "/this/is/the/path"
132
+ normalize("///this/////////is//the/path/////").should == "/this/is/the/path"
133
+ end
134
+
135
+ it "should reduce dots in the paths" do
136
+ canonize("/this/is/./the/path").should == "/this/is/the/path"
137
+ canonize("this/.is/./the/pa.th/").should == "this/.is/the/pa.th"
138
+ canonize("this//.///.//.is/the/pa.th/").should == "this/.is/the/pa.th"
139
+ end
140
+
141
+ it "should change to the upper directory with two dots" do
142
+ canonize("/this/is/../the/path").should == "/this/the/path"
143
+ canonize("this../.i.s/.../..the/..../pa.th/").should == "this../.i.s/.../..the/..../pa.th"
144
+ end
145
+
146
+ it "should downcase" do
147
+ canonize("/This/IS/tHe/path").should == "/this/is/the/path"
148
+ canonize("///THIS/.///./////iS//the/../PatH/////").should == "/this/is/path"
149
+ end
150
+
151
+ it "should raise an error for no strings" do
152
+ expect{
153
+ canonize(1)
154
+ }.to raise_error(ExcelError, "No string given to canonize, but 1")
155
+ end
156
+
157
+ end
158
+ end
159
+
160
+ describe "Object methods" do
161
+
162
+ before do
163
+ @book = Book.open(@simple_file)
164
+ @sheet = @book[0]
165
+ end
166
+
167
+ before do
168
+ @book.close
169
+ end
170
+
171
+ it "should raise an error when asking excel of a sheet" do
172
+ expect{
173
+ @sheet.excel
174
+ }.to raise_error(ExcelError, "receiver instance is neither an Excel nor a Book")
175
+ end
176
+
177
+ end
178
+
179
+ describe "trace" do
180
+
181
+ it "should put some number" do
182
+ a = 4
183
+ trace "some text #{a}"
184
+ end
185
+
186
+ it "should put another text" do
187
+ a = 5
188
+ trace "another text #{a}"
189
+ end
190
+ end
191
+
192
+ end
193
+ end