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

- old
+ new

@@ -15,14 +15,14 @@ should_have_instance_methods :autofit, :autofit? should_have_instance_methods :hidden, :hidden? should_have_instance_method :meta should "set it's defaults" do - assert_equal nil, subject.send(:instance_variable_get, "@width") - assert_equal false, subject.send(:instance_variable_get, "@autofit") + assert_equal nil, subject.send(:get_ivar, "width") + assert_equal false, subject.send(:get_ivar, "autofit") assert !subject.autofit? - assert_equal false, subject.send(:instance_variable_get, "@hidden") + assert_equal false, subject.send(:get_ivar, "hidden") assert !subject.hidden? assert_equal nil, subject.meta end @@ -38,14 +38,14 @@ ) end end should "should set them correctly" do - assert_equal 100, subject.send(:instance_variable_get, "@width") - assert_equal true, subject.send(:instance_variable_get, "@autofit") + assert_equal 100, subject.send(:get_ivar, "width") + assert_equal true, subject.send(:get_ivar, "autofit") assert subject.autofit? - assert_equal true, subject.send(:instance_variable_get, "@hidden") + assert_equal true, subject.send(:get_ivar, "hidden") assert subject.hidden? assert_equal({}, subject.meta) end should "know it's width" do @@ -69,13 +69,29 @@ end should "cast autofit and hidden to bool" do col = Column.new { autofit :true; hidden 'false'} - assert_kind_of ::TrueClass, col.send(:instance_variable_get, "@autofit") - assert_kind_of ::TrueClass, col.send(:instance_variable_get, "@hidden") + assert_kind_of ::TrueClass, col.send(:get_ivar, "autofit") + assert_kind_of ::TrueClass, col.send(:get_ivar, "hidden") end end end + + class ColumnBindingTest < Test::Unit::TestCase + context "a column defined w/ a block" do + should "access instance vars from that block's binding" do + @test = 50 + @col = Column.new { width @test } + + assert !@col.send(:instance_variable_get, "@test").nil? + assert_equal @test, @col.send(:instance_variable_get, "@test") + assert_equal @test.object_id, @col.send(:instance_variable_get, "@test").object_id + assert_equal @test, @col.attributes[:width] + assert_equal @test.object_id, @col.attributes[:width].object_id + end + end + end + end