robust_excel_ole 0.3.5 → 0.3.6

Sign up to get free protection for your applications and to get access to all the features.
data/spec/range_spec.rb CHANGED
@@ -1,18 +1,20 @@
1
1
  # -*- cdoing: utf-8 -*-
2
2
  require File.join(File.dirname(__FILE__), './spec_helper')
3
3
 
4
+ include RobustExcelOle
5
+
4
6
  describe RobustExcelOle::Range do
5
7
 
6
8
  before(:all) do
7
- excel = RobustExcelOle::Excel.new(:reuse => true)
9
+ excel = Excel.new(:reuse => true)
8
10
  open_books = excel == nil ? 0 : excel.Workbooks.Count
9
11
  puts "*** open books *** : #{open_books}" if open_books > 0
10
- RobustExcelOle::Excel.close_all
12
+ Excel.close_all
11
13
  end
12
14
 
13
15
  before do
14
16
  @dir = create_tmpdir
15
- @book = RobustExcelOle::Book.open(@dir + '/workbook.xls')
17
+ @book = Book.open(@dir + '/workbook.xls')
16
18
  @sheet = @book[1]
17
19
  @range = RobustExcelOle::Range.new(@sheet.worksheet.UsedRange.Rows(1))
18
20
  end
@@ -57,7 +59,7 @@ describe RobustExcelOle::Range do
57
59
 
58
60
  context "read 'merge_cells.xls'" do
59
61
  before do
60
- @merge_cells_book = RobustExcelOle::Book.open("#{@dir}/merge_cells.xls")
62
+ @merge_cells_book = Book.open("#{@dir}/merge_cells.xls")
61
63
  @merge_cells_sheet = @merge_cells_book[0]
62
64
  end
63
65
 
@@ -0,0 +1,113 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ require File.join(File.dirname(__FILE__), './spec_helper')
4
+
5
+ $VERBOSE = nil
6
+
7
+ include RobustExcelOle
8
+
9
+ describe RobustExcelOle do
10
+
11
+ before(:all) do
12
+ excel = Excel.new(:reuse => true)
13
+ open_books = excel == nil ? 0 : excel.Workbooks.Count
14
+ puts "*** open books *** : #{open_books}" if open_books > 0
15
+ Excel.close_all
16
+ end
17
+
18
+ before do
19
+ @dir = create_tmpdir
20
+ @simple_file = @dir + '/workbook.xls'
21
+ end
22
+
23
+ after do
24
+ #Excel.close_all
25
+ rm_tmp(@dir)
26
+ end
27
+
28
+ describe "t" do
29
+
30
+ it "should put some" do
31
+ a = 4
32
+ t "some text #{a}"
33
+ end
34
+
35
+ it "should put another text" do
36
+ a = 5
37
+ t "another text #{a}"
38
+ end
39
+
40
+ end
41
+
42
+ describe "#absolute_path" do
43
+
44
+ context "with standard" do
45
+
46
+ before do
47
+ @previous_dir = Dir.getwd
48
+ end
49
+
50
+ after do
51
+ Dir.chdir @previous_dir
52
+ end
53
+
54
+ it "should return the right absolute paths" do
55
+ absolute_path("C:/abc").should == "C:\\abc"
56
+ absolute_path("C:\\abc").should == "C:\\abc"
57
+ Dir.chdir "C:/windows"
58
+ absolute_path("C:abc").downcase.should == Dir.pwd.gsub("/","\\").downcase + "\\abc"
59
+ absolute_path("C:abc").upcase.should == File.expand_path("abc").gsub("/","\\").upcase
60
+ end
61
+
62
+ it "should return right absolute path name" do
63
+ filename = 'C:/Dokumente und Einstellungen/Zauberthomas/Eigene Dateien/robust_excel_ole/spec/book_spec.rb'
64
+ absolute_path(filename).gsub("\\","/").should == filename
65
+ end
66
+ end
67
+ end
68
+
69
+ describe "canonize" do
70
+
71
+ context "with standard" do
72
+
73
+ it "should reduce slash at the end" do
74
+ normalize("hallo/").should == "hallo"
75
+ normalize("/this/is/the/Path/").should == "/this/is/the/Path"
76
+ end
77
+
78
+ it "should save capital letters" do
79
+ normalize("HALLO/").should == "HALLO"
80
+ normalize("/This/IS/tHe/patH/").should == "/This/IS/tHe/patH"
81
+ end
82
+
83
+ it "should reduce multiple shlashes" do
84
+ normalize("/this/is//the/path").should == "/this/is/the/path"
85
+ normalize("///this/////////is//the/path/////").should == "/this/is/the/path"
86
+ end
87
+
88
+ it "should reduce dots in the paths" do
89
+ canonize("/this/is/./the/path").should == "/this/is/the/path"
90
+ canonize("this/.is/./the/pa.th/").should == "this/.is/the/pa.th"
91
+ canonize("this//.///.//.is/the/pa.th/").should == "this/.is/the/pa.th"
92
+ end
93
+
94
+ it "should change to the upper directory with two dots" do
95
+ canonize("/this/is/../the/path").should == "/this/the/path"
96
+ canonize("this../.i.s/.../..the/..../pa.th/").should == "this../.i.s/.../..the/..../pa.th"
97
+ end
98
+
99
+ it "should downcase" do
100
+ canonize("/This/IS/tHe/path").should == "/this/is/the/path"
101
+ canonize("///THIS/.///./////iS//the/../PatH/////").should == "/this/is/path"
102
+ end
103
+
104
+ it "should raise an error for no strings" do
105
+ expect{
106
+ canonize(1)
107
+ }.to raise_error(ExcelError, "No string given to canonize, but 1")
108
+ end
109
+
110
+ end
111
+ end
112
+
113
+ end
data/spec/sheet_spec.rb CHANGED
@@ -16,6 +16,14 @@ describe RobustExcelOle::Sheet do
16
16
  rm_tmp(@dir)
17
17
  end
18
18
 
19
+ before(:all) do
20
+ Excel.close_all
21
+ end
22
+
23
+ after(:all) do
24
+ Excel.close_all
25
+ end
26
+
19
27
  describe ".initialize" do
20
28
  context "when open sheet protected(with password is 'protect')" do
21
29
  before do
@@ -72,7 +80,7 @@ describe RobustExcelOle::Sheet do
72
80
  new_sheet = @book.add_sheet @sheet
73
81
  expect{
74
82
  new_sheet.name = 'foo'
75
- }.to raise_error(ExcelErrorSheet, "sheet name already exists")
83
+ }.to raise_error(ExcelErrorSheet, /sheet name "foo" already exists/)
76
84
  end
77
85
  end
78
86
  end
@@ -377,7 +385,7 @@ describe RobustExcelOle::Sheet do
377
385
  context "returning the value of a range" do
378
386
 
379
387
  before do
380
- @book1 = RobustExcelOle::Book.open(@dir + '/another_workbook.xls', :read_only => true)
388
+ @book1 = RobustExcelOle::Book.open(@dir + '/another_workbook.xls')
381
389
  @sheet1 = @book1[0]
382
390
  end
383
391
 
@@ -393,15 +401,19 @@ describe RobustExcelOle::Sheet do
393
401
  it "should raise an error if name not defined" do
394
402
  expect {
395
403
  value = @sheet1.nvalue("foo")
396
- }.to raise_error(SheetError, "name foo not in sheet")
404
+ }.to raise_error(SheetError, /cannot evaluate name "foo" in sheet/)
397
405
  expect {
398
406
  @sheet1["foo"]
399
- }.to raise_error(SheetError, "name foo not in sheet")
407
+ }.to raise_error(SheetError, /cannot evaluate name "foo" in sheet/)
400
408
  end
401
409
 
402
- it "should return default value if name not defined" do
410
+ it "should return default value if name not defined and default value is given" do
403
411
  @sheet1.nvalue("foo", :default => 2).should == 2
404
412
  end
413
+
414
+ it "should evaluate a formula" do
415
+ @sheet1.nvalue("named_formula").should == 4
416
+ end
405
417
  end
406
418
  end
407
419
 
@@ -428,6 +440,12 @@ describe RobustExcelOle::Sheet do
428
440
  @sheet1.nvalue("firstcell").should == "bar"
429
441
  @sheet1[1,1].Value.should == "bar"
430
442
  end
443
+
444
+ it "should raise an error" do
445
+ expect{
446
+ @sheet1.nvalue("foo")
447
+ }.to raise_error(SheetError, /cannot evaluate name "foo" in sheet/)
448
+ end
431
449
  end
432
450
  end
433
451
 
@@ -461,11 +479,29 @@ describe RobustExcelOle::Sheet do
461
479
  it "should raise an error" do
462
480
  expect{
463
481
  @sheet1.set_name("foo",-2,1)
464
- }.to raise_error(SheetError, "cannot add name foo to cell with row -2 and column 1")
482
+ }.to raise_error(SheetError, /cannot add name "foo" to cell with row -2 and column 1/)
465
483
  end
466
484
  end
467
485
  end
468
486
 
487
+ describe "send methods to worksheet" do
488
+
489
+ it "should send methods to worksheet" do
490
+ @sheet.Cells(1,1).Value.should eq 'foo'
491
+ end
492
+
493
+ it "should raise an error for unknown methods or properties" do
494
+ expect{
495
+ @sheet.Foo
496
+ }.to raise_error(VBAMethodMissingError, /unknown VBA property or method :Foo/)
497
+ end
498
+
499
+ # it "should report that worksheet is not alive" do
500
+ # @book.close
501
+ # expect{ @sheet.Nonexisting_method }.to raise_error(ExcelError, "method missing: worksheet nil")
502
+ # end
503
+ end
504
+
469
505
  describe "#method_missing" do
470
506
  it "can access COM method" do
471
507
  @sheet.Cells(1,1).Value.should eq 'foo'
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: 25
4
+ hash: 31
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 3
9
- - 5
10
- version: 0.3.5
9
+ - 6
10
+ version: 0.3.6
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: 2015-08-13 00:00:00 +02:00
18
+ date: 2015-10-27 00:00:00 +01:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -46,6 +46,7 @@ extra_rdoc_files:
46
46
  - LICENSE
47
47
  files:
48
48
  - .gitignore
49
+ - Changelog
49
50
  - Gemfile
50
51
  - Guardfile
51
52
  - LICENSE
@@ -75,6 +76,7 @@ files:
75
76
  - examples/open_save_close/example_reuse.rb
76
77
  - examples/open_save_close/example_simple.rb
77
78
  - examples/open_save_close/example_unobtrusively.rb
79
+ - lib/reo_console.rb
78
80
  - lib/robust_excel_ole.rb
79
81
  - lib/robust_excel_ole/book.rb
80
82
  - lib/robust_excel_ole/bookstore.rb
@@ -89,14 +91,15 @@ files:
89
91
  - lib/spec_helper.rb
90
92
  - reo.bat
91
93
  - robust_excel_ole.gemspec
92
- - spec/book_close_spec.rb
93
- - spec/book_misc_spec.rb
94
- - spec/book_open_spec.rb
95
- - spec/book_save_spec.rb
96
- - spec/book_sheet_spec.rb
97
- - spec/book_spec.rb
98
- - spec/book_subclass_spec.rb
99
- - spec/book_unobtr_spec.rb
94
+ - spec/book_specs/book_all_spec.rb
95
+ - spec/book_specs/book_close_spec.rb
96
+ - spec/book_specs/book_misc_spec.rb
97
+ - spec/book_specs/book_open_spec.rb
98
+ - spec/book_specs/book_save_spec.rb
99
+ - spec/book_specs/book_sheet_spec.rb
100
+ - spec/book_specs/book_spec.rb
101
+ - spec/book_specs/book_subclass_spec.rb
102
+ - spec/book_specs/book_unobtr_spec.rb
100
103
  - spec/bookstore_spec.rb
101
104
  - spec/cell_spec.rb
102
105
  - spec/cygwin_spec.rb
@@ -116,6 +119,7 @@ files:
116
119
  - spec/helpers/create_temporary_dir.rb
117
120
  - spec/helpers/key_sender.rb
118
121
  - spec/range_spec.rb
122
+ - spec/robust_excel_ole_spec.rb
119
123
  - spec/sheet_spec.rb
120
124
  - spec/spec_helper.rb
121
125
  - version.rb