test/column_test.rb in osheet-0.7.0 vs test/column_test.rb in osheet-0.8.0

- old
+ new

@@ -1,128 +1,121 @@ -require "test/helper" +require "assert" require "osheet/column" module Osheet - class ColumnTest < Test::Unit::TestCase - context "Osheet::Column" do - subject { Column.new } + class ColumnTest < Assert::Context + desc "Osheet::Column" + before { @c = Column.new } + subject { @c } - should_be_a_styled_element(Column) - should_be_a_worksheet_element(Column) - should_be_a_workbook_element(Column) + should_be_a_styled_element(Column) + should_be_a_worksheet_element(Column) + should_be_a_workbook_element(Column) - should_have_instance_method :width - should_have_instance_methods :autofit, :autofit? - should_have_instance_methods :hidden, :hidden? - should_have_instance_method :meta + should have_instance_method :width + 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(:get_ivar, "width") - assert_equal false, subject.send(:get_ivar, "autofit") - assert !subject.autofit? - assert_equal false, subject.send(:get_ivar, "hidden") - assert !subject.hidden? + should "set it's defaults" do + assert_equal nil, subject.send(:get_ivar, "width") + assert_equal false, subject.send(:get_ivar, "autofit") + assert !subject.autofit? + assert_equal false, subject.send(:get_ivar, "hidden") + assert !subject.hidden? - assert_equal nil, subject.meta - end + assert_equal nil, subject.meta + end + should "set it's width" do + subject.width(false) + assert_equal false, subject.width + subject.width(180) + assert_equal 180, subject.width + subject.width(nil) + assert_equal 180, subject.width end - end - class ColumnAttributesTest < Test::Unit::TestCase - context "that has attributes" do - subject do - Column.new do - style_class "more poo" - width 100 - autofit true - hidden true - meta( - {} - ) - end - end + should "cast autofit and hidden to bool" do + col = Column.new { autofit :true; hidden 'false'} + assert_kind_of ::TrueClass, col.send(:get_ivar, "autofit") + assert_kind_of ::TrueClass, col.send(:get_ivar, "hidden") + end - should "should set them correctly" do - assert_equal 100, subject.send(:get_ivar, "width") - assert_equal true, subject.send(:get_ivar, "autofit") - assert subject.autofit? - assert_equal true, subject.send(:get_ivar, "hidden") - assert subject.hidden? - assert_equal({}, subject.meta) - end + end - should "know it's attribute(s)" do - [:style_class, :width, :autofit, :hidden].each do |a| - assert subject.attributes.has_key?(a) - end - assert_equal 'more poo', subject.attributes[:style_class] - assert_equal 100, subject.attributes[:width] - assert_equal true, subject.attributes[:autofit] - assert_equal true, subject.attributes[:hidden] + class ColumnAttributesTest < ColumnTest + desc "that has attributes" + before do + @c = Column.new do + style_class "more poo" + width 100 + autofit true + hidden true + meta( + {} + ) end + end + should "should set them correctly" do + assert_equal 100, subject.send(:get_ivar, "width") + assert_equal true, subject.send(:get_ivar, "autofit") + assert subject.autofit? + assert_equal true, subject.send(:get_ivar, "hidden") + assert subject.hidden? + assert_equal({}, subject.meta) end - end - class ColumnDataTest < Test::Unit::TestCase - context "A column" do - subject { Column.new } - - should "set it's width" do - subject.width(false) - assert_equal false, subject.width - subject.width(180) - assert_equal 180, subject.width - subject.width(nil) - assert_equal 180, subject.width + should "know it's attribute(s)" do + [:style_class, :width, :autofit, :hidden].each do |a| + assert subject.attributes.has_key?(a) end - - should "cast autofit and hidden to bool" do - col = Column.new { autofit :true; hidden 'false'} - assert_kind_of ::TrueClass, col.send(:get_ivar, "autofit") - assert_kind_of ::TrueClass, col.send(:get_ivar, "hidden") - end - + assert_equal 'more poo', subject.attributes[:style_class] + assert_equal 100, subject.attributes[:width] + assert_equal true, subject.attributes[:autofit] + assert_equal true, subject.attributes[:hidden] end + end - class ColumnPartialTest < Test::Unit::TestCase - context "A workbook that defines column partials" do - subject do - Workbook.new { - partial(:column_stuff) { - width 200 - meta(:label => 'awesome') - } - - worksheet { column { - add :column_stuff - } } + class ColumnPartialTest < Assert::Context + desc "A workbook that defines column partials" + before do + @wkbk = Workbook.new { + partial(:column_stuff) { + width 200 + meta(:label => 'awesome') } - end - should "add it's partials to it's markup" do - assert_equal 200, subject.worksheets.first.columns.first.width - assert_equal({:label => 'awesome'}, subject.worksheets.first.columns.first.meta) - end + worksheet { column { + add :column_stuff + } } + } + end + subject { @wkbk } + should "add it's partials to it's markup" do + assert_equal 200, subject.worksheets.first.columns.first.width + assert_equal({:label => 'awesome'}, subject.worksheets.first.columns.first.meta) 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 } + class ColumnBindingTest < Assert::Context + desc "a column defined w/ a block" - 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 + 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