spec/dependency_builder_spec.rb in rubyfromexcel-0.0.10 vs spec/dependency_builder_spec.rb in rubyfromexcel-0.0.13
- old
+ new
@@ -4,12 +4,12 @@
before(:each) do
SheetNames.instance.clear
SheetNames.instance['Other Sheet'] = 'sheet2'
@workbook = mock(:workbook, :named_references => {'named_cell' => 'sheet2.z10', 'named_cell2' => "sheet2.a('z10','ab10')"})
- @worksheet1 = mock(:worksheet, :to_s => 'sheet1', :workbook => @workbook, :named_references => {'named_cell' => 'sheet1.a1'})
- @worksheet2 = mock(:worksheet, :to_s => 'sheet2', :workbook => @workbook, :named_references => {})
+ @worksheet1 = mock(:worksheet, :to_s => 'sheet1', :workbook => @workbook, :named_references => {'named_cell' => 'sheet1.a1','this_year' => 'sheet1.a1'})
+ @worksheet2 = mock(:worksheet, :to_s => 'sheet2', :workbook => @workbook, :named_references => {'year_matrix' => "sheet1.a('a20','a22')" })
@workbook.stub!(:worksheets => {'sheet1' => @worksheet1, 'sheet2' => @worksheet2 })
@cell = mock(:cell,:worksheet => @worksheet1, :reference => Reference.new('c30',@worksheet1))
@builder = DependencyBuilder.new(@cell)
end
@@ -65,8 +65,18 @@
it "and be able to deal with indirect formulae that call upon other vectors" do
Table.new(@worksheet2,'IndirectVectors2','a1:b10',['ColA','Description'],1)
@worksheet1.should_receive(:cell).with('c1').and_return(mock(:cell,:value_for_including => 'colA',:can_be_replaced_with_value? => true))
@worksheet1.should_receive(:cell).with('c2').and_return(mock(:cell,:value_for_including => 'indirectvectors2',:can_be_replaced_with_value? => true))
dependencies_for('INDIRECT(C2&"["&C1&"]")').should == ["sheet1.c1","sheet1.c2","sheet2.a2", "sheet2.a3", "sheet2.a4", "sheet2.a5", "sheet2.a6", "sheet2.a7", "sheet2.a8", "sheet2.a9"]
- end
+ end
+ it "should be able to deal with awkward combinations of tables and indirects" do
+ @worksheet1.should_receive(:cell).with('c102').twice.and_return(mock(:cell,:value_for_including => 'XVI.a',:can_be_replaced_with_value? => true))
+ @worksheet1.should_receive(:cell).with('a1').and_return(mock(:cell,:value_for_including => '2050',:can_be_replaced_with_value? => true))
+ Table.new(@worksheet1,'XVI.a.Outputs','a1:c41',['2050','Description','Vector'],1)
+ dependencies_for(%q|IFERROR(INDEX(INDIRECT($C102&".Outputs["&this.Year&"]"), MATCH(Z$5, INDIRECT($C102&".Outputs[Vector]"), 0)), 0)|).should == ["sheet1.a1", "sheet1.a30", "sheet1.c102", "sheet1.c30", "sheet1.z5"]
+ Table.new(@worksheet1,'xvi.a.inputs','a1:c41',['2050','Description','Vector'],1)
+ @worksheet1.should_receive(:cell).with('c1').twice.and_return(mock(:cell,:value_for_including => 'Other Sheet',:can_be_replaced_with_value? => true))
+ dependencies_for(%q|INDIRECT("'"&XVI.a.Inputs[#Headers]&"'!Year.Matrix")|).should == ["sheet1.a20", "sheet1.a21", "sheet1.a22", "sheet1.c1"]
+ dependencies_for(%q|MATCH([Vector], INDIRECT("'"&XVI.a.Inputs[#Headers]&"'!Year.Matrix"), 0)|).should == ["sheet1.a20", "sheet1.a21", "sheet1.a22", "sheet1.c1", "sheet1.c30"]
+ end
end
\ No newline at end of file