test/workbook_test.rb in osheet-0.4.0 vs test/workbook_test.rb in osheet-0.5.0

- old
+ new

@@ -12,11 +12,11 @@ should_have_instance_methods :title, :style, :template, :attributes, :use should_hm(Workbook, :worksheets, Worksheet) should "set it's defaults" do - assert_equal nil, subject.send(:instance_variable_get, "@title") + assert_equal nil, subject.send(:get_ivar, "title") assert_equal [], subject.worksheets assert_equal StyleSet.new, subject.styles assert_equal TemplateSet.new, subject.templates end @@ -39,11 +39,11 @@ } } end should "set it's title" do - assert_equal "The Poo", subject.send(:instance_variable_get, "@title") + assert_equal "The Poo", subject.send(:get_ivar, "title") end should "know it's title" do subject.title(false) assert_equal false, subject.title @@ -52,11 +52,11 @@ subject.title(nil) assert_equal 'la', subject.title end should "set it's worksheets" do - worksheets = subject.send(:instance_variable_get, "@worksheets") + worksheets = subject.send(:get_ivar, "worksheets") assert_equal 1, worksheets.size assert_kind_of Worksheet, worksheets.first end should "not allow multiple worksheets with the same name" do @@ -135,9 +135,24 @@ end end end + end + + class WorksheetBindingTest < Test::Unit::TestCase + context "a workbook defined w/ a block" do + should "access instance vars from that block's binding" do + @test = 'test' + @workbook = Workbook.new { title @test } + + assert !@workbook.send(:instance_variable_get, "@test").nil? + assert_equal @test, @workbook.send(:instance_variable_get, "@test") + assert_equal @test.object_id, @workbook.send(:instance_variable_get, "@test").object_id + assert_equal @test, @workbook.attributes[:title] + assert_equal @test.object_id, @workbook.attributes[:title].object_id + end + end end class WorkbookMixins < Test::Unit::TestCase context "a workbook w/ mixins" do subject do