robust_excel_ole 1.2 → 1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/spec/sheet_spec.rb CHANGED
@@ -172,6 +172,24 @@ describe Sheet do
172
172
  end
173
173
  end
174
174
 
175
+ describe "range" do
176
+
177
+ it "should create a range of one cell" do
178
+ @sheet.range(1,1).values.should == ["foo"]
179
+ end
180
+
181
+ it "should create a rectangular range" do
182
+ @sheet.range(1..3,2..4).values.should == ["workbook", "sheet1", nil, nil, "foobaaa", nil, "is", "nice", nil]
183
+ end
184
+
185
+ it "should raise an error" do
186
+ expect{
187
+ @sheet.range(0,0)
188
+ }.to raise_error(RangeNotCreated, "cannot create range (0..0,0..0)")
189
+ end
190
+
191
+ end
192
+
175
193
  describe '#each' do
176
194
  it "should sort line in order of column" do
177
195
  @sheet.each_with_index do |cell, i|
@@ -488,7 +506,7 @@ describe Sheet do
488
506
  end
489
507
  end
490
508
 
491
- describe "nameval, set_nameval" do
509
+ describe "namevalue_glob, set_namevalue_glob" do
492
510
 
493
511
  before do
494
512
  @book1 = Book.open(@dir + '/another_workbook.xls')
@@ -500,53 +518,53 @@ describe Sheet do
500
518
  end
501
519
 
502
520
  it "should return value of a defined name" do
503
- @sheet1.nameval("firstcell").should == "foo"
521
+ @sheet1.namevalue_glob("firstcell").should == "foo"
504
522
  end
505
523
 
506
524
  #it "should evaluate a formula" do
507
- # @sheet1.nameval("another_formula").should == 5
525
+ # @sheet1.namevalue_glob("another_formula").should == 5
508
526
  #end
509
527
 
510
528
  it "should raise an error if name not defined" do
511
529
  expect {
512
- @sheet1.nameval("foo")
530
+ @sheet1.namevalue_glob("foo")
513
531
  }.to raise_error(NameNotFound, /name "foo" not in/)
514
532
  end
515
533
 
516
534
  it "should raise an error of coordinates are given instead of a defined name" do
517
535
  expect {
518
- @sheet1.nameval("A1")
536
+ @sheet1.namevalue_glob("A1")
519
537
  }.to raise_error(NameNotFound, /name "A1" not in #<Sheet: Sheet1/)
520
538
  end
521
539
 
522
540
  it "should return default value for a range with empty contents" do
523
- @sheet1.nameval("another", :default => 2) == 2
541
+ @sheet1.namevalue_glob("another", :default => 2) == 2
524
542
  end
525
543
 
526
544
  it "should set a range to a value" do
527
- @sheet1.nameval("firstcell").should == "foo"
545
+ @sheet1.namevalue_glob("firstcell").should == "foo"
528
546
  @sheet1[1,1].Value.should == "foo"
529
- @sheet1.set_nameval("firstcell","bar")
530
- @sheet1.nameval("firstcell").should == "bar"
547
+ @sheet1.set_namevalue_glob("firstcell","bar")
548
+ @sheet1.namevalue_glob("firstcell").should == "bar"
531
549
  @sheet1[1,1].Value.should == "bar"
532
550
  end
533
551
 
534
552
  it "should raise an error if name cannot be evaluated" do
535
553
  expect{
536
- @sheet1.set_nameval("foo", 1)
554
+ @sheet1.set_namevalue_glob("foo", 1)
537
555
  }.to raise_error(NameNotFound, /name "foo" not in #<Sheet: Sheet1/)
538
556
  end
539
557
 
540
558
  it "should color the cell" do
541
- @sheet1.set_nameval("new", "bar")
559
+ @sheet1.set_namevalue_glob("new", "bar")
542
560
  @book1.Names.Item("new").RefersToRange.Interior.ColorIndex.should == -4142
543
- @sheet1.set_nameval("new", "bar", :color => 4)
561
+ @sheet1.set_namevalue_glob("new", "bar", :color => 4)
544
562
  @book1.Names.Item("new").RefersToRange.Interior.ColorIndex.should == 4
545
563
  end
546
564
 
547
565
  end
548
566
 
549
- describe "rangeval, set_rangeval" do
567
+ describe "namevalue, set_namevalue" do
550
568
 
551
569
  before do
552
570
  @book1 = Book.open(@dir + '/another_workbook.xls')
@@ -559,81 +577,81 @@ describe Sheet do
559
577
  end
560
578
 
561
579
  it "should return value of a locally defined name" do
562
- @sheet1.rangeval("firstcell").should == "foo"
580
+ @sheet1.namevalue("firstcell").should == "foo"
563
581
  end
564
582
 
565
583
  it "should return value of a name with coordinates" do
566
- @sheet1.rangeval("A1").should == "foo"
584
+ @sheet1.namevalue("A1").should == "foo"
567
585
  end
568
586
 
569
587
  it "should return nil for a range with empty contents" do
570
- @sheet1.rangeval("another").should == nil
588
+ @sheet1.namevalue("another").should == nil
571
589
  end
572
590
 
573
591
  it "should return value of a defined name" do
574
- @sheet1.rangeval("new").should == "foo"
575
- @sheet1.rangeval("one").should == 1.0
576
- @sheet1.rangeval("four").should == [[1,2],[3,4]]
577
- @sheet1.rangeval("firstrow").should == [[1,2]]
592
+ @sheet1.namevalue("new").should == "foo"
593
+ @sheet1.namevalue("one").should == 1.0
594
+ @sheet1.namevalue("four").should == [[1,2],[3,4]]
595
+ @sheet1.namevalue("firstrow").should == [[1,2]]
578
596
  end
579
597
 
580
598
  it "should return default value if name not defined and default value is given" do
581
- @sheet1.rangeval("foo", :default => 2).should == 2
599
+ @sheet1.namevalue("foo", :default => 2).should == 2
582
600
  end
583
601
 
584
602
  it "should raise an error if name not defined for the sheet" do
585
603
  expect {
586
- @sheet1.rangeval("foo")
604
+ @sheet1.namevalue("foo")
587
605
  }.to raise_error(NameNotFound, /name "foo" not in #<Sheet: Sheet1/)
588
606
  expect {
589
- @sheet1.rangeval("named_formula")
607
+ @sheet1.namevalue("named_formula")
590
608
  }.to raise_error(NameNotFound, /name "named_formula" not in #<Sheet: Sheet1/)
591
609
  expect {
592
- @sheet2.rangeval("firstcell")
610
+ @sheet2.namevalue("firstcell")
593
611
  }.to raise_error(NameNotFound, /name "firstcell" not in #<Sheet: Sheet2/)
594
612
  end
595
613
 
596
614
  it "should set a range to a value" do
597
- @sheet1.rangeval("firstcell").should == "foo"
615
+ @sheet1.namevalue("firstcell").should == "foo"
598
616
  @sheet1[1,1].Value.should == "foo"
599
- @sheet1.set_rangeval("firstcell","bar")
600
- @sheet1.rangeval("firstcell").should == "bar"
617
+ @sheet1.set_namevalue("firstcell","bar")
618
+ @sheet1.namevalue("firstcell").should == "bar"
601
619
  @sheet1[1,1].Value.should == "bar"
602
620
  end
603
621
 
604
622
  it "should raise an error if name cannot be evaluated" do
605
623
  expect{
606
- @sheet1.set_nameval("foo", 1)
624
+ @sheet1.set_namevalue_glob("foo", 1)
607
625
  }.to raise_error(NameNotFound, /name "foo" not in #<Sheet: Sheet1/)
608
626
  end
609
627
 
610
628
  it "should raise an error if name not defined and default value is not provided" do
611
629
  expect {
612
- @sheet1.rangeval("foo", :default => nil)
630
+ @sheet1.namevalue("foo", :default => nil)
613
631
  }.to_not raise_error
614
632
  expect {
615
- @sheet1.rangeval("foo", :default => :__not_provided)
633
+ @sheet1.namevalue("foo", :default => :__not_provided)
616
634
  }.to raise_error(NameNotFound, /name "foo" not in #<Sheet: Sheet1 another_workbook/)
617
635
  expect {
618
- @sheet1.rangeval("foo")
636
+ @sheet1.namevalue("foo")
619
637
  }.to raise_error(NameNotFound, /name "foo" not in #<Sheet: Sheet1 another_workbook/)
620
- @sheet1.rangeval("foo", :default => nil).should be_nil
621
- @sheet1.rangeval("foo", :default => 1).should == 1
622
- @sheet1.nameval("empty", :default => 1).should be_nil
638
+ @sheet1.namevalue("foo", :default => nil).should be_nil
639
+ @sheet1.namevalue("foo", :default => 1).should == 1
640
+ @sheet1.namevalue_glob("empty", :default => 1).should be_nil
623
641
  end
624
642
 
625
643
  it "should color the cell" do
626
- @sheet1.set_rangeval("new", "bar")
644
+ @sheet1.set_namevalue("new", "bar")
627
645
  @book1.Names.Item("new").RefersToRange.Interior.ColorIndex.should == -4142
628
- @sheet1.set_rangeval("new", "bar", :color => 4)
646
+ @sheet1.set_namevalue("new", "bar", :color => 4)
629
647
  @book1.Names.Item("new").RefersToRange.Interior.ColorIndex.should == 4
630
648
  end
631
649
 
632
650
  end
633
651
 
634
- describe "set_name" do
652
+ describe "add_name, delete_name, rename_range" do
635
653
 
636
- context "setting the name of a range" do
654
+ context "adding, renaming, deleting the name of a range" do
637
655
 
638
656
  before do
639
657
  @book1 = Book.open(@dir + '/another_workbook.xls', :read_only => true, :visible => true)
@@ -649,21 +667,41 @@ describe Sheet do
649
667
  expect{
650
668
  @sheet1[1,2].Name.Name
651
669
  }.to raise_error
652
- @sheet1.set_name("foo",1,2)
670
+ @sheet1.add_name("foo",1,2)
653
671
  @sheet1[1,2].Name.Name.should == "Sheet1!foo"
654
672
  end
655
673
 
656
674
  it "should rename an already named range with a giving address" do
657
675
  @sheet1[1,1].Name.Name.should == "Sheet1!firstcell"
658
- @sheet1.set_name("foo",1,1)
676
+ @sheet1.add_name("foo",1,1)
659
677
  @sheet1[1,1].Name.Name.should == "Sheet1!foo"
660
678
  end
661
679
 
662
680
  it "should raise an error" do
663
681
  expect{
664
- @sheet1.set_name("foo",-2,1)
682
+ @sheet1.add_name("foo", -2, 1)
665
683
  }.to raise_error(RangeNotEvaluatable, /cannot add name "foo" to cell with row -2 and column 1/)
666
684
  end
685
+
686
+ it "should rename a range" do
687
+ @sheet1.add_name("foo",1,1)
688
+ @sheet1.rename_range("foo","bar")
689
+ @sheet1.namevalue_glob("bar").should == "foo"
690
+ end
691
+
692
+ it "should delete a name of a range" do
693
+ @sheet1.add_name("foo",1,1)
694
+ @sheet1.delete_name("foo")
695
+ expect{
696
+ @sheet1.namevalue_glob("foo")
697
+ }.to raise_error(NameNotFound, /name "foo"/)
698
+ end
699
+
700
+ it "should add a name of a rectangular range" do
701
+ @sheet1.add_name("foo",1..3,1..4)
702
+ @sheet1["foo"].should == [["foo", "workbook", "sheet1", nil], ["foo", 1.0, 2.0, 4.0], ["matz", 3.0, 4.0, 4.0]]
703
+ end
704
+
667
705
  end
668
706
  end
669
707
 
data/spec/spec_helper.rb CHANGED
@@ -12,7 +12,7 @@ module RobustExcelOle::SpecHelpers
12
12
  end
13
13
 
14
14
  def rm_tmp(tmpdir) # :nodoc: #
15
- FileUtils.remove_entry_secure(File.dirname(tmpdir))
15
+ FileUtils.rm_f(File.dirname(tmpdir))
16
16
  end
17
17
 
18
18
  # This method is almost copy of wycats's implementation.
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: robust_excel_ole
3
3
  version: !ruby/object:Gem::Version
4
- version: '1.2'
4
+ version: '1.3'
5
5
  platform: ruby
6
6
  authors:
7
7
  - traths
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-08-11 00:00:00.000000000 Z
11
+ date: 2018-09-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec