robust_excel_ole 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
data/spec/book_spec.rb CHANGED
@@ -83,7 +83,7 @@ describe Book do
83
83
 
84
84
  it "should open unobtrusively" do
85
85
  book = Book.open(@simple_file, :if_locked => :take_writable,
86
- :if_unsaved => :accept, :if_obstructed => :reuse_excel)
86
+ :if_unsaved => :accept, :if_obstructed => :new_excel)
87
87
  book.close
88
88
  end
89
89
 
@@ -152,6 +152,55 @@ describe Book do
152
152
  book2.should be_alive
153
153
  book2.close
154
154
  end
155
+
156
+ it "should yield identical Book objects when reopening and the Excel is closed" do
157
+ @book.should be_alive
158
+ @book.close
159
+ Excel.close_all
160
+ book2 = Book.open(@simple_file)
161
+ book2.should be_alive
162
+ book2.should == @book
163
+ book2.close
164
+ end
165
+
166
+ it "should yield different Book objects when reopening in a new Excel" do
167
+ @book.should be_alive
168
+ old_excel = @book.excel
169
+ @book.close
170
+ @book.should_not be_alive
171
+ book2 = Book.open(@simple_file, :force_excel => :new)
172
+ book2.should_not == @book
173
+ book2.should be_alive
174
+ book2.excel.should_not == old_excel
175
+ book2.close
176
+ end
177
+
178
+ it "should yield different Book objects when reopening in a new given Excel instance" do
179
+ old_excel = @book.excel
180
+ new_excel = Excel.new(:reuse => false)
181
+ @book.close
182
+ @book.should_not be_alive
183
+ book2 = Book.open(@simple_file, :force_excel => new_excel)
184
+ book2.should_not == @book
185
+ book2.should be_alive
186
+ book2.excel.should == new_excel
187
+ book2.excel.should_not == old_excel
188
+ book2.close
189
+ end
190
+
191
+ it "should yield identical Book objects when reopening in the old excel" do
192
+ old_excel = @book.excel
193
+ new_excel = Excel.new(:reuse => false)
194
+ @book.close
195
+ @book.should_not be_alive
196
+ book2 = Book.open(@simple_file, :force_excel => old_excel)
197
+ book2.should == @book
198
+ book2.should be_alive
199
+ book2.excel.should == old_excel
200
+ @book.should be_alive
201
+ book2.close
202
+ end
203
+
155
204
  end
156
205
 
157
206
  context "with :force_excel" do
@@ -161,7 +210,7 @@ describe Book do
161
210
  end
162
211
 
163
212
  after do
164
- @book.close
213
+ @book.close rescue nil
165
214
  end
166
215
 
167
216
  it "should open in a new Excel" do
@@ -172,9 +221,11 @@ describe Book do
172
221
  book2.should_not == @book
173
222
  @book.Readonly.should be_false
174
223
  book2.Readonly.should be_true
224
+ book2.close
175
225
  end
176
226
 
177
- it "should open in a given Excel" do
227
+
228
+ it "should open in a given Excel, not provide identity transparency, because old book readonly, new book writable" do
178
229
  book2 = Book.open(@simple_file, :force_excel => :new)
179
230
  book2.excel.should_not == @book.excel
180
231
  book3 = Book.open(@simple_file, :force_excel => :new)
@@ -185,6 +236,27 @@ describe Book do
185
236
  book4.should be_alive
186
237
  book4.should be_a Book
187
238
  book4.excel.should == book2.excel
239
+ book4.Readonly.should == true
240
+ book4.should_not == book2
241
+ book4.close
242
+ book3.close
243
+ end
244
+
245
+ it "should open in a given Excel, provide identity transparency, because book can be readonly, such that the old and the new book are readonly" do
246
+ book2 = Book.open(@simple_file, :force_excel => :new)
247
+ book2.excel.should_not == @book.excel
248
+ book3 = Book.open(@simple_file, :force_excel => :new)
249
+ book3.excel.should_not == book2.excel
250
+ book3.excel.should_not == @book.excel
251
+ book2.close
252
+ book3.close
253
+ @book.close
254
+ book4 = Book.open(@simple_file, :force_excel => book2.excel, :read_only => true)
255
+ book4.should be_alive
256
+ book4.should be_a Book
257
+ book4.excel.should == book2.excel
258
+ book4.ReadOnly.should be_true
259
+ book4.should == book2
188
260
  book4.close
189
261
  book3.close
190
262
  end
@@ -201,6 +273,7 @@ describe Book do
201
273
  context "with :default_excel" do
202
274
 
203
275
  before do
276
+ excel = Excel.new(:reuse => false)
204
277
  @book = Book.open(@simple_file)
205
278
  end
206
279
 
@@ -208,7 +281,7 @@ describe Book do
208
281
  @book.close rescue nil
209
282
  end
210
283
 
211
- it "should reuse an open book" do
284
+ it "should use the open book" do
212
285
  book2 = Book.open(@simple_file, :default_excel => :reuse)
213
286
  book2.excel.should == @book.excel
214
287
  book2.should be_alive
@@ -217,19 +290,52 @@ describe Book do
217
290
  book2.close
218
291
  end
219
292
 
220
- it "should reopen a book" do
293
+ it "should reopen the book in the excel instance where it was opened before" do
294
+ excel = Excel.new(:reuse => false)
221
295
  @book.close
222
- book2 = Book.open(@simple_file, :default_excel => :reuse)
296
+ book2 = Book.open(@simple_file)
223
297
  book2.should be_alive
224
298
  book2.should be_a Book
225
299
  book2.excel.should == @book.excel
300
+ book2.excel.should_not == excel
226
301
  book2.filename.should == @book.filename
227
302
  @book.should be_alive
228
303
  book2.should == @book
229
304
  book2.close
230
305
  end
231
306
 
232
- it "should connect to the first opened excel, if the book cannot be reopened" do
307
+ it "should reopen a book in a new Excel if all Excel instances are closed" do
308
+ excel = Excel.new(:reuse => false)
309
+ excel2 = @book.excel
310
+ fn = @book.filename
311
+ @book.close
312
+ Excel.close_all
313
+ book2 = Book.open(@simple_file, :default_excel => :reuse)
314
+ book2.should be_alive
315
+ book2.should be_a Book
316
+ book2.filename.should == fn
317
+ @book.should be_alive
318
+ book2.should == @book
319
+ book2.close
320
+ end
321
+
322
+ it "should reopen a book in the first opened Excel if the old Excel is closed" do
323
+ excel = @book.excel
324
+ Excel.close_all
325
+ new_excel = Excel.new(:reuse => false)
326
+ new_excel2 = Excel.new(:reuse => false)
327
+ book2 = Book.open(@simple_file, :default_excel => :reuse)
328
+ book2.should be_alive
329
+ book2.should be_a Book
330
+ #book2.excel.should_not == excel
331
+ #book2.excel.should_not == new_excel2
332
+ #book2.excel.should == new_excel
333
+ @book.should be_alive
334
+ book2.should == @book
335
+ book2.close
336
+ end
337
+
338
+ it "should reopen a book in the first opened excel, if the book cannot be reopened" do
233
339
  @book.close
234
340
  Excel.close_all
235
341
  excel1 = Excel.new(:reuse => false)
@@ -242,6 +348,19 @@ describe Book do
242
348
  book2.close
243
349
  end
244
350
 
351
+ it "should reopen a book in the excel instance where it was opened most recently" do
352
+ book2 = Book.open(@simple_file, :force_excel => :new)
353
+ @book.close
354
+ book2.close
355
+ book3 = Book.open(@simple_file)
356
+ book2.should be_alive
357
+ book2.should be_a Book
358
+ book3.excel.should == book2.excel
359
+ book3.excel.should_not == @book.excel
360
+ book3.should == book2
361
+ book3.should_not == @book
362
+ end
363
+
245
364
  it "should open a new excel, if the book cannot be reopened" do
246
365
  @book.close
247
366
  new_excel = Excel.new(:reuse => false)
@@ -493,10 +612,13 @@ describe Book do
493
612
  @new_book.close
494
613
  end
495
614
 
496
- it "should raise an error, if :if_unsaved is default" do
497
- expect {
498
- @new_book = Book.open(@simple_file)
499
- }.to raise_error(ExcelErrorOpen, "book is already open but not saved (#{File.basename(@simple_file)})")
615
+ it "should open the book in a new excel instance, if :if_unsaved is default" do
616
+ @new_book = Book.open(@simple_file)
617
+ @book.should be_alive
618
+ @new_book.should be_alive
619
+ @new_book.filename.should == @book.filename
620
+ @new_book.excel.should_not == @book.excel
621
+ @new_book.close
500
622
  end
501
623
 
502
624
  it "should raise an error, if :if_unsaved is invalid option" do
@@ -574,11 +696,14 @@ describe Book do
574
696
  @new_book.excel.should_not == @book.excel
575
697
  end
576
698
 
577
- it "should raise an error, if :if_obstructed is default" do
578
- expect {
579
- @new_book = Book.open(@simple_file)
580
- }.to raise_error(ExcelErrorOpen, "blocked by a book with the same name in a different path")
699
+ it "should open the book in a new excel instance, if :if_obstructed is default" do
700
+ @new_book = Book.open(@simple_file)
701
+ @book.should be_alive
702
+ @new_book.should be_alive
703
+ @new_book.filename.should_not == @book.filename
704
+ @new_book.excel.should_not == @book.excel
581
705
  end
706
+
582
707
 
583
708
  it "should raise an error, if :if_obstructed is invalid option" do
584
709
  expect {
@@ -647,6 +772,79 @@ describe Book do
647
772
 
648
773
  context "with :read_only" do
649
774
 
775
+ it "should reopen the book with writable (unsaved changes from readonly are not saved)" do
776
+ book = Book.open(@simple_file, :read_only => true)
777
+ book.ReadOnly.should be_true
778
+ book.should be_alive
779
+ sheet = book[0]
780
+ old_cell_value = sheet[0,0].value
781
+ sheet[0,0] = sheet[0,0].value == "simple" ? "complex" : "simple"
782
+ book.Saved.should be_false
783
+ new_book = Book.open(@simple_file, :read_only => false, :if_unsaved => :accept)
784
+ new_book.ReadOnly.should be_false
785
+ new_book.should be_alive
786
+ book.should be_alive
787
+ new_book.should == book
788
+ new_sheet = new_book[0]
789
+ new_cell_value = new_sheet[0,0].value
790
+ new_cell_value.should == old_cell_value
791
+ end
792
+
793
+ it "should reopen the book with readonly (unsaved changes of the writable should be saved)" do
794
+ book = Book.open(@simple_file, :read_only => false)
795
+ book.ReadOnly.should be_false
796
+ book.should be_alive
797
+ sheet = book[0]
798
+ old_cell_value = sheet[0,0].value
799
+ sheet[0,0] = sheet[0,0].value == "simple" ? "complex" : "simple"
800
+ book.Saved.should be_false
801
+ new_book = Book.open(@simple_file, :read_only => true, :if_unsaved => :accept)
802
+ new_book.ReadOnly.should be_true
803
+ new_book.should be_alive
804
+ book.should be_alive
805
+ new_book.should == book
806
+ new_sheet = new_book[0]
807
+ new_cell_value = new_sheet[0,0].value
808
+ new_cell_value.should_not == old_cell_value
809
+ end
810
+
811
+ it "should reopen the book with writable (unsaved changes from readonly are not saved)" do
812
+ book = Book.open(@simple_file, :force_excel => :new, :read_only => true)
813
+ book.ReadOnly.should be_true
814
+ book.should be_alive
815
+ sheet = book[0]
816
+ old_cell_value = sheet[0,0].value
817
+ sheet[0,0] = sheet[0,0].value == "simple" ? "complex" : "simple"
818
+ book.Saved.should be_false
819
+ new_book = Book.open(@simple_file, :force_excel => book.excel, :read_only => false, :if_unsaved => :accept)
820
+ new_book.ReadOnly.should be_false
821
+ new_book.should be_alive
822
+ book.should be_alive
823
+ new_book.should == book
824
+ new_sheet = new_book[0]
825
+ new_cell_value = new_sheet[0,0].value
826
+ new_cell_value.should == old_cell_value
827
+ end
828
+
829
+ it "should reopen the book with readonly (unsaved changes of the writable should be saved)" do
830
+ book = Book.open(@simple_file, :force_excel => :new, :read_only => false)
831
+ book.ReadOnly.should be_false
832
+ book.should be_alive
833
+ sheet = book[0]
834
+ old_cell_value = sheet[0,0].value
835
+ sheet[0,0] = sheet[0,0].value == "simple" ? "complex" : "simple"
836
+ book.Saved.should be_false
837
+ new_book = Book.open(@simple_file, :force_excel => book.excel, :read_only => true, :if_unsaved => :accept)
838
+ new_book.ReadOnly.should be_true
839
+ new_book.should be_alive
840
+ book.should be_alive
841
+ new_book.should == book
842
+ new_sheet = new_book[0]
843
+ new_cell_value = new_sheet[0,0].value
844
+ new_cell_value.should_not == old_cell_value
845
+ end
846
+
847
+
650
848
  it "should open the second book in another Excel as writable" do
651
849
  book = Book.open(@simple_file, :read_only => true)
652
850
  book.ReadOnly.should be_true
@@ -665,7 +863,7 @@ describe Book do
665
863
  book.close
666
864
  end
667
865
 
668
- it "should be able to save, if :read_only is set to default value" do
866
+ it "should be able to save, if :read_only is default" do
669
867
  book = Book.open(@simple_file)
670
868
  book.should be_a Book
671
869
  expect {
@@ -736,6 +934,24 @@ describe Book do
736
934
  end
737
935
  end
738
936
 
937
+ context "with no open book" do
938
+
939
+ it "should open unobtrusively in a new Excel" do
940
+ expect{ unobtrusively_ok? }.to_not raise_error
941
+ end
942
+
943
+ it "should open unobtrusively in the first opened Excel" do
944
+ excel = Excel.new(:reuse => false)
945
+ new_excel = Excel.new(:reuse => false)
946
+ Book.unobtrusively(@simple_file) do |book|
947
+ book.should be_a Book
948
+ book.should be_alive
949
+ book.excel.should == excel
950
+ book.excel.should_not == new_excel
951
+ end
952
+ end
953
+ end
954
+
739
955
  context "with an open book" do
740
956
 
741
957
  before do
@@ -744,6 +960,7 @@ describe Book do
744
960
 
745
961
  after do
746
962
  @book.close(:if_unsaved => :forget)
963
+ @book2.close(:if_unsaved => :forget) rescue nil
747
964
  end
748
965
 
749
966
  it "should let a saved book saved" do
@@ -758,18 +975,36 @@ describe Book do
758
975
  sheet[0,0].value.should_not == old_cell_value
759
976
  end
760
977
 
761
- it "should let an unsaved book unsaved" do
978
+ it "should let the unsaved book unsaved" do
762
979
  sheet = @book[0]
763
- sheet[0,0] = sheet[0,0].value == "simple" ? "complex" : "simple"
764
- @book.Saved.should be_false
765
- @book.should be_alive
980
+ sheet[0,0] = sheet[0,0].value == "simple" ? "complex" : "simple"
766
981
  old_cell_value = sheet[0,0].value
767
- unobtrusively_ok?
768
982
  @book.Saved.should be_false
983
+ unobtrusively_ok?
769
984
  @book.should be_alive
770
- sheet = @book[0]
771
- sheet[0,0].value.should_not == old_cell_value
985
+ @book.Saved.should be_false
986
+ @book.close(:if_unsaved => :forget)
987
+ @book2 = Book.open(@simple_file)
988
+ sheet2 = @book2[0]
989
+ sheet2[0,0].value.should_not == old_cell_value
772
990
  end
991
+
992
+ it "should modify unobtrusively the second, writable book" do
993
+ @book2 = Book.open(@simple_file, :force_excel => :new)
994
+ @book.ReadOnly.should be_false
995
+ @book2.ReadOnly.should be_true
996
+ sheet = @book2[0]
997
+ old_cell_value = sheet[0,0].value
998
+ sheet[0,0] = sheet[0,0].value == "simple" ? "complex" : "simple"
999
+ unobtrusively_ok?
1000
+ @book2.should be_alive
1001
+ @book2.Saved.should be_false
1002
+ @book2.close(:if_unsaved => :forget)
1003
+ @book.close
1004
+ @book = Book.open(@simple_file)
1005
+ sheet2 = @book[0]
1006
+ sheet2[0,0].value.should_not == old_cell_value
1007
+ end
773
1008
  end
774
1009
 
775
1010
  context "with a closed book" do
@@ -779,8 +1014,7 @@ describe Book do
779
1014
  end
780
1015
 
781
1016
  after do
782
- @book.close(:if_unsaved => :forget)
783
- Excel.close_all
1017
+ @book.close(:if_unsaved => :forget)
784
1018
  end
785
1019
 
786
1020
  it "should let the closed book closed by default" do
@@ -810,57 +1044,13 @@ describe Book do
810
1044
  end
811
1045
  @book.should be_alive
812
1046
  @book.close
813
- @book = Book.open(@simple_file)
814
- sheet = @book[0]
1047
+ new_book = Book.open(@simple_file)
1048
+ sheet = new_book[0]
815
1049
  sheet[0,0].value.should_not == old_cell_value
816
1050
  end
817
1051
  end
818
1052
 
819
- context "with two books" do
820
-
821
- before do
822
- @book = Book.open(@simple_file)
823
- end
824
-
825
- after do
826
- @book.close(:if_unsaved => :forget)
827
- @book2.close(:if_unsaved => :forget)
828
- end
829
-
830
- it "should let the unsaved book unsaved" do
831
- sheet = @book[0]
832
- old_cell_value = sheet[0,0].value
833
- sheet[0,0] = sheet[0,0].value == "simple" ? "complex" : "simple"
834
- old_cell_value = sheet[0,0].value
835
- @book.Saved.should be_false
836
- unobtrusively_ok?
837
- @book.should be_alive
838
- @book.Saved.should be_false
839
- @book.close(:if_unsaved => :forget)
840
- @book2 = Book.open(@simple_file)
841
- sheet2 = @book2[0]
842
- sheet2[0,0].value.should_not == old_cell_value
843
- end
844
-
845
- it "should modify unobtrusively the second, writable book" do
846
- @book2 = Book.open(@simple_file, :force_excel => :new)
847
- @book.ReadOnly.should be_false
848
- @book2.ReadOnly.should be_true
849
- sheet = @book2[0]
850
- old_cell_value = sheet[0,0].value
851
- sheet[0,0] = sheet[0,0].value == "simple" ? "complex" : "simple"
852
- unobtrusively_ok?
853
- @book2.should be_alive
854
- @book2.Saved.should be_false
855
- @book2.close(:if_unsaved => :forget)
856
- @book.close
857
- @book = Book.open(@simple_file)
858
- sheet2 = @book[0]
859
- sheet2[0,0].value.should_not == old_cell_value
860
- end
861
- end
862
-
863
- context "with read_only book" do
1053
+ context "with a read_only book" do
864
1054
 
865
1055
  before do
866
1056
  @book = Book.open(@simple_file, :read_only => true)
@@ -902,6 +1092,29 @@ describe Book do
902
1092
  # modifies unobtrusively the saved version, not the unsaved version
903
1093
  sheet2[0,0].value.should == cell_value
904
1094
  end
1095
+
1096
+ it "should modify one of the unobtrusively books" do
1097
+ book2 = Book.open(@simple_file, :force_excel => :new, :read_only => true)
1098
+ @book.ReadOnly.should be_true
1099
+ book2.Readonly.should be_true
1100
+ sheet = @book[0]
1101
+ cell_value = sheet[0,0].value
1102
+ Book.unobtrusively(@simple_file) do |book|
1103
+ book.should be_a Book
1104
+ sheet = book[0]
1105
+ sheet[0,0] = sheet[0,0].value == "simple" ? "complex" : "simple"
1106
+ book.should be_alive
1107
+ book.Saved.should be_false
1108
+ end
1109
+ @book.Saved.should be_true
1110
+ @book.ReadOnly.should be_true
1111
+ @book.close
1112
+ book2.close
1113
+ book3 = Book.open(@simple_file)
1114
+ new_sheet = book3[0]
1115
+ new_sheet[0,0].value.should_not == cell_value
1116
+ book3.close
1117
+ end
905
1118
  end
906
1119
 
907
1120
  context "with a virgin Book class" do
@@ -953,7 +1166,7 @@ describe Book do
953
1166
  m_time2.should_not == m_time
954
1167
  end
955
1168
 
956
- it "should not save the book was not modified during unobtrusively" do
1169
+ it "should not save the book if it was not modified during unobtrusively" do
957
1170
  m_time = File.mtime(@book1.stored_filename)
958
1171
  Book.unobtrusively(@simple_file) do |book|
959
1172
  @book1.Saved.should be_true
@@ -1024,7 +1237,7 @@ describe Book do
1024
1237
  @book1.close(:if_unsaved => :forget)
1025
1238
  end
1026
1239
 
1027
- it "should unobtrusively use a book invisibe" do
1240
+ it "should unobtrusively use a book invisible" do
1028
1241
  @book1.excel.Visible.should be_false
1029
1242
  Book.unobtrusively(@simple_file, :visible => false) do |book|
1030
1243
  @book1.excel.Visible.should be_false
@@ -1037,7 +1250,7 @@ describe Book do
1037
1250
  @book1.excel.Visible.should be_false
1038
1251
  end
1039
1252
 
1040
- it "should unobtrusively use a book visibe" do
1253
+ it "should unobtrusively use a book visible" do
1041
1254
  @book1.excel.Visible.should be_false
1042
1255
  Book.unobtrusively(@simple_file, :visible => true) do |book|
1043
1256
  @book1.excel.Visible.should be_true
@@ -1063,6 +1276,96 @@ describe Book do
1063
1276
  @book1.excel.Visible.should be_false
1064
1277
  end
1065
1278
  end
1279
+
1280
+ context "with several Excel instances" do
1281
+
1282
+ it "should open unobtrusively the closed book in the most recent Excel" do
1283
+ book1 = Book.open(@simple_file)
1284
+ book2 = Book.open(@simple_file, :force_excel => :new)
1285
+ book1.Readonly.should == false
1286
+ book2.Readonly.should == true
1287
+ book1.close
1288
+ book2.close
1289
+ Book.unobtrusively(@simple_file) do |book|
1290
+ book.excel.should == book2.excel
1291
+ book.excel.should_not == book1.excel
1292
+ book.Readonly.should == false
1293
+ end
1294
+ end
1295
+
1296
+ it "should open unobtrusively the closed book in the most recent Excel where it was open before" do
1297
+ book1 = Book.open(@simple_file)
1298
+ book2 = Book.open(@simple_file, :force_excel => :new)
1299
+ book2.Readonly.should == true
1300
+ old_sheet = book1[0]
1301
+ old_cell_value = old_sheet[0,0].value
1302
+ book1.close
1303
+ book2.close
1304
+ book1.should_not be_alive
1305
+ book2.should_not be_alive
1306
+ Book.unobtrusively(@simple_file) do |book|
1307
+ book.excel.should == book2.excel
1308
+ book.excel.should_not == book1.excel
1309
+ book.ReadOnly.should == false
1310
+ sheet = book[0]
1311
+ cell = sheet[0,0]
1312
+ sheet[0,0] = cell.value == "simple" ? "complex" : "simple"
1313
+ book.Saved.should be_false
1314
+ end
1315
+ new_book = Book.open(@simple_file)
1316
+ sheet = new_book[0]
1317
+ sheet[0,0].value.should_not == old_cell_value
1318
+ end
1319
+
1320
+ it "should open unobtrusively the closed book in a new Excel if the Excel is not alive anymore" do
1321
+ book1 = Book.open(@simple_file)
1322
+ book2 = Book.open(@simple_file, :force_excel => :new)
1323
+ book2.Readonly.should == true
1324
+ old_sheet = book1[0]
1325
+ old_cell_value = old_sheet[0,0].value
1326
+ book1.close
1327
+ book2.close
1328
+ book1.should_not be_alive
1329
+ book2.should_not be_alive
1330
+ Excel.close_all
1331
+ Book.unobtrusively(@simple_file) do |book|
1332
+ book.ReadOnly.should == false
1333
+ #book.excel.should_not == book1.excel
1334
+ #book.excel.should_not == book2.excel
1335
+ sheet = book[0]
1336
+ cell = sheet[0,0]
1337
+ sheet[0,0] = cell.value == "simple" ? "complex" : "simple"
1338
+ book.Saved.should be_false
1339
+ end
1340
+ new_book = Book.open(@simple_file)
1341
+ sheet = new_book[0]
1342
+ sheet[0,0].value.should_not == old_cell_value
1343
+ end
1344
+
1345
+ it "should open unobtrusively the once opened book in a new Excel if the Excel is not alive anymore" do
1346
+ book1 = Book.open(@simple_file)
1347
+ book2 = Book.open(@simple_file, :force_excel => :new)
1348
+ book2.Readonly.should == true
1349
+ old_sheet = book1[0]
1350
+ old_cell_value = old_sheet[0,0].value
1351
+ book1.should be_alive
1352
+ book2.should be_alive
1353
+ Excel.close_all
1354
+ Book.unobtrusively(@simple_file) do |book|
1355
+ book.ReadOnly.should == false
1356
+ #book.excel.should_not == book1.excel
1357
+ #book.excel.should_not == book2.excel
1358
+ sheet = book[0]
1359
+ cell = sheet[0,0]
1360
+ sheet[0,0] = cell.value == "simple" ? "complex" : "simple"
1361
+ book.Saved.should be_false
1362
+ end
1363
+ new_book = Book.open(@simple_file)
1364
+ sheet = new_book[0]
1365
+ sheet[0,0].value.should_not == old_cell_value
1366
+ end
1367
+
1368
+ end
1066
1369
  end
1067
1370
 
1068
1371
  describe "nvalue" do
@@ -1228,18 +1531,6 @@ describe Book do
1228
1531
  end
1229
1532
  end
1230
1533
  end
1231
-
1232
- it "should raise error for default" do
1233
- expect{
1234
- @book.close
1235
- }.to raise_error(ExcelErrorClose, "book is unsaved (#{File.basename(@simple_file)})")
1236
- end
1237
-
1238
- it "should raise error for invalid option" do
1239
- expect{
1240
- @book.close(:if_unsaved => :invalid)
1241
- }.to raise_error(ExcelErrorClose, ":if_unsaved: invalid option")
1242
- end
1243
1534
  end
1244
1535
  end
1245
1536
 
@@ -1555,21 +1846,17 @@ describe Book do
1555
1846
  end
1556
1847
 
1557
1848
  it "should make Excel visible" do
1558
- @book.visible = false
1849
+ @book.excel.visible = false
1559
1850
  @book.excel.visible.should be_false
1560
- @book.visible.should be_false
1561
- @book.visible = true
1851
+ @book.excel.visible = true
1562
1852
  @book.excel.visible.should be_true
1563
- @book.visible.should be_true
1564
1853
  end
1565
1854
 
1566
1855
  it "should enable DisplayAlerts in Excel" do
1567
- @book.displayalerts = false
1856
+ @book.excel.displayalerts = false
1568
1857
  @book.excel.displayalerts.should be_false
1569
- @book.displayalerts.should be_false
1570
- @book.displayalerts = true
1858
+ @book.excel.displayalerts = true
1571
1859
  @book.excel.displayalerts.should be_true
1572
- @book.displayalerts.should be_true
1573
1860
  end
1574
1861
 
1575
1862
  end