summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--.rubocop.yml6
-rw-r--r--Gemfile1
-rw-r--r--test/content_type/tc_content_type.rb25
-rw-r--r--test/content_type/tc_default.rb5
-rw-r--r--test/content_type/tc_override.rb5
-rw-r--r--test/doc_props/tc_app.rb3
-rw-r--r--test/doc_props/tc_core.rb9
-rw-r--r--test/drawing/tc_area_chart.rb7
-rw-r--r--test/drawing/tc_area_series.rb22
-rw-r--r--test/drawing/tc_axis.rb21
-rw-r--r--test/drawing/tc_bar_3D_chart.rb20
-rw-r--r--test/drawing/tc_bar_chart.rb20
-rw-r--r--test/drawing/tc_bar_series.rb16
-rw-r--r--test/drawing/tc_bubble_chart.rb3
-rw-r--r--test/drawing/tc_bubble_series.rb5
-rw-r--r--test/drawing/tc_cat_axis.rb6
-rw-r--r--test/drawing/tc_chart.rb71
-rw-r--r--test/drawing/tc_d_lbls.rb5
-rw-r--r--test/drawing/tc_data_source.rb3
-rw-r--r--test/drawing/tc_drawing.rb30
-rw-r--r--test/drawing/tc_graphic_frame.rb1
-rw-r--r--test/drawing/tc_hyperlink.rb17
-rw-r--r--test/drawing/tc_line_3d_chart.rb9
-rw-r--r--test/drawing/tc_line_chart.rb7
-rw-r--r--test/drawing/tc_line_series.rb22
-rw-r--r--test/drawing/tc_marker.rb13
-rw-r--r--test/drawing/tc_num_data.rb7
-rw-r--r--test/drawing/tc_num_val.rb6
-rw-r--r--test/drawing/tc_one_cell_anchor.rb11
-rw-r--r--test/drawing/tc_pic.rb27
-rw-r--r--test/drawing/tc_picture_locking.rb22
-rw-r--r--test/drawing/tc_pie_3D_chart.rb7
-rw-r--r--test/drawing/tc_pie_series.rb7
-rw-r--r--test/drawing/tc_scaling.rb2
-rw-r--r--test/drawing/tc_scatter_chart.rb8
-rw-r--r--test/drawing/tc_scatter_series.rb25
-rw-r--r--test/drawing/tc_ser_axis.rb9
-rw-r--r--test/drawing/tc_series.rb5
-rw-r--r--test/drawing/tc_series_title.rb16
-rw-r--r--test/drawing/tc_str_data.rb5
-rw-r--r--test/drawing/tc_str_val.rb8
-rw-r--r--test/drawing/tc_title.rb20
-rw-r--r--test/drawing/tc_two_cell_anchor.rb17
-rw-r--r--test/drawing/tc_val_axis.rb3
-rw-r--r--test/drawing/tc_view_3D.rb13
-rw-r--r--test/drawing/tc_vml_drawing.rb3
-rw-r--r--test/drawing/tc_vml_shape.rb49
-rw-r--r--test/rels/tc_relationship.rb8
-rw-r--r--test/rels/tc_relationships.rb3
-rw-r--r--test/stylesheet/tc_border.rb12
-rw-r--r--test/stylesheet/tc_border_pr.rb10
-rw-r--r--test/stylesheet/tc_cell_alignment.rb37
-rw-r--r--test/stylesheet/tc_cell_protection.rb8
-rw-r--r--test/stylesheet/tc_cell_style.rb24
-rw-r--r--test/stylesheet/tc_color.rb13
-rw-r--r--test/stylesheet/tc_dxf.rb14
-rw-r--r--test/stylesheet/tc_font.rb55
-rw-r--r--test/stylesheet/tc_gradient_fill.rb28
-rw-r--r--test/stylesheet/tc_gradient_stop.rb9
-rw-r--r--test/stylesheet/tc_num_fmt.rb8
-rw-r--r--test/stylesheet/tc_pattern_fill.rb13
-rw-r--r--test/stylesheet/tc_styles.rb108
-rw-r--r--test/stylesheet/tc_table_style.rb20
-rw-r--r--test/stylesheet/tc_table_style_element.rb14
-rw-r--r--test/stylesheet/tc_table_styles.rb8
-rw-r--r--test/stylesheet/tc_xf.rb56
-rw-r--r--test/tc_axlsx.rb37
-rw-r--r--test/tc_package.rb75
-rw-r--r--test/util/tc_mime_type_utils.rb4
-rw-r--r--test/util/tc_serialized_attributes.rb1
-rw-r--r--test/util/tc_simple_typed_list.rb29
-rw-r--r--test/workbook/tc_defined_name.rb8
-rw-r--r--test/workbook/tc_shared_strings_table.rb10
-rw-r--r--test/workbook/tc_workbook.rb53
-rw-r--r--test/workbook/tc_workbook_view.rb1
-rw-r--r--test/workbook/worksheet/auto_filter/tc_auto_filter.rb6
-rw-r--r--test/workbook/worksheet/auto_filter/tc_filter_column.rb6
-rw-r--r--test/workbook/worksheet/auto_filter/tc_filters.rb13
-rw-r--r--test/workbook/worksheet/tc_border_creator.rb17
-rw-r--r--test/workbook/worksheet/tc_break.rb7
-rw-r--r--test/workbook/worksheet/tc_cell.rb242
-rw-r--r--test/workbook/worksheet/tc_cfvo.rb9
-rw-r--r--test/workbook/worksheet/tc_col.rb33
-rw-r--r--test/workbook/worksheet/tc_color_scale.rb18
-rw-r--r--test/workbook/worksheet/tc_comment.rb42
-rw-r--r--test/workbook/worksheet/tc_comments.rb11
-rw-r--r--test/workbook/worksheet/tc_conditional_formatting.rb70
-rw-r--r--test/workbook/worksheet/tc_data_bar.rb20
-rw-r--r--test/workbook/worksheet/tc_data_validation.rb37
-rw-r--r--test/workbook/worksheet/tc_date_time_converter.rb5
-rw-r--r--test/workbook/worksheet/tc_header_footer.rb26
-rw-r--r--test/workbook/worksheet/tc_icon_set.rb21
-rw-r--r--test/workbook/worksheet/tc_outline_pr.rb6
-rw-r--r--test/workbook/worksheet/tc_page_margins.rb36
-rw-r--r--test/workbook/worksheet/tc_page_set_up_pr.rb4
-rw-r--r--test/workbook/worksheet/tc_page_setup.rb40
-rw-r--r--test/workbook/worksheet/tc_pane.rb12
-rw-r--r--test/workbook/worksheet/tc_pivot_table.rb43
-rw-r--r--test/workbook/worksheet/tc_pivot_table_cache_definition.rb8
-rw-r--r--test/workbook/worksheet/tc_print_options.rb44
-rw-r--r--test/workbook/worksheet/tc_protected_range.rb1
-rw-r--r--test/workbook/worksheet/tc_rich_text.rb18
-rw-r--r--test/workbook/worksheet/tc_rich_text_run.rb53
-rw-r--r--test/workbook/worksheet/tc_row.rb52
-rw-r--r--test/workbook/worksheet/tc_selection.rb8
-rw-r--r--test/workbook/worksheet/tc_sheet_calc_pr.rb3
-rw-r--r--test/workbook/worksheet/tc_sheet_format_pr.rb2
-rw-r--r--test/workbook/worksheet/tc_sheet_pr.rb26
-rw-r--r--test/workbook/worksheet/tc_sheet_protection.rb1
-rw-r--r--test/workbook/worksheet/tc_sheet_view.rb41
-rw-r--r--test/workbook/worksheet/tc_table.rb27
-rw-r--r--test/workbook/worksheet/tc_table_style_info.rb1
-rw-r--r--test/workbook/worksheet/tc_worksheet.rb221
-rw-r--r--test/workbook/worksheet/tc_worksheet_hyperlink.rb22
114 files changed, 1524 insertions, 1016 deletions
diff --git a/.rubocop.yml b/.rubocop.yml
index 510c1b4b..cd74c973 100644
--- a/.rubocop.yml
+++ b/.rubocop.yml
@@ -1,5 +1,8 @@
inherit_from: .rubocop_todo.yml
+require:
+ - rubocop-minitest
+
AllCops:
DisabledByDefault: true
NewCops: enable
@@ -22,5 +25,8 @@ Layout/ExtraSpacing:
Lint:
Enabled: true
+Minitest:
+ Enabled: true
+
Style:
Enabled: true
diff --git a/Gemfile b/Gemfile
index fb69c977..d8395514 100644
--- a/Gemfile
+++ b/Gemfile
@@ -3,6 +3,7 @@ gemspec
group :development, :test do
gem 'rubocop'
+ gem 'rubocop-minitest'
end
group :test do
diff --git a/test/content_type/tc_content_type.rb b/test/content_type/tc_content_type.rb
index a657f7e2..b9d36063 100644
--- a/test/content_type/tc_content_type.rb
+++ b/test/content_type/tc_content_type.rb
@@ -8,7 +8,8 @@ class TestContentType < Test::Unit::TestCase
def test_valid_document
schema = Nokogiri::XML::Schema(File.open(Axlsx::CONTENT_TYPES_XSD))
- assert(schema.validate(@doc).map { |e| puts e.message; e.message }.empty?)
+
+ assert_empty(schema.validate(@doc).map { |e| puts e.message; e.message })
end
def test_pre_built_types
@@ -16,27 +17,33 @@ class TestContentType < Test::Unit::TestCase
d_path = "//xmlns:Default[@ContentType='%s']"
# default
- assert_equal(@doc.xpath("//xmlns:Default").size, 2, "There should be 2 default types")
+ assert_equal(2, @doc.xpath("//xmlns:Default").size, "There should be 2 default types")
node = @doc.xpath(d_path % Axlsx::XML_CT).first
+
assert_equal(node["Extension"], Axlsx::XML_EX.to_s, "xml content type invalid")
node = @doc.xpath(d_path % Axlsx::RELS_CT).first
+
assert_equal(node["Extension"], Axlsx::RELS_EX.to_s, "relationships content type invalid")
# overrride
- assert_equal(@doc.xpath("//xmlns:Override").size, 4, "There should be 4 Override types")
+ assert_equal(4, @doc.xpath("//xmlns:Override").size, "There should be 4 Override types")
node = @doc.xpath(o_path % Axlsx::APP_CT).first
+
assert_equal(node["PartName"], "/#{Axlsx::APP_PN}", "App part name invalid")
node = @doc.xpath(o_path % Axlsx::CORE_CT).first
+
assert_equal(node["PartName"], "/#{Axlsx::CORE_PN}", "Core part name invalid")
node = @doc.xpath(o_path % Axlsx::STYLES_CT).first
+
assert_equal(node["PartName"], "/xl/#{Axlsx::STYLES_PN}", "Styles part name invalid")
node = @doc.xpath(o_path % Axlsx::WORKBOOK_CT).first
+
assert_equal(node["PartName"], "/#{Axlsx::WORKBOOK_PN}", "Workbook part invalid")
end
@@ -45,12 +52,14 @@ class TestContentType < Test::Unit::TestCase
ws = @package.workbook.add_worksheet
doc = Nokogiri::XML(@package.send(:content_types).to_xml_string)
- assert_equal(doc.xpath("//xmlns:Override").size, 5, "adding a worksheet should add another type")
+
+ assert_equal(5, doc.xpath("//xmlns:Override").size, "adding a worksheet should add another type")
assert_equal(doc.xpath(o_path % Axlsx::WORKSHEET_CT).last["PartName"], "/xl/#{ws.pn}", "Worksheet part invalid")
ws = @package.workbook.add_worksheet
doc = Nokogiri::XML(@package.send(:content_types).to_xml_string)
- assert_equal(doc.xpath("//xmlns:Override").size, 6, "adding workship should add another type")
+
+ assert_equal(6, doc.xpath("//xmlns:Override").size, "adding workship should add another type")
assert_equal(doc.xpath(o_path % Axlsx::WORKSHEET_CT).last["PartName"], "/xl/#{ws.pn}", "Worksheet part invalid")
end
@@ -60,13 +69,15 @@ class TestContentType < Test::Unit::TestCase
c = ws.add_chart Axlsx::Pie3DChart
doc = Nokogiri::XML(@package.send(:content_types).to_xml_string)
- assert_equal(doc.xpath("//xmlns:Override").size, 7, "expected 7 types got #{doc.css("Types Override").size}")
+
+ assert_equal(7, doc.xpath("//xmlns:Override").size, "expected 7 types got #{doc.css("Types Override").size}")
assert_equal(doc.xpath(o_path % Axlsx::DRAWING_CT).first["PartName"], "/xl/#{ws.drawing.pn}", "Drawing part name invlid")
assert_equal(doc.xpath(o_path % Axlsx::CHART_CT).last["PartName"], "/xl/#{c.pn}", "Chart part name invlid")
c = ws.add_chart Axlsx::Pie3DChart
doc = Nokogiri::XML(@package.send(:content_types).to_xml_string)
- assert_equal(doc.xpath("//xmlns:Override").size, 8, "expected 7 types got #{doc.css("Types Override").size}")
+
+ assert_equal(8, doc.xpath("//xmlns:Override").size, "expected 7 types got #{doc.css("Types Override").size}")
assert_equal(doc.xpath(o_path % Axlsx::CHART_CT).last["PartName"], "/xl/#{c.pn}", "Chart part name invlid")
end
end
diff --git a/test/content_type/tc_default.rb b/test/content_type/tc_default.rb
index 096a117a..460cf017 100644
--- a/test/content_type/tc_default.rb
+++ b/test/content_type/tc_default.rb
@@ -8,7 +8,8 @@ class TestDefault < Test::Unit::TestCase
def test_to_xml_string
type = Axlsx::Default.new :Extension => "xml", :ContentType => Axlsx::XML_CT
doc = Nokogiri::XML(type.to_xml_string)
- assert_equal(doc.xpath("Default[@ContentType='#{Axlsx::XML_CT}']").size, 1)
- assert_equal(doc.xpath("Default[@Extension='xml']").size, 1)
+
+ assert_equal(1, doc.xpath("Default[@ContentType='#{Axlsx::XML_CT}']").size)
+ assert_equal(1, doc.xpath("Default[@Extension='xml']").size)
end
end
diff --git a/test/content_type/tc_override.rb b/test/content_type/tc_override.rb
index 952f40d8..ff00df94 100644
--- a/test/content_type/tc_override.rb
+++ b/test/content_type/tc_override.rb
@@ -7,7 +7,8 @@ class TestOverride < Test::Unit::TestCase
def test_to_xml
type = Axlsx::Override.new :PartName => "somechart.xml", :ContentType => Axlsx::CHART_CT
doc = Nokogiri::XML(type.to_xml_string)
- assert_equal(doc.xpath("Override[@ContentType='#{Axlsx::CHART_CT}']").size, 1)
- assert_equal(doc.xpath("Override[@PartName='somechart.xml']").size, 1)
+
+ assert_equal(1, doc.xpath("Override[@ContentType='#{Axlsx::CHART_CT}']").size)
+ assert_equal(1, doc.xpath("Override[@PartName='somechart.xml']").size)
end
end
diff --git a/test/doc_props/tc_app.rb b/test/doc_props/tc_app.rb
index cee3e564..94358fc5 100644
--- a/test/doc_props/tc_app.rb
+++ b/test/doc_props/tc_app.rb
@@ -38,6 +38,7 @@ class TestApp < Test::Unit::TestCase
schema.validate(doc).each do |error|
errors << error
end
- assert_equal(errors.size, 0, "app.xml invalid" + errors.map(&:message).to_s)
+
+ assert_equal(0, errors.size, "app.xml invalid" + errors.map(&:message).to_s)
end
end
diff --git a/test/doc_props/tc_core.rb b/test/doc_props/tc_core.rb
index d5412a4f..6aafca3e 100644
--- a/test/doc_props/tc_core.rb
+++ b/test/doc_props/tc_core.rb
@@ -15,7 +15,8 @@ class TestCore < Test::Unit::TestCase
puts error.message
errors << error
end
- assert_equal(errors.size, 0, "core.xml Invalid" + errors.map(&:message).to_s)
+
+ assert_equal(0, errors.size, "core.xml Invalid" + errors.map(&:message).to_s)
end
def test_populates_created
@@ -26,16 +27,18 @@ class TestCore < Test::Unit::TestCase
time = Time.utc(2013, 1, 1, 12, 0)
c = Axlsx::Core.new :created => time
doc = Nokogiri::XML(c.to_xml_string)
+
assert_equal(doc.xpath('//dcterms:created').text, time.xmlschema, "dcterms:created incorrect")
end
def test_populates_default_name
- assert_equal(@doc.xpath('//dc:creator').text, "axlsx", "Default name not populated")
+ assert_equal("axlsx", @doc.xpath('//dc:creator').text, "Default name not populated")
end
def test_creator_as_option
c = Axlsx::Core.new :creator => "some guy"
doc = Nokogiri::XML(c.to_xml_string)
- assert(doc.xpath('//dc:creator').text == "some guy")
+
+ assert_equal("some guy", doc.xpath('//dc:creator').text)
end
end
diff --git a/test/drawing/tc_area_chart.rb b/test/drawing/tc_area_chart.rb
index 490df25a..64a4cedb 100644
--- a/test/drawing/tc_area_chart.rb
+++ b/test/drawing/tc_area_chart.rb
@@ -11,7 +11,7 @@ class TestAreaChart < Test::Unit::TestCase
def teardown; end
def test_initialization
- assert_equal(@chart.grouping, :standard, "grouping defualt incorrect")
+ assert_equal(:standard, @chart.grouping, "grouping defualt incorrect")
assert_equal(@chart.series_type, Axlsx::AreaSeries, "series type incorrect")
assert(@chart.cat_axis.is_a?(Axlsx::CatAxis), "category axis not created")
assert(@chart.val_axis.is_a?(Axlsx::ValAxis), "value access not created")
@@ -20,7 +20,7 @@ class TestAreaChart < Test::Unit::TestCase
def test_grouping
assert_raise(ArgumentError, "require valid grouping") { @chart.grouping = :inverted }
assert_nothing_raised("allow valid grouping") { @chart.grouping = :stacked }
- assert(@chart.grouping == :stacked)
+ assert_equal(:stacked, @chart.grouping)
end
def test_to_xml
@@ -31,6 +31,7 @@ class TestAreaChart < Test::Unit::TestCase
errors.push error
puts error.message
end
- assert(errors.empty?, "error free validation")
+
+ assert_empty(errors, "error free validation")
end
end
diff --git a/test/drawing/tc_area_series.rb b/test/drawing/tc_area_series.rb
index 250c6e13..0ac562b3 100644
--- a/test/drawing/tc_area_series.rb
+++ b/test/drawing/tc_area_series.rb
@@ -16,42 +16,48 @@ class TestAreaSeries < Test::Unit::TestCase
end
def test_initialize
- assert_equal(@series.title.text, "bob", "series title has been applied")
+ assert_equal("bob", @series.title.text, "series title has been applied")
assert_equal(@series.labels.class, Axlsx::AxDataSource)
assert_equal(@series.data.class, Axlsx::NumDataSource)
end
def test_show_marker
- assert_equal(true, @series.show_marker)
+ assert(@series.show_marker)
@series.show_marker = false
- assert_equal(false, @series.show_marker)
+
+ refute(@series.show_marker)
end
def test_smooth
- assert_equal(true, @series.smooth)
+ assert(@series.smooth)
@series.smooth = false
- assert_equal(false, @series.smooth)
+
+ refute(@series.smooth)
end
def test_marker_symbol
assert_equal(:default, @series.marker_symbol)
@series.marker_symbol = :circle
+
assert_equal(:circle, @series.marker_symbol)
end
def test_to_xml_string
doc = Nokogiri::XML(wrap_with_namespaces(@series))
+
assert(doc.xpath("//srgbClr[@val='#{@series.color}']"))
- assert_equal(xpath_with_namespaces(doc, "//c:marker").size, 0)
+ assert_equal(0, xpath_with_namespaces(doc, "//c:marker").size)
assert(doc.xpath("//smooth"))
@series.marker_symbol = :diamond
doc = Nokogiri::XML(wrap_with_namespaces(@series))
- assert_equal(xpath_with_namespaces(doc, "//c:marker/c:symbol[@val='diamond']").size, 1)
+
+ assert_equal(1, xpath_with_namespaces(doc, "//c:marker/c:symbol[@val='diamond']").size)
@series.show_marker = false
doc = Nokogiri::XML(wrap_with_namespaces(@series))
- assert_equal(xpath_with_namespaces(doc, "//c:marker/c:symbol[@val='none']").size, 1)
+
+ assert_equal(1, xpath_with_namespaces(doc, "//c:marker/c:symbol[@val='none']").size)
end
def wrap_with_namespaces(series)
diff --git a/test/drawing/tc_axis.rb b/test/drawing/tc_axis.rb
index 0b3bddc0..e9269b6e 100644
--- a/test/drawing/tc_axis.rb
+++ b/test/drawing/tc_axis.rb
@@ -6,10 +6,10 @@ class TestAxis < Test::Unit::TestCase
end
def test_initialization
- assert_equal(@axis.ax_pos, :b, "axis position default incorrect")
- assert_equal(@axis.tick_lbl_pos, :nextTo, "tick label position default incorrect")
- assert_equal(@axis.tick_lbl_pos, :nextTo, "tick label position default incorrect")
- assert_equal(@axis.crosses, :autoZero, "tick label position default incorrect")
+ assert_equal(:b, @axis.ax_pos, "axis position default incorrect")
+ assert_equal(:nextTo, @axis.tick_lbl_pos, "tick label position default incorrect")
+ assert_equal(:nextTo, @axis.tick_lbl_pos, "tick label position default incorrect")
+ assert_equal(:autoZero, @axis.crosses, "tick label position default incorrect")
assert(@axis.scaling.is_a?(Axlsx::Scaling) && @axis.scaling.orientation == :minMax, "scaling default incorrect")
assert_equal('Foo', @axis.title.text)
end
@@ -20,6 +20,7 @@ class TestAxis < Test::Unit::TestCase
str = '<?xml version="1.0" encoding="UTF-8"?>'
str << '<c:chartSpace xmlns:c="' << Axlsx::XML_NS_C << '" xmlns:a="' << Axlsx::XML_NS_A << '">'
doc = Nokogiri::XML(@axis.to_xml_string(str))
+
assert(doc.xpath("//a:srgbClr[@val='00FF00']"))
end
@@ -32,6 +33,7 @@ class TestAxis < Test::Unit::TestCase
sheet.add_chart(Axlsx::Line3DChart) do |chart|
chart.add_series :data => sheet['B2:D2'], :labels => sheet['B1']
chart.val_axis.title = sheet['A1']
+
assert_equal('battle victories', chart.val_axis.title.text)
end
end
@@ -47,7 +49,7 @@ class TestAxis < Test::Unit::TestCase
assert_raise(ArgumentError, "requires valid angle") { @axis.label_rotation = 91 }
assert_raise(ArgumentError, "requires valid angle") { @axis.label_rotation = -91 }
assert_nothing_raised("accepts valid angle") { @axis.label_rotation = 45 }
- assert_equal(@axis.label_rotation, 45 * 60000)
+ assert_equal(45 * 60000, @axis.label_rotation)
end
def test_tick_label_position
@@ -75,15 +77,15 @@ class TestAxis < Test::Unit::TestCase
def test_format_code_resets_source_linked
create_chart_with_formatting("#,##0.00") do |doc|
- assert_equal(doc.xpath("//c:valAx/c:numFmt[@formatCode='#,##0.00']").size, 1)
- assert_equal(doc.xpath("//c:valAx/c:numFmt[@sourceLinked='0']").size, 1)
+ assert_equal(1, doc.xpath("//c:valAx/c:numFmt[@formatCode='#,##0.00']").size)
+ assert_equal(1, doc.xpath("//c:valAx/c:numFmt[@sourceLinked='0']").size)
end
end
def test_no_format_code_keeps_source_linked
create_chart_with_formatting do |doc|
- assert_equal(doc.xpath("//c:valAx/c:numFmt[@formatCode='General']").size, 1)
- assert_equal(doc.xpath("//c:valAx/c:numFmt[@sourceLinked='1']").size, 1)
+ assert_equal(1, doc.xpath("//c:valAx/c:numFmt[@formatCode='General']").size)
+ assert_equal(1, doc.xpath("//c:valAx/c:numFmt[@sourceLinked='1']").size)
end
end
@@ -102,6 +104,7 @@ class TestAxis < Test::Unit::TestCase
str = '<?xml version="1.0" encoding="UTF-8"?>'
str << '<c:chartSpace xmlns:c="' << Axlsx::XML_NS_C << '" xmlns:a="' << Axlsx::XML_NS_A << '">'
doc = Nokogiri::XML(@axis.to_xml_string(str))
+
assert(doc.xpath('//a:noFill'))
assert(doc.xpath("//c:crosses[@val='#{@axis.crosses}']"))
assert(doc.xpath("//c:crossAx[@val='#{@axis.cross_axis}']"))
diff --git a/test/drawing/tc_bar_3D_chart.rb b/test/drawing/tc_bar_3D_chart.rb
index 178ee65a..a2e245f6 100644
--- a/test/drawing/tc_bar_3D_chart.rb
+++ b/test/drawing/tc_bar_3D_chart.rb
@@ -11,9 +11,9 @@ class TestBar3DChart < Test::Unit::TestCase
def teardown; end
def test_initialization
- assert_equal(@chart.grouping, :clustered, "grouping defualt incorrect")
+ assert_equal(:clustered, @chart.grouping, "grouping defualt incorrect")
assert_equal(@chart.series_type, Axlsx::BarSeries, "series type incorrect")
- assert_equal(@chart.bar_dir, :bar, " bar direction incorrect")
+ assert_equal(:bar, @chart.bar_dir, " bar direction incorrect")
assert(@chart.cat_axis.is_a?(Axlsx::CatAxis), "category axis not created")
assert(@chart.val_axis.is_a?(Axlsx::ValAxis), "value access not created")
end
@@ -21,33 +21,33 @@ class TestBar3DChart < Test::Unit::TestCase
def test_bar_direction
assert_raise(ArgumentError, "require valid bar direction") { @chart.bar_dir = :left }
assert_nothing_raised("allow valid bar direction") { @chart.bar_dir = :col }
- assert(@chart.bar_dir == :col)
+ assert_equal(:col, @chart.bar_dir)
end
def test_grouping
assert_raise(ArgumentError, "require valid grouping") { @chart.grouping = :inverted }
assert_nothing_raised("allow valid grouping") { @chart.grouping = :standard }
- assert(@chart.grouping == :standard)
+ assert_equal(:standard, @chart.grouping)
end
def test_gap_width
assert_raise(ArgumentError, "require valid gap width") { @chart.gap_width = -1 }
assert_raise(ArgumentError, "require valid gap width") { @chart.gap_width = 501 }
assert_nothing_raised("allow valid gapWidth") { @chart.gap_width = 200 }
- assert_equal(@chart.gap_width, 200, 'gap width is incorrect')
+ assert_equal(200, @chart.gap_width, 'gap width is incorrect')
end
def test_gap_depth
assert_raise(ArgumentError, "require valid gap_depth") { @chart.gap_depth = -1 }
assert_raise(ArgumentError, "require valid gap_depth") { @chart.gap_depth = 501 }
assert_nothing_raised("allow valid gap_depth") { @chart.gap_depth = 200 }
- assert_equal(@chart.gap_depth, 200, 'gap depth is incorrect')
+ assert_equal(200, @chart.gap_depth, 'gap depth is incorrect')
end
def test_shape
assert_raise(ArgumentError, "require valid shape") { @chart.shape = :star }
assert_nothing_raised("allow valid shape") { @chart.shape = :cone }
- assert(@chart.shape == :cone)
+ assert_equal(:cone, @chart.shape)
end
def test_to_xml_string
@@ -58,13 +58,15 @@ class TestBar3DChart < Test::Unit::TestCase
errors.push error
puts error.message
end
- assert(errors.empty?, "error free validation")
+
+ assert_empty(errors, "error free validation")
end
def test_to_xml_string_has_axes_in_correct_order
str = @chart.to_xml_string
cat_axis_position = str.index(@chart.axes[:cat_axis].id.to_s)
val_axis_position = str.index(@chart.axes[:val_axis].id.to_s)
+
assert(cat_axis_position < val_axis_position, "cat_axis must occur earlier than val_axis in the XML")
end
@@ -72,6 +74,7 @@ class TestBar3DChart < Test::Unit::TestCase
gap_depth_value = rand(0..500)
@chart.gap_depth = gap_depth_value
doc = Nokogiri::XML(@chart.to_xml_string)
+
assert_equal(doc.xpath("//c:bar3DChart/c:gapDepth").first.attribute('val').value, gap_depth_value.to_s)
end
@@ -79,6 +82,7 @@ class TestBar3DChart < Test::Unit::TestCase
gap_width_value = rand(0..500)
@chart.gap_width = gap_width_value
doc = Nokogiri::XML(@chart.to_xml_string)
+
assert_equal(doc.xpath("//c:bar3DChart/c:gapWidth").first.attribute('val').value, gap_width_value.to_s)
end
end
diff --git a/test/drawing/tc_bar_chart.rb b/test/drawing/tc_bar_chart.rb
index 62927bc7..be5514c4 100644
--- a/test/drawing/tc_bar_chart.rb
+++ b/test/drawing/tc_bar_chart.rb
@@ -11,9 +11,9 @@ class TestBarChart < Test::Unit::TestCase
def teardown; end
def test_initialization
- assert_equal(@chart.grouping, :clustered, "grouping defualt incorrect")
+ assert_equal(:clustered, @chart.grouping, "grouping defualt incorrect")
assert_equal(@chart.series_type, Axlsx::BarSeries, "series type incorrect")
- assert_equal(@chart.bar_dir, :bar, " bar direction incorrect")
+ assert_equal(:bar, @chart.bar_dir, " bar direction incorrect")
assert(@chart.cat_axis.is_a?(Axlsx::CatAxis), "category axis not created")
assert(@chart.val_axis.is_a?(Axlsx::ValAxis), "value access not created")
end
@@ -21,33 +21,33 @@ class TestBarChart < Test::Unit::TestCase
def test_bar_direction
assert_raise(ArgumentError, "require valid bar direction") { @chart.bar_dir = :left }
assert_nothing_raised("allow valid bar direction") { @chart.bar_dir = :col }
- assert(@chart.bar_dir == :col)
+ assert_equal(:col, @chart.bar_dir)
end
def test_grouping
assert_raise(ArgumentError, "require valid grouping") { @chart.grouping = :inverted }
assert_nothing_raised("allow valid grouping") { @chart.grouping = :standard }
- assert(@chart.grouping == :standard)
+ assert_equal(:standard, @chart.grouping)
end
def test_gap_width
assert_raise(ArgumentError, "require valid gap width") { @chart.gap_width = -1 }
assert_raise(ArgumentError, "require valid gap width") { @chart.gap_width = 501 }
assert_nothing_raised("allow valid gap width") { @chart.gap_width = 200 }
- assert_equal(@chart.gap_width, 200, 'gap width is incorrect')
+ assert_equal(200, @chart.gap_width, 'gap width is incorrect')
end
def test_overlap
assert_raise(ArgumentError, "require valid overlap") { @chart.overlap = -101 }
assert_raise(ArgumentError, "require valid overlap") { @chart.overlap = 101 }
assert_nothing_raised("allow valid overlap") { @chart.overlap = 100 }
- assert_equal(@chart.overlap, 100, 'overlap is incorrect')
+ assert_equal(100, @chart.overlap, 'overlap is incorrect')
end
def test_shape
assert_raise(ArgumentError, "require valid shape") { @chart.shape = :star }
assert_nothing_raised("allow valid shape") { @chart.shape = :cone }
- assert(@chart.shape == :cone)
+ assert_equal(:cone, @chart.shape)
end
def test_to_xml_string
@@ -58,13 +58,15 @@ class TestBarChart < Test::Unit::TestCase
errors.push error
puts error.message
end
- assert(errors.empty?, "error free validation")
+
+ assert_empty(errors, "error free validation")
end
def test_to_xml_string_has_axes_in_correct_order
str = @chart.to_xml_string
cat_axis_position = str.index(@chart.axes[:cat_axis].id.to_s)
val_axis_position = str.index(@chart.axes[:val_axis].id.to_s)
+
assert(cat_axis_position < val_axis_position, "cat_axis must occur earlier than val_axis in the XML")
end
@@ -72,6 +74,7 @@ class TestBarChart < Test::Unit::TestCase
gap_width_value = rand(0..500)
@chart.gap_width = gap_width_value
doc = Nokogiri::XML(@chart.to_xml_string)
+
assert_equal(doc.xpath("//c:barChart/c:gapWidth").first.attribute('val').value, gap_width_value.to_s)
end
@@ -79,6 +82,7 @@ class TestBarChart < Test::Unit::TestCase
overlap_value = rand(-100..100)
@chart.overlap = overlap_value
doc = Nokogiri::XML(@chart.to_xml_string)
+
assert_equal(doc.xpath("//c:barChart/c:overlap").first.attribute('val').value, overlap_value.to_s)
end
end
diff --git a/test/drawing/tc_bar_series.rb b/test/drawing/tc_bar_series.rb
index a1f98f64..0be791ee 100644
--- a/test/drawing/tc_bar_series.rb
+++ b/test/drawing/tc_bar_series.rb
@@ -16,30 +16,30 @@ class TestBarSeries < Test::Unit::TestCase
end
def test_initialize
- assert_equal(@series.title.text, "bob", "series title has been applied")
+ assert_equal("bob", @series.title.text, "series title has been applied")
assert_equal(@series.data.class, Axlsx::NumDataSource, "data option applied")
- assert_equal(@series.shape, :cone, "series shape has been applied")
- assert_equal(@series.series_color, '5A5A5A', 'series color has been applied')
+ assert_equal(:cone, @series.shape, "series shape has been applied")
+ assert_equal('5A5A5A', @series.series_color, 'series color has been applied')
assert(@series.data.is_a?(Axlsx::NumDataSource))
assert(@series.labels.is_a?(Axlsx::AxDataSource))
end
def test_colors
- assert_equal(@series.colors.size, 3)
+ assert_equal(3, @series.colors.size)
end
def test_shape
assert_raise(ArgumentError, "require valid shape") { @series.shape = :teardropt }
assert_nothing_raised("allow valid shape") { @series.shape = :box }
- assert(@series.shape == :box)
+ assert_equal(:box, @series.shape)
end
def test_to_xml_string
doc = Nokogiri::XML(@chart.to_xml_string)
@series.colors.each_with_index do |_color, index|
- assert_equal(doc.xpath("//c:dPt/c:idx[@val='#{index}']").size, 1)
- assert_equal(doc.xpath("//c:dPt/c:spPr/a:solidFill/a:srgbClr[@val='#{@series.colors[index]}']").size, 1)
+ assert_equal(1, doc.xpath("//c:dPt/c:idx[@val='#{index}']").size)
+ assert_equal(1, doc.xpath("//c:dPt/c:spPr/a:solidFill/a:srgbClr[@val='#{@series.colors[index]}']").size)
end
- assert_equal(doc.xpath('//c:spPr[not(ancestor::c:dPt)]/a:solidFill/a:srgbClr').first.get_attribute('val'), '5A5A5A', 'series color has been applied')
+ assert_equal('5A5A5A', doc.xpath('//c:spPr[not(ancestor::c:dPt)]/a:solidFill/a:srgbClr').first.get_attribute('val'), 'series color has been applied')
end
end
diff --git a/test/drawing/tc_bubble_chart.rb b/test/drawing/tc_bubble_chart.rb
index eb07afee..a0e27b1e 100644
--- a/test/drawing/tc_bubble_chart.rb
+++ b/test/drawing/tc_bubble_chart.rb
@@ -37,6 +37,7 @@ class TestBubbleChart < Test::Unit::TestCase
errors.push error
puts error.message
end
- assert(errors.empty?, "error free validation")
+
+ assert_empty(errors, "error free validation")
end
end
diff --git a/test/drawing/tc_bubble_series.rb b/test/drawing/tc_bubble_series.rb
index af051d11..d7edbdad 100644
--- a/test/drawing/tc_bubble_series.rb
+++ b/test/drawing/tc_bubble_series.rb
@@ -9,11 +9,12 @@ class TestBubbleSeries < Test::Unit::TestCase
end
def test_initialize
- assert_equal(@series.title.text, "GDP", "series title has been applied")
+ assert_equal("GDP", @series.title.text, "series title has been applied")
end
def test_to_xml_string
doc = Nokogiri::XML(@chart.to_xml_string)
- assert_equal(doc.xpath("//a:srgbClr[@val='#{@series.color}']").size, 2)
+
+ assert_equal(2, doc.xpath("//a:srgbClr[@val='#{@series.color}']").size)
end
end
diff --git a/test/drawing/tc_cat_axis.rb b/test/drawing/tc_cat_axis.rb
index 2cb029cc..c7eaaedc 100644
--- a/test/drawing/tc_cat_axis.rb
+++ b/test/drawing/tc_cat_axis.rb
@@ -8,9 +8,9 @@ class TestCatAxis < Test::Unit::TestCase
def teardown; end
def test_initialization
- assert_equal(@axis.auto, 1, "axis auto default incorrect")
- assert_equal(@axis.lbl_algn, :ctr, "label align default incorrect")
- assert_equal(@axis.lbl_offset, "100", "label offset default incorrect")
+ assert_equal(1, @axis.auto, "axis auto default incorrect")
+ assert_equal(:ctr, @axis.lbl_algn, "label align default incorrect")
+ assert_equal("100", @axis.lbl_offset, "label offset default incorrect")
end
def test_auto
diff --git a/test/drawing/tc_chart.rb b/test/drawing/tc_chart.rb
index c39bdc11..8bbc89c4 100644
--- a/test/drawing/tc_chart.rb
+++ b/test/drawing/tc_chart.rb
@@ -14,25 +14,28 @@ class TestChart < Test::Unit::TestCase
def test_initialization
assert_equal(@p.workbook.charts.last, @chart, "the chart is in the workbook")
- assert_equal(@chart.title.text, "fishery", "the title option has been applied")
+ assert_equal("fishery", @chart.title.text, "the title option has been applied")
assert((@chart.series.is_a?(Axlsx::SimpleTypedList) && @chart.series.empty?), "The series is initialized and empty")
end
def test_title
@chart.title.text = 'wowzer'
- assert_equal(@chart.title.text, "wowzer", "the title text via a string")
- assert_equal(@chart.title.cell, nil, "the title cell is nil as we set the title with text.")
+
+ assert_equal("wowzer", @chart.title.text, "the title text via a string")
+ assert_nil(@chart.title.cell, "the title cell is nil as we set the title with text.")
@chart.title = @row.cells.first
- assert_equal(@chart.title.text, "one", "the title text was set via cell reference")
+
+ assert_equal("one", @chart.title.text, "the title text was set via cell reference")
assert_equal(@chart.title.cell, @row.cells.first)
@chart.title = ""
- assert(@chart.title.empty?)
+
+ assert_empty(@chart.title)
end
def test_style
assert_raise(ArgumentError) { @chart.style = 49 }
assert_nothing_raised { @chart.style = 2 }
- assert_equal(@chart.style, 2)
+ assert_equal(2, @chart.style)
end
def test_to_from_marker_access
@@ -43,20 +46,20 @@ class TestChart < Test::Unit::TestCase
def test_bg_color
assert_raise(ArgumentError) { @chart.bg_color = 2 }
assert_nothing_raised { @chart.bg_color = "FFFFFF" }
- assert_equal(@chart.bg_color, "FFFFFF")
+ assert_equal("FFFFFF", @chart.bg_color)
end
def test_title_size
assert_raise(ArgumentError) { @chart.title_size = 2 }
assert_nothing_raised { @chart.title_size = "100" }
- assert_equal(@chart.title.text_size, "100")
+ assert_equal("100", @chart.title.text_size)
end
def test_vary_colors
- assert_equal(true, @chart.vary_colors)
+ assert(@chart.vary_colors)
assert_raise(ArgumentError) { @chart.vary_colors = 7 }
assert_nothing_raised { @chart.vary_colors = false }
- assert_equal(false, @chart.vary_colors)
+ refute(@chart.vary_colors)
end
def test_display_blanks_as
@@ -69,47 +72,56 @@ class TestChart < Test::Unit::TestCase
def test_start_at
@chart.start_at 15, 25
- assert_equal(@chart.graphic_frame.anchor.from.col, 15)
- assert_equal(@chart.graphic_frame.anchor.from.row, 25)
+
+ assert_equal(15, @chart.graphic_frame.anchor.from.col)
+ assert_equal(25, @chart.graphic_frame.anchor.from.row)
@chart.start_at @row.cells.first
- assert_equal(@chart.graphic_frame.anchor.from.col, 0)
- assert_equal(@chart.graphic_frame.anchor.from.row, 0)
+
+ assert_equal(0, @chart.graphic_frame.anchor.from.col)
+ assert_equal(0, @chart.graphic_frame.anchor.from.row)
@chart.start_at [5, 6]
- assert_equal(@chart.graphic_frame.anchor.from.col, 5)
- assert_equal(@chart.graphic_frame.anchor.from.row, 6)
+
+ assert_equal(5, @chart.graphic_frame.anchor.from.col)
+ assert_equal(6, @chart.graphic_frame.anchor.from.row)
end
def test_end_at
@chart.end_at 25, 90
- assert_equal(@chart.graphic_frame.anchor.to.col, 25)
- assert_equal(@chart.graphic_frame.anchor.to.row, 90)
+
+ assert_equal(25, @chart.graphic_frame.anchor.to.col)
+ assert_equal(90, @chart.graphic_frame.anchor.to.row)
@chart.end_at @row.cells.last
- assert_equal(@chart.graphic_frame.anchor.to.col, 2)
- assert_equal(@chart.graphic_frame.anchor.to.row, 0)
+
+ assert_equal(2, @chart.graphic_frame.anchor.to.col)
+ assert_equal(0, @chart.graphic_frame.anchor.to.row)
@chart.end_at [10, 11]
- assert_equal(@chart.graphic_frame.anchor.to.col, 10)
- assert_equal(@chart.graphic_frame.anchor.to.row, 11)
+
+ assert_equal(10, @chart.graphic_frame.anchor.to.col)
+ assert_equal(11, @chart.graphic_frame.anchor.to.row)
end
def test_add_series
s = @chart.add_series :data => [0, 1, 2, 3], :labels => ["one", 1, "anything"], :title => "bob"
+
assert_equal(@chart.series.last, s, "series has been added to chart series collection")
- assert_equal(s.title.text, "bob", "series title has been applied")
+ assert_equal("bob", s.title.text, "series title has been applied")
end
def test_pn
- assert_equal(@chart.pn, "charts/chart1.xml")
+ assert_equal("charts/chart1.xml", @chart.pn)
end
def test_d_lbls
- assert_equal(nil, Axlsx.instance_values_for(@chart)[:d_lbls])
+ assert_nil(Axlsx.instance_values_for(@chart)[:d_lbls])
@chart.d_lbls.d_lbl_pos = :t
+
assert(@chart.d_lbls.is_a?(Axlsx::DLbls), 'DLbls instantiated on access')
end
def test_plot_visible_only
assert(@chart.plot_visible_only, "default should be true")
@chart.plot_visible_only = false
+
assert_false(@chart.plot_visible_only)
assert_raise(ArgumentError) { @chart.plot_visible_only = "" }
end
@@ -117,6 +129,7 @@ class TestChart < Test::Unit::TestCase
def test_rounded_corners
assert(@chart.rounded_corners, "default should be true")
@chart.rounded_corners = false
+
assert_false(@chart.rounded_corners)
assert_raise(ArgumentError) { @chart.rounded_corners = "" }
end
@@ -125,34 +138,40 @@ class TestChart < Test::Unit::TestCase
schema = Nokogiri::XML::Schema(File.open(Axlsx::DRAWING_XSD))
doc = Nokogiri::XML(@chart.to_xml_string)
errors = schema.validate(doc).map { |error| puts error.message; error }
- assert(errors.empty?, "error free validation")
+
+ assert_empty(errors, "error free validation")
end
def test_to_xml_string_for_display_blanks_as
@chart.display_blanks_as = :span
doc = Nokogiri::XML(@chart.to_xml_string)
+
assert_equal("span", doc.xpath("//c:dispBlanksAs").attr("val").value, "did not use the display_blanks_as configuration")
end
def test_to_xml_string_for_title
@chart.title = "foobar"
doc = Nokogiri::XML(@chart.to_xml_string)
+
assert_equal("foobar", doc.xpath("//c:title//c:tx//a:t").text)
@chart.title = ""
doc = Nokogiri::XML(@chart.to_xml_string)
+
assert_equal(0, doc.xpath("//c:title").size)
end
def test_to_xml_string_for_plot_visible_only
assert_equal("true", Nokogiri::XML(@chart.to_xml_string).xpath("//c:plotVisOnly").attr("val").value)
@chart.plot_visible_only = false
+
assert_equal("false", Nokogiri::XML(@chart.to_xml_string).xpath("//c:plotVisOnly").attr("val").value)
end
def test_to_xml_string_for_rounded_corners
assert_equal("true", Nokogiri::XML(@chart.to_xml_string).xpath("//c:roundedCorners").attr("val").value)
@chart.rounded_corners = false
+
assert_equal("false", Nokogiri::XML(@chart.to_xml_string).xpath("//c:roundedCorners").attr("val").value)
end
end
diff --git a/test/drawing/tc_d_lbls.rb b/test/drawing/tc_d_lbls.rb
index 7f4f77e5..97011f6d 100644
--- a/test/drawing/tc_d_lbls.rb
+++ b/test/drawing/tc_d_lbls.rb
@@ -15,7 +15,7 @@ class TestDLbls < Test::Unit::TestCase
def test_initialization
assert_equal(:bestFit, @d_lbls.d_lbl_pos)
@boolean_attributes.each do |attr|
- assert_equal(false, @d_lbls.send(attr))
+ refute(@d_lbls.send(attr))
end
end
@@ -25,7 +25,7 @@ class TestDLbls < Test::Unit::TestCase
d_lbls = Axlsx::DLbls.new(Axlsx::Pie3DChart, options_hash.merge({ :d_lbl_pos => :t }))
@boolean_attributes.each do |attr|
- assert_equal(true, d_lbls.send(attr), "boolean attributes set by options")
+ assert(d_lbls.send(attr), "boolean attributes set by options")
end
assert_equal(:t, d_lbls.d_lbl_pos, "d_lbl_pos set by options")
end
@@ -49,6 +49,7 @@ class TestDLbls < Test::Unit::TestCase
@d_lbls.to_xml_string(str)
str << '</c:chartSpace>'
doc = Nokogiri::XML(str)
+
Axlsx.instance_values_for(@d_lbls).each do |name, value|
assert(doc.xpath("//c:#{Axlsx::camel(name, false)}[@val='#{value}']"), "#{name} is properly serialized")
end
diff --git a/test/drawing/tc_data_source.rb b/test/drawing/tc_data_source.rb
index b635d56e..70d52d11 100644
--- a/test/drawing/tc_data_source.rb
+++ b/test/drawing/tc_data_source.rb
@@ -16,6 +16,7 @@ class TestNumDataSource < Test::Unit::TestCase
str << '<c:chartSpace xmlns:c="' << Axlsx::XML_NS_C << '">'
str << @data_source.to_xml_string
doc = Nokogiri::XML(str)
- assert_equal(doc.xpath("//c:val").size, 1)
+
+ assert_equal(1, doc.xpath("//c:val").size)
end
end
diff --git a/test/drawing/tc_drawing.rb b/test/drawing/tc_drawing.rb
index 282a03da..a0cf9f98 100644
--- a/test/drawing/tc_drawing.rb
+++ b/test/drawing/tc_drawing.rb
@@ -7,23 +7,26 @@ class TestDrawing < Test::Unit::TestCase
end
def test_initialization
- assert(@ws.workbook.drawings.empty?)
+ assert_empty(@ws.workbook.drawings)
end
def test_add_chart
chart = @ws.add_chart(Axlsx::Pie3DChart, :title => "bob", :start_at => [0, 0], :end_at => [1, 1])
+
assert(chart.is_a?(Axlsx::Pie3DChart), "must create a chart")
assert_equal(@ws.workbook.charts.last, chart, "must be added to workbook charts collection")
assert_equal(@ws.drawing.anchors.last.object.chart, chart, "an anchor has been created and holds a reference to this chart")
anchor = @ws.drawing.anchors.last
- assert_equal([anchor.from.row, anchor.from.col], [0, 0], "options for start at are applied")
- assert_equal([anchor.to.row, anchor.to.col], [1, 1], "options for start at are applied")
- assert_equal(chart.title.text, "bob", "option for title is applied")
+
+ assert_equal([0, 0], [anchor.from.row, anchor.from.col], "options for start at are applied")
+ assert_equal([1, 1], [anchor.to.row, anchor.to.col], "options for start at are applied")
+ assert_equal("bob", chart.title.text, "option for title is applied")
end
def test_add_image
src = File.dirname(__FILE__) + "/../fixtures/image1.jpeg"
image = @ws.add_image(:image_src => src, :start_at => [0, 0], :width => 600, :height => 400)
+
assert(@ws.drawing.anchors.last.is_a?(Axlsx::OneCellAnchor))
assert(image.is_a?(Axlsx::Pic))
assert_equal(600, image.width)
@@ -33,37 +36,45 @@ class TestDrawing < Test::Unit::TestCase
def test_add_two_cell_anchor_image
src = File.dirname(__FILE__) + "/../fixtures/image1.jpeg"
image = @ws.add_image(:image_src => src, :start_at => [0, 0], :end_at => [15, 0])
+
assert(@ws.drawing.anchors.last.is_a?(Axlsx::TwoCellAnchor))
assert(image.is_a?(Axlsx::Pic))
end
def test_charts
chart = @ws.add_chart(Axlsx::Pie3DChart, :title => "bob", :start_at => [0, 0], :end_at => [1, 1])
+
assert_equal(@ws.drawing.charts.last, chart, "add chart is returned")
chart = @ws.add_chart(Axlsx::Pie3DChart, :title => "nancy", :start_at => [1, 5], :end_at => [5, 10])
+
assert_equal(@ws.drawing.charts.last, chart, "add chart is returned")
end
def test_pn
@ws.add_chart(Axlsx::Pie3DChart)
- assert_equal(@ws.drawing.pn, "drawings/drawing1.xml")
+
+ assert_equal("drawings/drawing1.xml", @ws.drawing.pn)
end
def test_rels_pn
@ws.add_chart(Axlsx::Pie3DChart)
- assert_equal(@ws.drawing.rels_pn, "drawings/_rels/drawing1.xml.rels")
+
+ assert_equal("drawings/_rels/drawing1.xml.rels", @ws.drawing.rels_pn)
end
def test_index
@ws.add_chart(Axlsx::Pie3DChart)
+
assert_equal(@ws.drawing.index, @ws.workbook.drawings.index(@ws.drawing))
end
def test_relationships
@ws.add_chart(Axlsx::Pie3DChart, :title => "bob", :start_at => [0, 0], :end_at => [1, 1])
- assert_equal(@ws.drawing.relationships.size, 1, "adding a chart adds a relationship")
+
+ assert_equal(1, @ws.drawing.relationships.size, "adding a chart adds a relationship")
@ws.add_chart(Axlsx::Pie3DChart, :title => "nancy", :start_at => [1, 5], :end_at => [5, 10])
- assert_equal(@ws.drawing.relationships.size, 2, "adding a chart adds a relationship")
+
+ assert_equal(2, @ws.drawing.relationships.size, "adding a chart adds a relationship")
end
def test_to_xml
@@ -75,6 +86,7 @@ class TestDrawing < Test::Unit::TestCase
errors.push error
puts error.message
end
- assert(errors.empty?, "error free validation")
+
+ assert_empty(errors, "error free validation")
end
end
diff --git a/test/drawing/tc_graphic_frame.rb b/test/drawing/tc_graphic_frame.rb
index c57c4d96..30479f0f 100644
--- a/test/drawing/tc_graphic_frame.rb
+++ b/test/drawing/tc_graphic_frame.rb
@@ -21,6 +21,7 @@ class TestGraphicFrame < Test::Unit::TestCase
def test_to_xml_has_correct_rId
doc = Nokogiri::XML(@frame.to_xml_string)
+
assert_equal @frame.rId, doc.xpath("//c:chart", doc.collect_namespaces).first["r:id"]
end
end
diff --git a/test/drawing/tc_hyperlink.rb b/test/drawing/tc_hyperlink.rb
index dd27d084..8ae5d01e 100644
--- a/test/drawing/tc_hyperlink.rb
+++ b/test/drawing/tc_hyperlink.rb
@@ -13,49 +13,50 @@ class TestHyperlink < Test::Unit::TestCase
def test_href
assert_nothing_raised { @hyperlink.href = "http://axlsx.blogspot.com" }
- assert_equal(@hyperlink.href, "http://axlsx.blogspot.com")
+ assert_equal("http://axlsx.blogspot.com", @hyperlink.href)
end
def test_tgtFrame
assert_nothing_raised { @hyperlink.tgtFrame = "http://axlsx.blogspot.com" }
- assert_equal(@hyperlink.tgtFrame, "http://axlsx.blogspot.com")
+ assert_equal("http://axlsx.blogspot.com", @hyperlink.tgtFrame)
end
def test_tooltip
assert_nothing_raised { @hyperlink.tooltip = "http://axlsx.blogspot.com" }
- assert_equal(@hyperlink.tooltip, "http://axlsx.blogspot.com")
+ assert_equal("http://axlsx.blogspot.com", @hyperlink.tooltip)
end
def test_invalidUrl
assert_nothing_raised { @hyperlink.invalidUrl = "http://axlsx.blogspot.com" }
- assert_equal(@hyperlink.invalidUrl, "http://axlsx.blogspot.com")
+ assert_equal("http://axlsx.blogspot.com", @hyperlink.invalidUrl)
end
def test_action
assert_nothing_raised { @hyperlink.action = "flee" }
- assert_equal(@hyperlink.action, "flee")
+ assert_equal("flee", @hyperlink.action)
end
def test_endSnd
assert_nothing_raised { @hyperlink.endSnd = "true" }
assert_raise(ArgumentError) { @hyperlink.endSnd = "bob" }
- assert_equal(@hyperlink.endSnd, "true")
+ assert_equal("true", @hyperlink.endSnd)
end
def test_highlightClick
assert_nothing_raised { @hyperlink.highlightClick = false }
assert_raise(ArgumentError) { @hyperlink.highlightClick = "bob" }
- assert_equal(@hyperlink.highlightClick, false)
+ refute(@hyperlink.highlightClick)
end
def test_history
assert_nothing_raised { @hyperlink.history = false }
assert_raise(ArgumentError) { @hyperlink.history = "bob" }
- assert_equal(@hyperlink.history, false)
+ refute(@hyperlink.history)
end
def test_to_xml_string
doc = Nokogiri::XML(@p.workbook.worksheets.first.drawing.to_xml_string)
+
assert(doc.xpath("//a:hlinkClick"))
end
end
diff --git a/test/drawing/tc_line_3d_chart.rb b/test/drawing/tc_line_3d_chart.rb
index 64603b11..f50f52cb 100644
--- a/test/drawing/tc_line_3d_chart.rb
+++ b/test/drawing/tc_line_3d_chart.rb
@@ -11,7 +11,7 @@ class TestLine3DChart < Test::Unit::TestCase
def teardown; end
def test_initialization
- assert_equal(@chart.grouping, :standard, "grouping defualt incorrect")
+ assert_equal(:standard, @chart.grouping, "grouping defualt incorrect")
assert_equal(@chart.series_type, Axlsx::LineSeries, "series type incorrect")
assert(@chart.catAxis.is_a?(Axlsx::CatAxis), "category axis not created")
assert(@chart.valAxis.is_a?(Axlsx::ValAxis), "value access not created")
@@ -21,13 +21,13 @@ class TestLine3DChart < Test::Unit::TestCase
def test_grouping
assert_raise(ArgumentError, "require valid grouping") { @chart.grouping = :inverted }
assert_nothing_raised("allow valid grouping") { @chart.grouping = :stacked }
- assert(@chart.grouping == :stacked)
+ assert_equal(:stacked, @chart.grouping)
end
def test_gapDepth
assert_raise(ArgumentError, "require valid gapDepth") { @chart.gapDepth = 200 }
assert_nothing_raised("allow valid gapDepth") { @chart.gapDepth = "200%" }
- assert(@chart.gapDepth == "200%")
+ assert_equal("200%", @chart.gapDepth)
end
def test_to_xml
@@ -38,6 +38,7 @@ class TestLine3DChart < Test::Unit::TestCase
errors.push error
puts error.message
end
- assert(errors.empty?, "error free validation")
+
+ assert_empty(errors, "error free validation")
end
end
diff --git a/test/drawing/tc_line_chart.rb b/test/drawing/tc_line_chart.rb
index 4a96af44..fe159bbb 100644
--- a/test/drawing/tc_line_chart.rb
+++ b/test/drawing/tc_line_chart.rb
@@ -11,7 +11,7 @@ class TestLineChart < Test::Unit::TestCase
def teardown; end
def test_initialization
- assert_equal(@chart.grouping, :standard, "grouping defualt incorrect")
+ assert_equal(:standard, @chart.grouping, "grouping defualt incorrect")
assert_equal(@chart.series_type, Axlsx::LineSeries, "series type incorrect")
assert(@chart.cat_axis.is_a?(Axlsx::CatAxis), "category axis not created")
assert(@chart.val_axis.is_a?(Axlsx::ValAxis), "value access not created")
@@ -20,7 +20,7 @@ class TestLineChart < Test::Unit::TestCase
def test_grouping
assert_raise(ArgumentError, "require valid grouping") { @chart.grouping = :inverted }
assert_nothing_raised("allow valid grouping") { @chart.grouping = :stacked }
- assert(@chart.grouping == :stacked)
+ assert_equal(:stacked, @chart.grouping)
end
def test_to_xml
@@ -31,6 +31,7 @@ class TestLineChart < Test::Unit::TestCase
errors.push error
puts error.message
end
- assert(errors.empty?, "error free validation")
+
+ assert_empty(errors, "error free validation")
end
end
diff --git a/test/drawing/tc_line_series.rb b/test/drawing/tc_line_series.rb
index 80643c4e..b125337e 100644
--- a/test/drawing/tc_line_series.rb
+++ b/test/drawing/tc_line_series.rb
@@ -16,42 +16,48 @@ class TestLineSeries < Test::Unit::TestCase
end
def test_initialize
- assert_equal(@series.title.text, "bob", "series title has been applied")
+ assert_equal("bob", @series.title.text, "series title has been applied")
assert_equal(@series.labels.class, Axlsx::AxDataSource)
assert_equal(@series.data.class, Axlsx::NumDataSource)
end
def test_show_marker
- assert_equal(true, @series.show_marker)
+ assert(@series.show_marker)
@series.show_marker = false
- assert_equal(false, @series.show_marker)
+
+ refute(@series.show_marker)
end
def test_smooth
- assert_equal(true, @series.smooth)
+ assert(@series.smooth)
@series.smooth = false
- assert_equal(false, @series.smooth)
+
+ refute(@series.smooth)
end
def test_marker_symbol
assert_equal(:default, @series.marker_symbol)
@series.marker_symbol = :circle
+
assert_equal(:circle, @series.marker_symbol)
end
def test_to_xml_string
doc = Nokogiri::XML(wrap_with_namespaces(@series))
+
assert(doc.xpath("//srgbClr[@val='#{@series.color}']"))
- assert_equal(xpath_with_namespaces(doc, "//c:marker").size, 0)
+ assert_equal(0, xpath_with_namespaces(doc, "//c:marker").size)
assert(doc.xpath("//smooth"))
@series.marker_symbol = :diamond
doc = Nokogiri::XML(wrap_with_namespaces(@series))
- assert_equal(xpath_with_namespaces(doc, "//c:marker/c:symbol[@val='diamond']").size, 1)
+
+ assert_equal(1, xpath_with_namespaces(doc, "//c:marker/c:symbol[@val='diamond']").size)
@series.show_marker = false
doc = Nokogiri::XML(wrap_with_namespaces(@series))
- assert_equal(xpath_with_namespaces(doc, "//c:marker/c:symbol[@val='none']").size, 1)
+
+ assert_equal(1, xpath_with_namespaces(doc, "//c:marker/c:symbol[@val='none']").size)
end
def wrap_with_namespaces(series)
diff --git a/test/drawing/tc_marker.rb b/test/drawing/tc_marker.rb
index bc801965..7a052a9f 100644
--- a/test/drawing/tc_marker.rb
+++ b/test/drawing/tc_marker.rb
@@ -8,10 +8,10 @@ class TestMarker < Test::Unit::TestCase
def teardown; end
def test_initialization
- assert(@marker.col == 0)
- assert(@marker.colOff == 0)
- assert(@marker.row == 0)
- assert(@marker.rowOff == 0)
+ assert_equal(0, @marker.col)
+ assert_equal(0, @marker.colOff)
+ assert_equal(0, @marker.row)
+ assert_equal(0, @marker.rowOff)
end
def test_col
@@ -36,7 +36,8 @@ class TestMarker < Test::Unit::TestCase
def test_coord
@marker.coord 5, 10
- assert_equal(@marker.col, 5)
- assert_equal(@marker.row, 10)
+
+ assert_equal(5, @marker.col)
+ assert_equal(10, @marker.row)
end
end
diff --git a/test/drawing/tc_num_data.rb b/test/drawing/tc_num_data.rb
index 10e35785..772bbcfc 100644
--- a/test/drawing/tc_num_data.rb
+++ b/test/drawing/tc_num_data.rb
@@ -6,7 +6,7 @@ class TestNumData < Test::Unit::TestCase
end
def test_initialize
- assert_equal(@num_data.format_code, "General")
+ assert_equal("General", @num_data.format_code)
end
def test_formula_based_cell; end
@@ -21,7 +21,8 @@ class TestNumData < Test::Unit::TestCase
str << '<c:chartSpace xmlns:c="' << Axlsx::XML_NS_C << '">'
str << @num_data.to_xml_string
doc = Nokogiri::XML(str)
- assert_equal(doc.xpath("//c:numLit/c:ptCount[@val=3]").size, 1)
- assert_equal(doc.xpath("//c:numLit/c:pt/c:v[text()='1']").size, 1)
+
+ assert_equal(1, doc.xpath("//c:numLit/c:ptCount[@val=3]").size)
+ assert_equal(1, doc.xpath("//c:numLit/c:pt/c:v[text()='1']").size)
end
end
diff --git a/test/drawing/tc_num_val.rb b/test/drawing/tc_num_val.rb
index 2123ea92..a6bbf71a 100644
--- a/test/drawing/tc_num_val.rb
+++ b/test/drawing/tc_num_val.rb
@@ -6,8 +6,8 @@ class TestNumVal < Test::Unit::TestCase
end
def test_initialize
- assert_equal(@num_val.format_code, "General")
- assert_equal(@num_val.v, "1")
+ assert_equal("General", @num_val.format_code)
+ assert_equal("1", @num_val.v)
end
def test_format_code
@@ -21,6 +21,6 @@ class TestNumVal < Test::Unit::TestCase
str << @num_val.to_xml_string(0)
doc = Nokogiri::XML(str)
# lets see if this works?
- assert_equal(doc.xpath("//c:pt/c:v[text()='1']").size, 1)
+ assert_equal(1, doc.xpath("//c:pt/c:v[text()='1']").size)
end
end
diff --git a/test/drawing/tc_one_cell_anchor.rb b/test/drawing/tc_one_cell_anchor.rb
index e0f9da43..25704a83 100644
--- a/test/drawing/tc_one_cell_anchor.rb
+++ b/test/drawing/tc_one_cell_anchor.rb
@@ -12,10 +12,10 @@ class TestOneCellAnchor < Test::Unit::TestCase
def teardown; end
def test_initialization
- assert(@anchor.from.col == 0)
- assert(@anchor.from.row == 0)
- assert(@anchor.width == 0)
- assert(@anchor.height == 0)
+ assert_equal(0, @anchor.from.col)
+ assert_equal(0, @anchor.from.row)
+ assert_equal(0, @anchor.width)
+ assert_equal(0, @anchor.height)
end
def test_from
@@ -33,7 +33,7 @@ class TestOneCellAnchor < Test::Unit::TestCase
def test_width
assert_raise(ArgumentError) { @anchor.width = "a" }
assert_nothing_raised { @anchor.width = 600 }
- assert_equal(@anchor.width, 600)
+ assert_equal(600, @anchor.width)
end
def test_height
@@ -44,6 +44,7 @@ class TestOneCellAnchor < Test::Unit::TestCase
def test_ext
ext = @anchor.send(:ext)
+
assert_equal(ext[:cx], (@anchor.width * 914400 / 96))
assert_equal(ext[:cy], (@anchor.height * 914400 / 96))
end
diff --git a/test/drawing/tc_pic.rb b/test/drawing/tc_pic.rb
index 21d3f931..6fb54822 100644
--- a/test/drawing/tc_pic.rb
+++ b/test/drawing/tc_pic.rb
@@ -19,15 +19,15 @@ class TestPic < Test::Unit::TestCase
def test_initialization
assert_equal(@p.workbook.images.first, @image)
- assert_equal(@image.file_name, 'image1.jpeg')
+ assert_equal('image1.jpeg', @image.file_name)
assert_equal(@image.image_src, @test_img)
end
def test_remote_img_initialization
assert_equal(@p.workbook.images[1], @image_remote)
- assert_equal(@image_remote.file_name, nil)
+ assert_nil(@image_remote.file_name)
assert_equal(@image_remote.image_src, @test_img_remote_png)
- assert_equal(@image_remote.remote?, true)
+ assert_predicate(@image_remote, :remote?)
end
def test_anchor_swapping
@@ -35,6 +35,7 @@ class TestPic < Test::Unit::TestCase
assert(@image.anchor.is_a?(Axlsx::OneCellAnchor))
start_at = @image.anchor.from
@image.end_at 10, 5
+
assert(@image.anchor.is_a?(Axlsx::TwoCellAnchor))
assert_equal(start_at.col, @image.anchor.from.col)
assert_equal(start_at.row, @image.anchor.from.row)
@@ -43,6 +44,7 @@ class TestPic < Test::Unit::TestCase
# swap from two cell to one cell when width or height are specified
@image.width = 200
+
assert(@image.anchor.is_a?(Axlsx::OneCellAnchor))
assert_equal(start_at.col, @image.anchor.from.col)
assert_equal(start_at.row, @image.anchor.from.row)
@@ -50,28 +52,29 @@ class TestPic < Test::Unit::TestCase
end
def test_hyperlink
- assert_equal(@image.hyperlink.href, "https://github.com/randym")
+ assert_equal("https://github.com/randym", @image.hyperlink.href)
@image.hyperlink = "http://axlsx.blogspot.com"
- assert_equal(@image.hyperlink.href, "http://axlsx.blogspot.com")
+
+ assert_equal("http://axlsx.blogspot.com", @image.hyperlink.href)
end
def test_name
assert_raise(ArgumentError) { @image.name = 49 }
assert_nothing_raised { @image.name = "unknown" }
- assert_equal(@image.name, "unknown")
+ assert_equal("unknown", @image.name)
end
def test_start_at
assert_raise(ArgumentError) { @image.start_at "a", 1 }
assert_nothing_raised { @image.start_at 6, 7 }
- assert_equal(@image.anchor.from.col, 6)
- assert_equal(@image.anchor.from.row, 7)
+ assert_equal(6, @image.anchor.from.col)
+ assert_equal(7, @image.anchor.from.row)
end
def test_width
assert_raise(ArgumentError) { @image.width = "a" }
assert_nothing_raised { @image.width = 600 }
- assert_equal(@image.width, 600)
+ assert_equal(600, @image.width)
end
def test_height
@@ -99,7 +102,7 @@ class TestPic < Test::Unit::TestCase
def test_descr
assert_raise(ArgumentError) { @image.descr = 49 }
assert_nothing_raised { @image.descr = "test" }
- assert_equal(@image.descr, "test")
+ assert_equal("test", @image.descr)
end
def test_to_xml
@@ -110,12 +113,14 @@ class TestPic < Test::Unit::TestCase
errors.push error
puts error.message
end
- assert(errors.empty?, "error free validation")
+
+ assert_empty(errors, "error free validation")
end
def test_to_xml_has_correct_r_id
r_id = @image.anchor.drawing.relationships.for(@image).Id
doc = Nokogiri::XML(@image.anchor.drawing.to_xml_string)
+
assert_equal r_id, doc.xpath("//a:blip").first["r:embed"]
end
end
diff --git a/test/drawing/tc_picture_locking.rb b/test/drawing/tc_picture_locking.rb
index 2543b1ca..4febc858 100644
--- a/test/drawing/tc_picture_locking.rb
+++ b/test/drawing/tc_picture_locking.rb
@@ -8,61 +8,61 @@ class TestPictureLocking < Test::Unit::TestCase
def teardown; end
def test_initialiation
- assert_equal(Axlsx.instance_values_for(@item).size, 1)
- assert_equal(@item.noChangeAspect, true)
+ assert_equal(1, Axlsx.instance_values_for(@item).size)
+ assert(@item.noChangeAspect)
end
def test_noGrp
assert_raise(ArgumentError) { @item.noGrp = -1 }
assert_nothing_raised { @item.noGrp = false }
- assert_equal(@item.noGrp, false)
+ refute(@item.noGrp)
end
def test_noRot
assert_raise(ArgumentError) { @item.noRot = -1 }
assert_nothing_raised { @item.noRot = false }
- assert_equal(@item.noRot, false)
+ refute(@item.noRot)
end
def test_noChangeAspect
assert_raise(ArgumentError) { @item.noChangeAspect = -1 }
assert_nothing_raised { @item.noChangeAspect = false }
- assert_equal(@item.noChangeAspect, false)
+ refute(@item.noChangeAspect)
end
def test_noMove
assert_raise(ArgumentError) { @item.noMove = -1 }
assert_nothing_raised { @item.noMove = false }
- assert_equal(@item.noMove, false)
+ refute(@item.noMove)
end
def test_noResize
assert_raise(ArgumentError) { @item.noResize = -1 }
assert_nothing_raised { @item.noResize = false }
- assert_equal(@item.noResize, false)
+ refute(@item.noResize)
end
def test_noEditPoints
assert_raise(ArgumentError) { @item.noEditPoints = -1 }
assert_nothing_raised { @item.noEditPoints = false }
- assert_equal(@item.noEditPoints, false)
+ refute(@item.noEditPoints)
end
def test_noAdjustHandles
assert_raise(ArgumentError) { @item.noAdjustHandles = -1 }
assert_nothing_raised { @item.noAdjustHandles = false }
- assert_equal(@item.noAdjustHandles, false)
+ refute(@item.noAdjustHandles)
end
def test_noChangeArrowheads
assert_raise(ArgumentError) { @item.noChangeArrowheads = -1 }
assert_nothing_raised { @item.noChangeArrowheads = false }
- assert_equal(@item.noChangeArrowheads, false)
+ refute(@item.noChangeArrowheads)
end
def test_noChangeShapeType
assert_raise(ArgumentError) { @item.noChangeShapeType = -1 }
assert_nothing_raised { @item.noChangeShapeType = false }
- assert_equal(@item.noChangeShapeType, false)
+ refute(@item.noChangeShapeType)
end
end
diff --git a/test/drawing/tc_pie_3D_chart.rb b/test/drawing/tc_pie_3D_chart.rb
index 9692ccc4..94438e16 100644
--- a/test/drawing/tc_pie_3D_chart.rb
+++ b/test/drawing/tc_pie_3D_chart.rb
@@ -11,8 +11,8 @@ class TestPie3DChart < Test::Unit::TestCase
def teardown; end
def test_initialization
- assert_equal(@chart.view_3D.rot_x, 30, "view 3d default rot_x incorrect")
- assert_equal(@chart.view_3D.perspective, 30, "view_3d default perspective incorrect")
+ assert_equal(30, @chart.view_3D.rot_x, "view 3d default rot_x incorrect")
+ assert_equal(30, @chart.view_3D.perspective, "view_3d default perspective incorrect")
assert_equal(@chart.series_type, Axlsx::PieSeries, "series type incorrect")
end
@@ -20,6 +20,7 @@ class TestPie3DChart < Test::Unit::TestCase
schema = Nokogiri::XML::Schema(File.open(Axlsx::DRAWING_XSD))
doc = Nokogiri::XML(@chart.to_xml_string)
errors = schema.validate(doc).map { |error| puts error.message; error }
- assert(errors.empty?, "error free validation")
+
+ assert_empty(errors, "error free validation")
end
end
diff --git a/test/drawing/tc_pie_series.rb b/test/drawing/tc_pie_series.rb
index 2c897fd2..0a7961eb 100644
--- a/test/drawing/tc_pie_series.rb
+++ b/test/drawing/tc_pie_series.rb
@@ -9,22 +9,23 @@ class TestPieSeries < Test::Unit::TestCase
end
def test_initialize
- assert_equal(@series.title.text, "bob", "series title has been applied")
+ assert_equal("bob", @series.title.text, "series title has been applied")
assert_equal(@series.labels.class, Axlsx::AxDataSource)
assert_equal(@series.data.class, Axlsx::NumDataSource)
- assert_equal(@series.explosion, nil, "series shape has been applied")
+ assert_nil(@series.explosion, "series shape has been applied")
end
def test_explosion
assert_raise(ArgumentError, "require valid explosion") { @series.explosion = :lots }
assert_nothing_raised("allow valid explosion") { @series.explosion = 20 }
- assert(@series.explosion == 20)
+ assert_equal(20, @series.explosion)
# issue 58 - explosion caused to_xml_string to fail - now tested
assert_nothing_raised("allow to_xml_string") { @series.to_xml_string }
end
def test_to_xml_string
doc = Nokogiri::XML(@series.to_xml_string)
+
assert(doc.xpath("//srgbClr[@val='#{@series.colors[0]}']"))
end
# TODO: test unique serialization parts
diff --git a/test/drawing/tc_scaling.rb b/test/drawing/tc_scaling.rb
index 1cd1538b..f369161c 100644
--- a/test/drawing/tc_scaling.rb
+++ b/test/drawing/tc_scaling.rb
@@ -8,7 +8,7 @@ class TestScaling < Test::Unit::TestCase
def teardown; end
def test_initialization
- assert(@scaling.orientation == :minMax)
+ assert_equal(:minMax, @scaling.orientation)
end
def test_logBase
diff --git a/test/drawing/tc_scatter_chart.rb b/test/drawing/tc_scatter_chart.rb
index 42d4a773..6e174567 100644
--- a/test/drawing/tc_scatter_chart.rb
+++ b/test/drawing/tc_scatter_chart.rb
@@ -23,12 +23,13 @@ class TestScatterChart < Test::Unit::TestCase
def test_scatter_style
@chart.scatterStyle = :marker
- assert(@chart.scatterStyle == :marker)
+
+ assert_equal(:marker, @chart.scatterStyle)
assert_raise(ArgumentError) { @chart.scatterStyle = :buckshot }
end
def test_initialization
- assert_equal(@chart.scatterStyle, :lineMarker, "scatterStyle defualt incorrect")
+ assert_equal(:lineMarker, @chart.scatterStyle, "scatterStyle defualt incorrect")
assert_equal(@chart.series_type, Axlsx::ScatterSeries, "series type incorrect")
assert(@chart.xValAxis.is_a?(Axlsx::ValAxis), "independant value axis not created")
assert(@chart.yValAxis.is_a?(Axlsx::ValAxis), "dependant value axis not created")
@@ -42,6 +43,7 @@ class TestScatterChart < Test::Unit::TestCase
errors.push error
puts error.message
end
- assert(errors.empty?, "error free validation")
+
+ assert_empty(errors, "error free validation")
end
end
diff --git a/test/drawing/tc_scatter_series.rb b/test/drawing/tc_scatter_series.rb
index 5ca126a2..ba04c980 100644
--- a/test/drawing/tc_scatter_series.rb
+++ b/test/drawing/tc_scatter_series.rb
@@ -9,64 +9,73 @@ class TestScatterSeries < Test::Unit::TestCase
end
def test_initialize
- assert_equal(@series.title.text, "exponents", "series title has been applied")
+ assert_equal("exponents", @series.title.text, "series title has been applied")
end
def test_smoothed_chart_default_smoothing
@chart = @ws.add_chart Axlsx::ScatterChart, :title => "Smooth Chart", :scatter_style => :smoothMarker
@series = @chart.add_series :xData => [1, 2, 4], :yData => [1, 3, 9], :title => "smoothed exponents"
+
assert(@series.smooth, "series is smooth by default on smooth charts")
end
def test_unsmoothed_chart_default_smoothing
@chart = @ws.add_chart Axlsx::ScatterChart, :title => "Unsmooth Chart", :scatter_style => :line
@series = @chart.add_series :xData => [1, 2, 4], :yData => [1, 3, 9], :title => "unsmoothed exponents"
- assert([email protected], "series is not smooth by default on non-smooth charts")
+
+ refute(@series.smooth, "series is not smooth by default on non-smooth charts")
end
def test_explicit_smoothing
@chart = @ws.add_chart Axlsx::ScatterChart, :title => "Unsmooth Chart, Smooth Series", :scatter_style => :line
@series = @chart.add_series :xData => [1, 2, 4], :yData => [1, 3, 9], :title => "smoothed exponents", :smooth => true
+
assert(@series.smooth, "series is smooth when overriding chart default")
end
def test_explicit_unsmoothing
@chart = @ws.add_chart Axlsx::ScatterChart, :title => "Smooth Chart, Unsmooth Series", :scatter_style => :smoothMarker
@series = @chart.add_series :xData => [1, 2, 4], :yData => [1, 3, 9], :title => "unsmoothed exponents", :smooth => false
- assert([email protected], "series is not smooth when overriding chart default")
+
+ refute(@series.smooth, "series is not smooth when overriding chart default")
end
def test_ln_width
@chart = @ws.add_chart Axlsx::ScatterChart, :title => "ln width", :scatter_style => :line
@series = @chart.add_series :xData => [1, 2, 4], :yData => [1, 3, 9], :title => "ln_width"
@series.ln_width = 12700
- assert_equal(@series.ln_width, 12700, 'line width assigment is allowed')
+
+ assert_equal(12700, @series.ln_width, 'line width assigment is allowed')
end
def test_to_xml_string
@chart.scatter_style = :line
@series.ln_width = 12700
doc = Nokogiri::XML(@chart.to_xml_string)
+
assert_equal(12700, @series.ln_width)
- assert_equal(doc.xpath("//a:srgbClr[@val='#{@series.color}']").size, 4)
- assert_equal(doc.xpath("//a:ln[@w='#{@series.ln_width}']").length, 1)
+ assert_equal(4, doc.xpath("//a:srgbClr[@val='#{@series.color}']").size)
+ assert_equal(1, doc.xpath("//a:ln[@w='#{@series.ln_width}']").length)
end
def test_false_show_marker
@chart = @ws.add_chart Axlsx::ScatterChart, :title => 'Smooth Chart', :scatter_style => :smoothMarker
@series = @chart.add_series :xData => [1, 2, 4], :yData => [1, 3, 9]
+
assert(@series.show_marker, 'markers are enabled for marker-related styles')
end
def test_true_show_marker
@chart = @ws.add_chart Axlsx::ScatterChart, :title => 'Line chart', :scatter_style => :line
@series = @chart.add_series :xData => [1, 2, 4], :yData => [1, 3, 9]
- assert([email protected]_marker, 'markers are disabled for markerless scatter styles')
+
+ refute(@series.show_marker, 'markers are disabled for markerless scatter styles')
end
def test_marker_symbol
@chart = @ws.add_chart Axlsx::ScatterChart, :title => 'Line chart', :scatter_style => :line
@series = @chart.add_series :xData => [1, 2, 4], :yData => [1, 3, 9], :marker_symbol => :diamond
- assert_equal(@series.marker_symbol, :diamond, 'series could have own custom marker symbol')
+
+ assert_equal(:diamond, @series.marker_symbol, 'series could have own custom marker symbol')
end
end
diff --git a/test/drawing/tc_ser_axis.rb b/test/drawing/tc_ser_axis.rb
index 80800fb5..de2f5db2 100644
--- a/test/drawing/tc_ser_axis.rb
+++ b/test/drawing/tc_ser_axis.rb
@@ -9,19 +9,20 @@ class TestSerAxis < Test::Unit::TestCase
def test_options
a = Axlsx::SerAxis.new(:tick_lbl_skip => 9, :tick_mark_skip => 7)
- assert_equal(a.tick_lbl_skip, 9)
- assert_equal(a.tick_mark_skip, 7)
+
+ assert_equal(9, a.tick_lbl_skip)
+ assert_equal(7, a.tick_mark_skip)
end
def test_tick_lbl_skip
assert_raise(ArgumentError, "requires valid tick_lbl_skip") { @axis.tick_lbl_skip = -1 }
assert_nothing_raised("accepts valid tick_lbl_skip") { @axis.tick_lbl_skip = 1 }
- assert_equal(@axis.tick_lbl_skip, 1)
+ assert_equal(1, @axis.tick_lbl_skip)
end
def test_tick_mark_skip
assert_raise(ArgumentError, "requires valid tick_mark_skip") { @axis.tick_mark_skip = :my_eyes }
assert_nothing_raised("accepts valid tick_mark_skip") { @axis.tick_mark_skip = 2 }
- assert_equal(@axis.tick_mark_skip, 2)
+ assert_equal(2, @axis.tick_mark_skip)
end
end
diff --git a/test/drawing/tc_series.rb b/test/drawing/tc_series.rb
index 80f4b7cb..8ffa5158 100644
--- a/test/drawing/tc_series.rb
+++ b/test/drawing/tc_series.rb
@@ -9,13 +9,14 @@ class TestSeries < Test::Unit::TestCase
end
def test_initialize
- assert_equal(@series.title.text, "bob", "series title has been applied")
+ assert_equal("bob", @series.title.text, "series title has been applied")
assert_equal(@series.order, @series.index, "order is index by default")
assert_equal(@series.index, @series.chart.series.index(@series), "index is applied")
end
def test_order
@series.order = 2
- assert_equal(@series.order, 2)
+
+ assert_equal(2, @series.order)
end
end
diff --git a/test/drawing/tc_series_title.rb b/test/drawing/tc_series_title.rb
index a304802b..260ad826 100644
--- a/test/drawing/tc_series_title.rb
+++ b/test/drawing/tc_series_title.rb
@@ -12,21 +12,23 @@ class TestSeriesTitle < Test::Unit::TestCase
def teardown; end
def test_initialization
- assert(@title.text == "")
- assert(@title.cell.nil?)
+ assert_equal("", @title.text)
+ assert_nil(@title.cell)
end
def test_text
assert_raise(ArgumentError, "text must be a string") { @title.text = 123 }
@title.cell = @row.cells.first
@title.text = "bob"
- assert(@title.cell.nil?, "setting title with text clears the cell")
+
+ assert_nil(@title.cell, "setting title with text clears the cell")
end
def test_cell
assert_raise(ArgumentError, "cell must be a Cell") { @title.cell = "123" }
@title.cell = @row.cells.first
- assert(@title.text == "one")
+
+ assert_equal("one", @title.text)
end
def test_to_xml_string_for_special_characters
@@ -36,7 +38,8 @@ class TestSeriesTitle < Test::Unit::TestCase
doc = Nokogiri::XML(@chart.to_xml_string)
errors = doc.errors
- assert(errors.empty?, "invalid xml: #{errors.map(&:to_s).join(', ')}")
+
+ assert_empty(errors, "invalid xml: #{errors.map(&:to_s).join(', ')}")
end
def test_to_xml_string_for_special_characters_in_cell
@@ -48,6 +51,7 @@ class TestSeriesTitle < Test::Unit::TestCase
doc = Nokogiri::XML(@chart.to_xml_string)
errors = doc.errors
- assert(errors.empty?, "invalid xml: #{errors.map(&:to_s).join(', ')}")
+
+ assert_empty(errors, "invalid xml: #{errors.map(&:to_s).join(', ')}")
end
end
diff --git a/test/drawing/tc_str_data.rb b/test/drawing/tc_str_data.rb
index f964a7b3..a2757d02 100644
--- a/test/drawing/tc_str_data.rb
+++ b/test/drawing/tc_str_data.rb
@@ -10,7 +10,8 @@ class TestStrData < Test::Unit::TestCase
str << '<c:chartSpace xmlns:c="' << Axlsx::XML_NS_C << '">'
str << @str_data.to_xml_string
doc = Nokogiri::XML(str)
- assert_equal(doc.xpath("//c:strLit/c:ptCount[@val=3]").size, 1)
- assert_equal(doc.xpath("//c:strLit/c:pt/c:v[text()='1']").size, 1)
+
+ assert_equal(1, doc.xpath("//c:strLit/c:ptCount[@val=3]").size)
+ assert_equal(1, doc.xpath("//c:strLit/c:pt/c:v[text()='1']").size)
end
end
diff --git a/test/drawing/tc_str_val.rb b/test/drawing/tc_str_val.rb
index 03b0b32a..e7b72197 100644
--- a/test/drawing/tc_str_val.rb
+++ b/test/drawing/tc_str_val.rb
@@ -7,7 +7,7 @@ class TestStrVal < Test::Unit::TestCase
end
def test_initialize
- assert_equal(@str_val.v, "1")
+ assert_equal("1", @str_val.v)
end
def test_to_xml_string
@@ -15,7 +15,8 @@ class TestStrVal < Test::Unit::TestCase
str << '<c:chartSpace xmlns:c="' << Axlsx::XML_NS_C << '">'
str << @str_val.to_xml_string(0)
doc = Nokogiri::XML(str)
- assert_equal(doc.xpath("//c:pt/c:v[text()='1']").size, 1)
+
+ assert_equal(1, doc.xpath("//c:pt/c:v[text()='1']").size)
end
def test_to_xml_string_special_characters
@@ -23,6 +24,7 @@ class TestStrVal < Test::Unit::TestCase
str << '<c:chartSpace xmlns:c="' << Axlsx::XML_NS_C << '">'
str << @str_val_with_special_characters.to_xml_string(0)
doc = Nokogiri::XML(str)
- assert_equal(doc.xpath("//c:pt/c:v[text()='a & b <c>']").size, 1)
+
+ assert_equal(1, doc.xpath("//c:pt/c:v[text()='a & b <c>']").size)
end
end
diff --git a/test/drawing/tc_title.rb b/test/drawing/tc_title.rb
index f26c307e..3a0609da 100644
--- a/test/drawing/tc_title.rb
+++ b/test/drawing/tc_title.rb
@@ -14,12 +14,13 @@ class TestTitle < Test::Unit::TestCase
def teardown; end
def test_initialization
- assert(@title.text == "")
- assert(@title.cell.nil?)
+ assert_equal("", @title.text)
+ assert_nil(@title.cell)
end
def test_initialize_title_size
title = Axlsx::Title.new 'bob', 90
+
assert_equal "90", title.text_size
end
@@ -27,18 +28,21 @@ class TestTitle < Test::Unit::TestCase
assert_raise(ArgumentError, "text must be a string") { @title.text = 123 }
@title.cell = @row.cells.first
@title.text = "bob"
- assert(@title.cell.nil?, "setting title with text clears the cell")
+
+ assert_nil(@title.cell, "setting title with text clears the cell")
end
def test_cell
assert_raise(ArgumentError, "cell must be a Cell") { @title.cell = "123" }
@title.cell = @row.cells.first
- assert(@title.text == "one")
+
+ assert_equal("one", @title.text)
end
def test_to_xml_string_text
@chart.title.text = 'foo'
doc = Nokogiri::XML(@chart.to_xml_string)
+
assert_equal(1, doc.xpath('//c:rich').size)
assert_equal(1, doc.xpath("//a:t[text()='foo']").size)
end
@@ -46,6 +50,7 @@ class TestTitle < Test::Unit::TestCase
def test_to_xml_string_cell
@chart.title.cell = @row.cells.first
doc = Nokogiri::XML(@chart.to_xml_string)
+
assert_equal("'Sheet1'!$A$1:$A$1", doc.xpath('//c:strRef/c:f').text)
assert_equal(1, doc.xpath('//c:strCache').size)
assert_equal('one', doc.xpath('//c:strCache/c:pt//c:v').text)
@@ -55,6 +60,7 @@ class TestTitle < Test::Unit::TestCase
@row.cells.first.value = ""
@chart.title.cell = @row.cells.first
doc = Nokogiri::XML(@chart.to_xml_string)
+
assert_equal("'Sheet1'!$A$1:$A$1", doc.xpath('//c:strRef/c:f').text)
assert_equal(1, doc.xpath('//c:strCache').size)
assert_equal('', doc.xpath('//c:strCache/c:pt//c:v').text)
@@ -64,7 +70,8 @@ class TestTitle < Test::Unit::TestCase
@chart.title.text = "&><'\""
doc = Nokogiri::XML(@chart.to_xml_string)
errors = doc.errors
- assert(errors.empty?, "invalid xml: #{errors.map(&:to_s).join(', ')}")
+
+ assert_empty(errors, "invalid xml: #{errors.map(&:to_s).join(', ')}")
end
def test_to_xml_string_for_special_characters_in_cell
@@ -74,6 +81,7 @@ class TestTitle < Test::Unit::TestCase
@chart.title.cell = cell
doc = Nokogiri::XML(@chart.to_xml_string)
errors = doc.errors
- assert(errors.empty?, "invalid xml: #{errors.map(&:to_s).join(', ')}")
+
+ assert_empty(errors, "invalid xml: #{errors.map(&:to_s).join(', ')}")
end
end
diff --git a/test/drawing/tc_two_cell_anchor.rb b/test/drawing/tc_two_cell_anchor.rb
index f2067c23..55cd9ca6 100644
--- a/test/drawing/tc_two_cell_anchor.rb
+++ b/test/drawing/tc_two_cell_anchor.rb
@@ -10,10 +10,10 @@ class TestTwoCellAnchor < Test::Unit::TestCase
end
def test_initialization
- assert(@anchor.from.col == 0)
- assert(@anchor.from.row == 0)
- assert(@anchor.to.col == 5)
- assert(@anchor.to.row == 10)
+ assert_equal(0, @anchor.from.col)
+ assert_equal(0, @anchor.from.row)
+ assert_equal(5, @anchor.to.col)
+ assert_equal(10, @anchor.to.row)
end
def test_index
@@ -26,9 +26,10 @@ class TestTwoCellAnchor < Test::Unit::TestCase
# this is actually raised in the graphic frame
assert_raise(ArgumentError, 'invalid Chart') { @ws.add_chart Axlsx::TwoCellAnchor }
a = @ws.add_chart Axlsx::Chart, :start_at => [15, 35], :end_at => [90, 45]
- assert_equal(a.graphic_frame.anchor.from.col, 15)
- assert_equal(a.graphic_frame.anchor.from.row, 35)
- assert_equal(a.graphic_frame.anchor.to.col, 90)
- assert_equal(a.graphic_frame.anchor.to.row, 45)
+
+ assert_equal(15, a.graphic_frame.anchor.from.col)
+ assert_equal(35, a.graphic_frame.anchor.from.row)
+ assert_equal(90, a.graphic_frame.anchor.to.col)
+ assert_equal(45, a.graphic_frame.anchor.to.row)
end
end
diff --git a/test/drawing/tc_val_axis.rb b/test/drawing/tc_val_axis.rb
index cc67f448..76574226 100644
--- a/test/drawing/tc_val_axis.rb
+++ b/test/drawing/tc_val_axis.rb
@@ -8,11 +8,12 @@ class TestValAxis < Test::Unit::TestCase
def teardown; end
def test_initialization
- assert_equal(@axis.cross_between, :between, "axis crossBetween default incorrect")
+ assert_equal(:between, @axis.cross_between, "axis crossBetween default incorrect")
end
def test_options
a = Axlsx::ValAxis.new(:cross_between => :midCat)
+
assert_equal(:midCat, a.cross_between)
end
diff --git a/test/drawing/tc_view_3D.rb b/test/drawing/tc_view_3D.rb
index 6d59c219..0b666014 100644
--- a/test/drawing/tc_view_3D.rb
+++ b/test/drawing/tc_view_3D.rb
@@ -9,12 +9,13 @@ class TestView3D < Test::Unit::TestCase
def test_options
v = Axlsx::View3D.new :rot_x => 10, :rot_y => 5, :h_percent => "30%", :depth_percent => "45%", :r_ang_ax => false, :perspective => 10
- assert_equal(v.rot_x, 10)
- assert_equal(v.rot_y, 5)
- assert_equal(v.h_percent, "30%")
- assert_equal(v.depth_percent, "45%")
- assert_equal(v.r_ang_ax, false)
- assert_equal(v.perspective, 10)
+
+ assert_equal(10, v.rot_x)
+ assert_equal(5, v.rot_y)
+ assert_equal("30%", v.h_percent)
+ assert_equal("45%", v.depth_percent)
+ refute(v.r_ang_ax)
+ assert_equal(10, v.perspective)
end
def test_rot_x
diff --git a/test/drawing/tc_vml_drawing.rb b/test/drawing/tc_vml_drawing.rb
index 1e2132af..3bfc613f 100644
--- a/test/drawing/tc_vml_drawing.rb
+++ b/test/drawing/tc_vml_drawing.rb
@@ -17,7 +17,8 @@ class TestVmlDrawing < Test::Unit::TestCase
def test_to_xml_string
str = @vml_drawing.to_xml_string
doc = Nokogiri::XML(str)
- assert_equal(doc.xpath("//v:shape").size, 2)
+
+ assert_equal(2, doc.xpath("//v:shape").size)
assert(doc.xpath("//o:idmap[@o:data='#{@ws.index + 1}']"))
end
end
diff --git a/test/drawing/tc_vml_shape.rb b/test/drawing/tc_vml_shape.rb
index f93ea48d..0f2fb3b5 100644
--- a/test/drawing/tc_vml_shape.rb
+++ b/test/drawing/tc_vml_shape.rb
@@ -16,91 +16,106 @@ class TestVmlShape < Test::Unit::TestCase
def test_row
shape = @comments.first.vml_shape
- assert_equal(shape.row, 0)
+
+ assert_equal(0, shape.row)
shape = @comments.last.vml_shape
- assert_equal(shape.row, 2)
+
+ assert_equal(2, shape.row)
end
def test_column
shape = @comments.first.vml_shape
- assert_equal(shape.column, 0)
+
+ assert_equal(0, shape.column)
shape = @comments.last.vml_shape
- assert_equal(shape.column, 2)
+
+ assert_equal(2, shape.column)
end
def test_left_column
shape = @comments.first.vml_shape
shape.left_column = 3
- assert(shape.left_column == 3)
+
+ assert_equal(3, shape.left_column)
assert_raise(ArgumentError) { shape.left_column = [] }
end
def test_left_offset
shape = @comments.first.vml_shape
shape.left_offset = 3
- assert(shape.left_offset == 3)
+
+ assert_equal(3, shape.left_offset)
assert_raise(ArgumentError) { shape.left_offset = [] }
end
def test_right_column
shape = @comments.first.vml_shape
shape.right_column = 3
- assert(shape.right_column == 3)
+
+ assert_equal(3, shape.right_column)
assert_raise(ArgumentError) { shape.right_column = [] }
end
def test_right_offset
shape = @comments.first.vml_shape
shape.right_offset = 3
- assert(shape.right_offset == 3)
+
+ assert_equal(3, shape.right_offset)
assert_raise(ArgumentError) { shape.right_offset = [] }
end
def test_top_offset
shape = @comments.first.vml_shape
shape.top_offset = 3
- assert(shape.top_offset == 3)
+
+ assert_equal(3, shape.top_offset)
assert_raise(ArgumentError) { shape.top_offset = [] }
end
def test_bottom_offset
shape = @comments.first.vml_shape
shape.bottom_offset = 3
- assert(shape.bottom_offset == 3)
+
+ assert_equal(3, shape.bottom_offset)
assert_raise(ArgumentError) { shape.bottom_offset = [] }
end
def test_bottom_row
shape = @comments.first.vml_shape
shape.bottom_row = 3
- assert(shape.bottom_row == 3)
+
+ assert_equal(3, shape.bottom_row)
assert_raise(ArgumentError) { shape.bottom_row = [] }
end
def test_top_row
shape = @comments.first.vml_shape
shape.top_row = 3
- assert(shape.top_row == 3)
+
+ assert_equal(3, shape.top_row)
assert_raise(ArgumentError) { shape.top_row = [] }
end
def test_visible
shape = @comments.first.vml_shape
shape.visible = false
- assert(shape.visible == false)
+
+ refute(shape.visible)
assert_raise(ArgumentError) { shape.visible = 'foo' }
end
def test_to_xml_string
str = @comments.vml_drawing.to_xml_string
doc = Nokogiri::XML(str)
- assert_equal(doc.xpath("//v:shape").size, 2)
+
+ assert_equal(2, doc.xpath("//v:shape").size)
assert_equal(1, doc.xpath("//x:Visible").size, 'ClientData/x:Visible element rendering')
@comments.each do |comment|
shape = comment.vml_shape
- assert(doc.xpath("//v:shape/x:ClientData/x:Row[text()='#{shape.row}']").size == 1)
- assert(doc.xpath("//v:shape/x:ClientData/x:Column[text()='#{shape.column}']").size == 1)
- assert(doc.xpath("//v:shape/x:ClientData/x:Anchor[text()='#{shape.left_column}, #{shape.left_offset}, #{shape.top_row}, #{shape.top_offset}, #{shape.right_column}, #{shape.right_offset}, #{shape.bottom_row}, #{shape.bottom_offset}']").size == 1)
+
+ assert_equal(1, doc.xpath("//v:shape/x:ClientData/x:Row[text()='#{shape.row}']").size)
+ assert_equal(1, doc.xpath("//v:shape/x:ClientData/x:Column[text()='#{shape.column}']").size)
+ assert_equal(1, doc.xpath("//v:shape/x:ClientData/x:Anchor[text()='#{shape.left_column}, #{shape.left_offset}, #{shape.top_row}, #{shape.top_offset}, #{shape.right_column}, #{shape.right_offset}, #{shape.bottom_row}, #{shape.bottom_offset}']").size)
end
end
end
diff --git a/test/rels/tc_relationship.rb b/test/rels/tc_relationship.rb
index 1a9df27a..71208ec7 100644
--- a/test/rels/tc_relationship.rb
+++ b/test/rels/tc_relationship.rb
@@ -4,12 +4,14 @@ class TestRelationships < Test::Unit::TestCase
def test_instances_with_different_attributes_have_unique_ids
rel_1 = Axlsx::Relationship.new(Object.new, Axlsx::WORKSHEET_R, 'target')
rel_2 = Axlsx::Relationship.new(Object.new, Axlsx::COMMENT_R, 'foobar')
+
assert_not_equal rel_1.Id, rel_2.Id
end
def test_instances_with_same_attributes_share_id
source_obj = Object.new
instance = Axlsx::Relationship.new(source_obj, Axlsx::WORKSHEET_R, 'target')
+
assert_equal instance.Id, Axlsx::Relationship.new(source_obj, Axlsx::WORKSHEET_R, 'target').Id
end
@@ -18,6 +20,7 @@ class TestRelationships < Test::Unit::TestCase
t1 = Thread.new { cache1 = Axlsx::Relationship.ids_cache }
t2 = Thread.new { cache2 = Axlsx::Relationship.ids_cache }
[t1, t2].each(&:join)
+
assert_not_same(cache1, cache2)
end
@@ -25,10 +28,12 @@ class TestRelationships < Test::Unit::TestCase
source_obj = Object.new
rel_1 = Axlsx::Relationship.new(source_obj, Axlsx::WORKSHEET_R, 'target')
rel_2 = Axlsx::Relationship.new(source_obj, Axlsx::WORKSHEET_R, '../target')
+
assert_equal rel_1.Id, rel_2.Id
rel_3 = Axlsx::Relationship.new(source_obj, Axlsx::HYPERLINK_R, 'target', :target_mode => :External)
rel_4 = Axlsx::Relationship.new(source_obj, Axlsx::HYPERLINK_R, '../target', :target_mode => :External)
+
assert_not_equal rel_3.Id, rel_4.Id
end
@@ -46,6 +51,7 @@ class TestRelationships < Test::Unit::TestCase
def test_ampersand_escaping_in_target
r = Axlsx::Relationship.new(nil, Axlsx::HYPERLINK_R, "http://example.com?foo=1&bar=2", :target_mod => :External)
doc = Nokogiri::XML(r.to_xml_string)
- assert_equal(doc.xpath("//Relationship[@Target='http://example.com?foo=1&bar=2']").size, 1)
+
+ assert_equal(1, doc.xpath("//Relationship[@Target='http://example.com?foo=1&bar=2']").size)
end
end
diff --git a/test/rels/tc_relationships.rb b/test/rels/tc_relationships.rb
index 35adbc9b..ba153ce7 100644
--- a/test/rels/tc_relationships.rb
+++ b/test/rels/tc_relationships.rb
@@ -9,6 +9,7 @@ class TestRelationships < Test::Unit::TestCase
rels = Axlsx::Relationships.new
rels << rel_1
rels << rel_2
+
assert_equal rel_1, rels.for(source_obj_1)
assert_equal rel_2, rels.for(source_obj_2)
end
@@ -31,6 +32,6 @@ class TestRelationships < Test::Unit::TestCase
errors << error
end
- assert(errors.empty?)
+ assert_empty(errors)
end
end
diff --git a/test/stylesheet/tc_border.rb b/test/stylesheet/tc_border.rb
index f7791d94..4060dbf5 100644
--- a/test/stylesheet/tc_border.rb
+++ b/test/stylesheet/tc_border.rb
@@ -8,28 +8,28 @@ class TestBorder < Test::Unit::TestCase
def teardown; end
def test_initialiation
- assert_equal(@b.diagonalUp, nil)
- assert_equal(@b.diagonalDown, nil)
- assert_equal(@b.outline, nil)
+ assert_nil(@b.diagonalUp)
+ assert_nil(@b.diagonalDown)
+ assert_nil(@b.outline)
assert(@b.prs.is_a?(Axlsx::SimpleTypedList))
end
def test_diagonalUp
assert_raise(ArgumentError) { @b.diagonalUp = :red }
assert_nothing_raised { @b.diagonalUp = true }
- assert_equal(@b.diagonalUp, true)
+ assert(@b.diagonalUp)
end
def test_diagonalDown
assert_raise(ArgumentError) { @b.diagonalDown = :red }
assert_nothing_raised { @b.diagonalDown = true }
- assert_equal(@b.diagonalDown, true)
+ assert(@b.diagonalDown)
end
def test_outline
assert_raise(ArgumentError) { @b.outline = :red }
assert_nothing_raised { @b.outline = true }
- assert_equal(@b.outline, true)
+ assert(@b.outline)
end
def test_prs
diff --git a/test/stylesheet/tc_border_pr.rb b/test/stylesheet/tc_border_pr.rb
index 652f4f6d..90f18586 100644
--- a/test/stylesheet/tc_border_pr.rb
+++ b/test/stylesheet/tc_border_pr.rb
@@ -8,9 +8,9 @@ class TestBorderPr < Test::Unit::TestCase
def teardown; end
def test_initialiation
- assert_equal(@bpr.color, nil)
- assert_equal(@bpr.style, nil)
- assert_equal(@bpr.name, nil)
+ assert_nil(@bpr.color)
+ assert_nil(@bpr.style)
+ assert_nil(@bpr.name)
end
def test_color
@@ -22,12 +22,12 @@ class TestBorderPr < Test::Unit::TestCase
def test_style
assert_raise(ArgumentError) { @bpr.style = :red }
assert_nothing_raised { @bpr.style = :thin }
- assert_equal(@bpr.style, :thin)
+ assert_equal(:thin, @bpr.style)
end
def test_name
assert_raise(ArgumentError) { @bpr.name = :red }
assert_nothing_raised { @bpr.name = :top }
- assert_equal(@bpr.name, :top)
+ assert_equal(:top, @bpr.name)
end
end
diff --git a/test/stylesheet/tc_cell_alignment.rb b/test/stylesheet/tc_cell_alignment.rb
index 0b514bf4..28e0d272 100644
--- a/test/stylesheet/tc_cell_alignment.rb
+++ b/test/stylesheet/tc_cell_alignment.rb
@@ -6,19 +6,20 @@ class TestCellAlignment < Test::Unit::TestCase
end
def test_initialiation
- assert_equal(@item.horizontal, nil)
- assert_equal(@item.vertical, nil)
- assert_equal(@item.textRotation, nil)
- assert_equal(@item.wrapText, nil)
- assert_equal(@item.indent, nil)
- assert_equal(@item.relativeIndent, nil)
- assert_equal(@item.justifyLastLine, nil)
- assert_equal(@item.shrinkToFit, nil)
- assert_equal(@item.readingOrder, nil)
+ assert_nil(@item.horizontal)
+ assert_nil(@item.vertical)
+ assert_nil(@item.textRotation)
+ assert_nil(@item.wrapText)
+ assert_nil(@item.indent)
+ assert_nil(@item.relativeIndent)
+ assert_nil(@item.justifyLastLine)
+ assert_nil(@item.shrinkToFit)
+ assert_nil(@item.readingOrder)
options = { :horizontal => :left, :vertical => :top, :textRotation => 3,
:wrapText => true, :indent => 2, :relativeIndent => 5,
:justifyLastLine => true, :shrinkToFit => true, :readingOrder => 2 }
ca = Axlsx::CellAlignment.new options
+
options.each do |key, value|
assert_equal(ca.send(key.to_sym), value)
end
@@ -27,54 +28,54 @@ class TestCellAlignment < Test::Unit::TestCase
def test_horizontal
assert_raise(ArgumentError) { @item.horizontal = :red }
assert_nothing_raised { @item.horizontal = :left }
- assert_equal(@item.horizontal, :left)
+ assert_equal(:left, @item.horizontal)
end
def test_vertical
assert_raise(ArgumentError) { @item.vertical = :red }
assert_nothing_raised { @item.vertical = :top }
- assert_equal(@item.vertical, :top)
+ assert_equal(:top, @item.vertical)
end
def test_textRotation
assert_raise(ArgumentError) { @item.textRotation = -1 }
assert_nothing_raised { @item.textRotation = 5 }
- assert_equal(@item.textRotation, 5)
+ assert_equal(5, @item.textRotation)
end
def test_wrapText
assert_raise(ArgumentError) { @item.wrapText = -1 }
assert_nothing_raised { @item.wrapText = false }
- assert_equal(@item.wrapText, false)
+ refute(@item.wrapText)
end
def test_indent
assert_raise(ArgumentError) { @item.indent = -1 }
assert_nothing_raised { @item.indent = 5 }
- assert_equal(@item.indent, 5)
+ assert_equal(5, @item.indent)
end
def test_relativeIndent
assert_raise(ArgumentError) { @item.relativeIndent = :symbol }
assert_nothing_raised { @item.relativeIndent = 5 }
- assert_equal(@item.relativeIndent, 5)
+ assert_equal(5, @item.relativeIndent)
end
def test_justifyLastLine
assert_raise(ArgumentError) { @item.justifyLastLine = -1 }
assert_nothing_raised { @item.justifyLastLine = true }
- assert_equal(@item.justifyLastLine, true)
+ assert(@item.justifyLastLine)
end
def test_shrinkToFit
assert_raise(ArgumentError) { @item.shrinkToFit = -1 }
assert_nothing_raised { @item.shrinkToFit = true }
- assert_equal(@item.shrinkToFit, true)
+ assert(@item.shrinkToFit)
end
def test_readingOrder
assert_raise(ArgumentError) { @item.readingOrder = -1 }
assert_nothing_raised { @item.readingOrder = 2 }
- assert_equal(@item.readingOrder, 2)
+ assert_equal(2, @item.readingOrder)
end
end
diff --git a/test/stylesheet/tc_cell_protection.rb b/test/stylesheet/tc_cell_protection.rb
index 253b6c82..631192de 100644
--- a/test/stylesheet/tc_cell_protection.rb
+++ b/test/stylesheet/tc_cell_protection.rb
@@ -8,19 +8,19 @@ class TestCellProtection < Test::Unit::TestCase
def teardown; end
def test_initialiation
- assert_equal(@item.hidden, nil)
- assert_equal(@item.locked, nil)
+ assert_nil(@item.hidden)
+ assert_nil(@item.locked)
end
def test_hidden
assert_raise(ArgumentError) { @item.hidden = -1 }
assert_nothing_raised { @item.hidden = false }
- assert_equal(@item.hidden, false)
+ refute(@item.hidden)
end
def test_locked
assert_raise(ArgumentError) { @item.locked = -1 }
assert_nothing_raised { @item.locked = false }
- assert_equal(@item.locked, false)
+ refute(@item.locked)
end
end
diff --git a/test/stylesheet/tc_cell_style.rb b/test/stylesheet/tc_cell_style.rb
index 06f20af3..d62e68ed 100644
--- a/test/stylesheet/tc_cell_style.rb
+++ b/test/stylesheet/tc_cell_style.rb
@@ -8,47 +8,47 @@ class TestCellStyle < Test::Unit::TestCase
def teardown; end
def test_initialiation
- assert_equal(@item.name, nil)
- assert_equal(@item.xfId, nil)
- assert_equal(@item.builtinId, nil)
- assert_equal(@item.iLevel, nil)
- assert_equal(@item.hidden, nil)
- assert_equal(@item.customBuiltin, nil)
+ assert_nil(@item.name)
+ assert_nil(@item.xfId)
+ assert_nil(@item.builtinId)
+ assert_nil(@item.iLevel)
+ assert_nil(@item.hidden)
+ assert_nil(@item.customBuiltin)
end
def test_name
assert_raise(ArgumentError) { @item.name = -1 }
assert_nothing_raised { @item.name = "stylin" }
- assert_equal(@item.name, "stylin")
+ assert_equal("stylin", @item.name)
end
def test_xfId
assert_raise(ArgumentError) { @item.xfId = -1 }
assert_nothing_raised { @item.xfId = 5 }
- assert_equal(@item.xfId, 5)
+ assert_equal(5, @item.xfId)
end
def test_builtinId
assert_raise(ArgumentError) { @item.builtinId = -1 }
assert_nothing_raised { @item.builtinId = 5 }
- assert_equal(@item.builtinId, 5)
+ assert_equal(5, @item.builtinId)
end
def test_iLevel
assert_raise(ArgumentError) { @item.iLevel = -1 }
assert_nothing_raised { @item.iLevel = 5 }
- assert_equal(@item.iLevel, 5)
+ assert_equal(5, @item.iLevel)
end
def test_hidden
assert_raise(ArgumentError) { @item.hidden = -1 }
assert_nothing_raised { @item.hidden = true }
- assert_equal(@item.hidden, true)
+ assert(@item.hidden)
end
def test_customBuiltin
assert_raise(ArgumentError) { @item.customBuiltin = -1 }
assert_nothing_raised { @item.customBuiltin = true }
- assert_equal(@item.customBuiltin, true)
+ assert(@item.customBuiltin)
end
end
diff --git a/test/stylesheet/tc_color.rb b/test/stylesheet/tc_color.rb
index 46e94f88..336c093f 100644
--- a/test/stylesheet/tc_color.rb
+++ b/test/stylesheet/tc_color.rb
@@ -8,32 +8,33 @@ class TestColor < Test::Unit::TestCase
def teardown; end
def test_initialiation
- assert_equal(@item.auto, nil)
- assert_equal(@item.rgb, "FF000000")
- assert_equal(@item.tint, nil)
+ assert_nil(@item.auto)
+ assert_equal("FF000000", @item.rgb)
+ assert_nil(@item.tint)
end
def test_auto
assert_raise(ArgumentError) { @item.auto = -1 }
assert_nothing_raised { @item.auto = true }
- assert_equal(@item.auto, true)
+ assert(@item.auto)
end
def test_rgb
assert_raise(ArgumentError) { @item.rgb = -1 }
assert_nothing_raised { @item.rgb = "FF00FF00" }
- assert_equal(@item.rgb, "FF00FF00")
+ assert_equal("FF00FF00", @item.rgb)
end
def test_rgb_writer_doesnt_mutate_its_argument
my_rgb = 'ff00ff00'
@item.rgb = my_rgb
+
assert_equal 'ff00ff00', my_rgb
end
def test_tint
assert_raise(ArgumentError) { @item.tint = -1 }
assert_nothing_raised { @item.tint = -1.0 }
- assert_equal(@item.tint, -1.0)
+ assert_in_delta(@item.tint, -1.0)
end
end
diff --git a/test/stylesheet/tc_dxf.rb b/test/stylesheet/tc_dxf.rb
index ecbd7112..bac649dd 100644
--- a/test/stylesheet/tc_dxf.rb
+++ b/test/stylesheet/tc_dxf.rb
@@ -9,12 +9,12 @@ class TestDxf < Test::Unit::TestCase
def teardown; end
def test_initialiation
- assert_equal(@item.alignment, nil)
- assert_equal(@item.protection, nil)
- assert_equal(@item.numFmt, nil)
- assert_equal(@item.font, nil)
- assert_equal(@item.fill, nil)
- assert_equal(@item.border, nil)
+ assert_nil(@item.alignment)
+ assert_nil(@item.protection)
+ assert_nil(@item.numFmt)
+ assert_nil(@item.font)
+ assert_nil(@item.fill)
+ assert_nil(@item.border)
end
def test_alignment
@@ -56,6 +56,7 @@ class TestDxf < Test::Unit::TestCase
def test_to_xml
@item.border = Axlsx::Border.new
doc = Nokogiri::XML.parse(@item.to_xml_string)
+
assert_equal(1, doc.xpath(".//dxf//border").size)
assert_equal(0, doc.xpath(".//dxf//font").size)
end
@@ -69,6 +70,7 @@ class TestDxf < Test::Unit::TestCase
@item.numFmt = Axlsx::NumFmt.new
doc = Nokogiri::XML.parse(@item.to_xml_string)
+
assert_equal(1, doc.xpath(".//dxf//fill//patternFill[@patternType='solid']//fgColor[@rgb='FF000000']").size)
assert_equal(1, doc.xpath(".//dxf//font").size)
assert_equal(1, doc.xpath(".//dxf//protection").size)
diff --git a/test/stylesheet/tc_font.rb b/test/stylesheet/tc_font.rb
index 601e7a65..3eaec01a 100644
--- a/test/stylesheet/tc_font.rb
+++ b/test/stylesheet/tc_font.rb
@@ -8,108 +8,109 @@ class TestFont < Test::Unit::TestCase
def teardown; end
def test_initialiation
- assert_equal(@item.name, nil)
- assert_equal(@item.charset, nil)
- assert_equal(@item.family, nil)
- assert_equal(@item.b, nil)
- assert_equal(@item.i, nil)
- assert_equal(@item.u, nil)
- assert_equal(@item.strike, nil)
- assert_equal(@item.outline, nil)
- assert_equal(@item.shadow, nil)
- assert_equal(@item.condense, nil)
- assert_equal(@item.extend, nil)
- assert_equal(@item.color, nil)
- assert_equal(@item.sz, nil)
+ assert_nil(@item.name)
+ assert_nil(@item.charset)
+ assert_nil(@item.family)
+ assert_nil(@item.b)
+ assert_nil(@item.i)
+ assert_nil(@item.u)
+ assert_nil(@item.strike)
+ assert_nil(@item.outline)
+ assert_nil(@item.shadow)
+ assert_nil(@item.condense)
+ assert_nil(@item.extend)
+ assert_nil(@item.color)
+ assert_nil(@item.sz)
end
# def name=(v) Axlsx::validate_string v; @name = v end
def test_name
assert_raise(ArgumentError) { @item.name = 7 }
assert_nothing_raised { @item.name = "bob" }
- assert_equal(@item.name, "bob")
+ assert_equal("bob", @item.name)
end
# def charset=(v) Axlsx::validate_unsigned_int v; @charset = v end
def test_charset
assert_raise(ArgumentError) { @item.charset = -7 }
assert_nothing_raised { @item.charset = 5 }
- assert_equal(@item.charset, 5)
+ assert_equal(5, @item.charset)
end
# def family=(v) Axlsx::validate_unsigned_int v; @family = v end
def test_family
assert_raise(ArgumentError) { @item.family = -7 }
assert_nothing_raised { @item.family = 5 }
- assert_equal(@item.family, 5)
+ assert_equal(5, @item.family)
end
# def b=(v) Axlsx::validate_boolean v; @b = v end
def test_b
assert_raise(ArgumentError) { @item.b = -7 }
assert_nothing_raised { @item.b = true }
- assert_equal(@item.b, true)
+ assert(@item.b)
end
# def i=(v) Axlsx::validate_boolean v; @i = v end
def test_i
assert_raise(ArgumentError) { @item.i = -7 }
assert_nothing_raised { @item.i = true }
- assert_equal(@item.i, true)
+ assert(@item.i)
end
# def u=(v) Axlsx::validate_cell_u v; @u = v end
def test_u
assert_raise(ArgumentError) { @item.u = -7 }
assert_nothing_raised { @item.u = :single }
- assert_equal(@item.u, :single)
+ assert_equal(:single, @item.u)
doc = Nokogiri::XML(@item.to_xml_string)
+
assert(doc.xpath('//u[@val="single"]'))
end
def test_u_backward_compatibility
# backward compatibility for true
assert_nothing_raised { @item.u = true }
- assert_equal(@item.u, :single)
+ assert_equal(:single, @item.u)
# backward compatibility for false
assert_nothing_raised { @item.u = false }
- assert_equal(@item.u, :none)
+ assert_equal(:none, @item.u)
end
# def strike=(v) Axlsx::validate_boolean v; @strike = v end
def test_strike
assert_raise(ArgumentError) { @item.strike = -7 }
assert_nothing_raised { @item.strike = true }
- assert_equal(@item.strike, true)
+ assert(@item.strike)
end
# def outline=(v) Axlsx::validate_boolean v; @outline = v end
def test_outline
assert_raise(ArgumentError) { @item.outline = -7 }
assert_nothing_raised { @item.outline = true }
- assert_equal(@item.outline, true)
+ assert(@item.outline)
end
# def shadow=(v) Axlsx::validate_boolean v; @shadow = v end
def test_shadow
assert_raise(ArgumentError) { @item.shadow = -7 }
assert_nothing_raised { @item.shadow = true }
- assert_equal(@item.shadow, true)
+ assert(@item.shadow)
end
# def condense=(v) Axlsx::validate_boolean v; @condense = v end
def test_condense
assert_raise(ArgumentError) { @item.condense = -7 }
assert_nothing_raised { @item.condense = true }
- assert_equal(@item.condense, true)
+ assert(@item.condense)
end
# def extend=(v) Axlsx::validate_boolean v; @extend = v end
def test_extend
assert_raise(ArgumentError) { @item.extend = -7 }
assert_nothing_raised { @item.extend = true }
- assert_equal(@item.extend, true)
+ assert(@item.extend)
end
# def color=(v) DataTypeValidator.validate "Font.color", Color, v; @color=v end
@@ -123,6 +124,6 @@ class TestFont < Test::Unit::TestCase
def test_sz
assert_raise(ArgumentError) { @item.sz = -7 }
assert_nothing_raised { @item.sz = 5 }
- assert_equal(@item.sz, 5)
+ assert_equal(5, @item.sz)
end
end
diff --git a/test/stylesheet/tc_gradient_fill.rb b/test/stylesheet/tc_gradient_fill.rb
index 3707cdad..7f0a4013 100644
--- a/test/stylesheet/tc_gradient_fill.rb
+++ b/test/stylesheet/tc_gradient_fill.rb
@@ -8,54 +8,55 @@ class TestGradientFill < Test::Unit::TestCase
def teardown; end
def test_initialiation
- assert_equal(@item.type, :linear)
- assert_equal(@item.degree, nil)
- assert_equal(@item.left, nil)
- assert_equal(@item.right, nil)
- assert_equal(@item.top, nil)
- assert_equal(@item.bottom, nil)
+ assert_equal(:linear, @item.type)
+ assert_nil(@item.degree)
+ assert_nil(@item.left)
+ assert_nil(@item.right)
+ assert_nil(@item.top)
+ assert_nil(@item.bottom)
assert(@item.stop.is_a?(Axlsx::SimpleTypedList))
end
def test_type
assert_raise(ArgumentError) { @item.type = 7 }
assert_nothing_raised { @item.type = :path }
- assert_equal(@item.type, :path)
+ assert_equal(:path, @item.type)
end
def test_degree
assert_raise(ArgumentError) { @item.degree = -7 }
assert_nothing_raised { @item.degree = 5.0 }
- assert_equal(@item.degree, 5.0)
+ assert_in_delta(@item.degree, 5.0)
end
def test_left
assert_raise(ArgumentError) { @item.left = -1.1 }
assert_nothing_raised { @item.left = 1.0 }
- assert_equal(@item.left, 1.0)
+ assert_in_delta(@item.left, 1.0)
end
def test_right
assert_raise(ArgumentError) { @item.right = -1.1 }
assert_nothing_raised { @item.right = 0.5 }
- assert_equal(@item.right, 0.5)
+ assert_in_delta(@item.right, 0.5)
end
def test_top
assert_raise(ArgumentError) { @item.top = -1.1 }
assert_nothing_raised { @item.top = 1.0 }
- assert_equal(@item.top, 1.0)
+ assert_in_delta(@item.top, 1.0)
end
def test_bottom
assert_raise(ArgumentError) { @item.bottom = -1.1 }
assert_nothing_raised { @item.bottom = 0.0 }
- assert_equal(@item.bottom, 0.0)
+ assert_in_delta(@item.bottom, 0.0)
end
def test_stop
@item.stop << Axlsx::GradientStop.new(Axlsx::Color.new(:rgb => "00000000"), 0.5)
- assert(@item.stop.size == 1)
+
+ assert_equal(1, @item.stop.size)
assert(@item.stop.last.is_a?(Axlsx::GradientStop))
end
@@ -64,6 +65,7 @@ class TestGradientFill < Test::Unit::TestCase
@item.stop << Axlsx::GradientStop.new(Axlsx::Color.new(:rgb => "FFFFFF"), 0.5)
@item.type = :path
doc = Nokogiri::XML(@item.to_xml_string)
+
assert(doc.xpath("//color[@rgb='FF000000']"))
end
end
diff --git a/test/stylesheet/tc_gradient_stop.rb b/test/stylesheet/tc_gradient_stop.rb
index a4cd4ef8..48b0d69d 100644
--- a/test/stylesheet/tc_gradient_stop.rb
+++ b/test/stylesheet/tc_gradient_stop.rb
@@ -8,20 +8,21 @@ class TestGradientStop < Test::Unit::TestCase
def teardown; end
def test_initialiation
- assert_equal(@item.color.rgb, "FFFF0000")
- assert_equal(@item.position, 1.0)
+ assert_equal("FFFF0000", @item.color.rgb)
+ assert_in_delta(@item.position, 1.0)
end
def test_position
assert_raise(ArgumentError) { @item.position = -1.1 }
assert_nothing_raised { @item.position = 0.0 }
- assert_equal(@item.position, 0.0)
+ assert_in_delta(@item.position, 0.0)
end
def test_color
assert_raise(ArgumentError) { @item.color = nil }
color = Axlsx::Color.new(:rgb => "FF0000FF")
@item.color = color
- assert_equal(@item.color.rgb, "FF0000FF")
+
+ assert_equal("FF0000FF", @item.color.rgb)
end
end
diff --git a/test/stylesheet/tc_num_fmt.rb b/test/stylesheet/tc_num_fmt.rb
index 63c818b0..f75db1d1 100644
--- a/test/stylesheet/tc_num_fmt.rb
+++ b/test/stylesheet/tc_num_fmt.rb
@@ -8,19 +8,19 @@ class TestNumFmt < Test::Unit::TestCase
def teardown; end
def test_initialiation
- assert_equal(@item.numFmtId, 0)
- assert_equal(@item.formatCode, "")
+ assert_equal(0, @item.numFmtId)
+ assert_equal("", @item.formatCode)
end
def test_numFmtId
assert_raise(ArgumentError) { @item.numFmtId = -1.1 }
assert_nothing_raised { @item.numFmtId = 2 }
- assert_equal(@item.numFmtId, 2)
+ assert_equal(2, @item.numFmtId)
end
def test_fomatCode
assert_raise(ArgumentError) { @item.formatCode = -1.1 }
assert_nothing_raised { @item.formatCode = "0" }
- assert_equal(@item.formatCode, "0")
+ assert_equal("0", @item.formatCode)
end
end
diff --git a/test/stylesheet/tc_pattern_fill.rb b/test/stylesheet/tc_pattern_fill.rb
index 228d7ca2..9e122d19 100644
--- a/test/stylesheet/tc_pattern_fill.rb
+++ b/test/stylesheet/tc_pattern_fill.rb
@@ -8,32 +8,33 @@ class TestPatternFill < Test::Unit::TestCase
def teardown; end
def test_initialiation
- assert_equal(@item.patternType, :none)
- assert_equal(@item.bgColor, nil)
- assert_equal(@item.fgColor, nil)
+ assert_equal(:none, @item.patternType)
+ assert_nil(@item.bgColor)
+ assert_nil(@item.fgColor)
end
def test_bgColor
assert_raise(ArgumentError) { @item.bgColor = -1.1 }
assert_nothing_raised { @item.bgColor = Axlsx::Color.new }
- assert_equal(@item.bgColor.rgb, "FF000000")
+ assert_equal("FF000000", @item.bgColor.rgb)
end
def test_fgColor
assert_raise(ArgumentError) { @item.fgColor = -1.1 }
assert_nothing_raised { @item.fgColor = Axlsx::Color.new }
- assert_equal(@item.fgColor.rgb, "FF000000")
+ assert_equal("FF000000", @item.fgColor.rgb)
end
def test_pattern_type
assert_raise(ArgumentError) { @item.patternType = -1.1 }
assert_nothing_raised { @item.patternType = :lightUp }
- assert_equal(@item.patternType, :lightUp)
+ assert_equal(:lightUp, @item.patternType)
end
def test_to_xml_string
@item = Axlsx::PatternFill.new :bgColor => Axlsx::Color.new(:rgb => "FF0000"), :fgColor => Axlsx::Color.new(:rgb => "00FF00")
doc = Nokogiri::XML(@item.to_xml_string)
+
assert(doc.xpath('//color[@rgb="FFFF0000"]'))
assert(doc.xpath('//color[@rgb="FF00FF00"]'))
end
diff --git a/test/stylesheet/tc_styles.rb b/test/stylesheet/tc_styles.rb
index d6e9115a..415bf968 100644
--- a/test/stylesheet/tc_styles.rb
+++ b/test/stylesheet/tc_styles.rb
@@ -15,16 +15,18 @@ class TestStyles < Test::Unit::TestCase
errors.push error
puts error.message
end
- assert(errors.empty?)
+
+ assert_empty(errors)
end
def test_add_style_border_hash
border_count = @styles.borders.size
@styles.add_style :border => { :style => :thin, :color => "FFFF0000" }
+
assert_equal(@styles.borders.size, border_count + 1)
- assert_equal(@styles.borders.last.prs.last.color.rgb, "FFFF0000")
+ assert_equal("FFFF0000", @styles.borders.last.prs.last.color.rgb)
assert_raise(ArgumentError) { @styles.add_style :border => { :color => "FFFF0000" } }
- assert_equal @styles.borders.last.prs.size, 4
+ assert_equal(4, @styles.borders.last.prs.size)
end
def test_add_style_border_array
@@ -46,34 +48,39 @@ class TestStyles < Test::Unit::TestCase
current_border = @styles.borders.last
borders_array.each do |b_opts|
- if b_opts[:edges]
- border_pr = current_border.prs.detect { |x| x.name == b_opts[:edges].first }
- assert_equal(border_pr.color.rgb, "FF#{b_opts[:color]}")
- end
+ next unless b_opts[:edges]
+
+ border_pr = current_border.prs.detect { |x| x.name == b_opts[:edges].first }
+
+ assert_equal(border_pr.color.rgb, "FF#{b_opts[:color]}")
end
end
def test_add_style_border_edges
@styles.add_style :border => { :style => :thin, :color => "0000FFFF", :edges => [:top, :bottom] }
parts = @styles.borders.last.prs
- parts.each { |pr| assert_equal(pr.color.rgb, "0000FFFF", "Style is applied to #{pr.name} properly") }
- assert((parts.map { |pr| pr.name.to_s }.sort && ['bottom', 'top']).size == 2, "specify two edges, and you get two border prs")
+
+ parts.each { |pr| assert_equal("0000FFFF", pr.color.rgb, "Style is applied to #{pr.name} properly") }
+ assert_equal(2, (parts.map { |pr| pr.name.to_s }.sort && ['bottom', 'top']).size, "specify two edges, and you get two border prs")
end
def test_do_not_alter_options_in_add_style
# This should test all options, but for now - just the bits that we know caused some pain
options = { :border => { :style => :thin, :color => "FF000000" } }
@styles.add_style options
- assert_equal options[:border][:style], :thin, 'thin style is stil in option'
- assert_equal options[:border][:color], "FF000000", 'color is stil in option'
+
+ assert_equal(:thin, options[:border][:style], 'thin style is stil in option')
+ assert_equal("FF000000", options[:border][:color], 'color is stil in option')
end
def test_parse_num_fmt
f_code = { :format_code => "YYYY/MM" }
num_fmt = { :num_fmt => 5 }
- assert_equal(@styles.parse_num_fmt_options, nil, 'noop if neither :format_code or :num_fmt exist')
+
+ assert_nil(@styles.parse_num_fmt_options, 'noop if neither :format_code or :num_fmt exist')
max = @styles.numFmts.map(&:numFmtId).max
@styles.parse_num_fmt_options(f_code)
+
assert_equal(@styles.numFmts.last.numFmtId, max + 1, "new numfmts gets next available id")
assert(@styles.parse_num_fmt_options(num_fmt).is_a?(Integer), "Should return the provided num_fmt if not dxf")
assert(@styles.parse_num_fmt_options(num_fmt.merge({ :type => :dxf })).is_a?(Axlsx::NumFmt), "Makes a new NumFmt if dxf")
@@ -88,9 +95,10 @@ class TestStyles < Test::Unit::TestCase
def test_parse_border_basic_options
b_opts = { :border => { :diagonalUp => 1, :edges => [:left, :right], :color => "FFDADADA", :style => :thick } }
b = @styles.parse_border_options b_opts
+
assert(b.is_a?(Integer))
assert_equal(@styles.parse_border_options(b_opts.merge({ :type => :dxf })).class, Axlsx::Border)
- assert(@styles.borders.last.diagonalUp == 1, "border options are passed in to the initializer")
+ assert_equal(1, @styles.borders.last.diagonalUp, "border options are passed in to the initializer")
end
def test_parse_border_options_edges
@@ -101,22 +109,23 @@ class TestStyles < Test::Unit::TestCase
right = b.prs.select { |bpr| bpr.name == :right }[0]
top = b.prs.select { |bpr| bpr.name == :top }[0]
bottom = b.prs.select { |bpr| bpr.name == :bottom }[0]
- assert_equal(top, nil, "unspecified top edge should not be created")
- assert_equal(bottom, nil, "unspecified bottom edge should not be created")
+
+ assert_nil(top, "unspecified top edge should not be created")
+ assert_nil(bottom, "unspecified bottom edge should not be created")
assert(left.is_a?(Axlsx::BorderPr), "specified left edge is set")
assert(right.is_a?(Axlsx::BorderPr), "specified right edge is set")
assert_equal(left.style, right.style, "edge parts have the same style")
- assert_equal(left.style, :thick, "the style is THICK")
+ assert_equal(:thick, left.style, "the style is THICK")
assert_equal(right.color.rgb, left.color.rgb, "edge parts are colors are the same")
- assert_equal(right.color.rgb, "FFDADADA", "edge color rgb is correct")
+ assert_equal("FFDADADA", right.color.rgb, "edge color rgb is correct")
end
def test_parse_border_options_noop
- assert_equal(@styles.parse_border_options({}), nil, "noop if the border key is not in options")
+ assert_nil(@styles.parse_border_options({}), "noop if the border key is not in options")
end
def test_parse_border_options_integer_xf
- assert_equal(@styles.parse_border_options(:border => 1), 1)
+ assert_equal(1, @styles.parse_border_options(:border => 1))
assert_raise(ArgumentError, "unknown border index") { @styles.parse_border_options(:border => 100) }
end
@@ -124,11 +133,12 @@ class TestStyles < Test::Unit::TestCase
b_opts = { :border => { :edges => [:left, :right], :color => "FFFFFFFF", :style => :thick } }
b = @styles.parse_border_options(b_opts)
b2 = @styles.parse_border_options(:border => b, :type => :dxf)
+
assert(b2.is_a?(Axlsx::Border), "Cloned existing border object")
end
def test_parse_alignment_options
- assert_equal(@styles.parse_alignment_options, nil, "noop if :alignment is not set")
+ assert_nil(@styles.parse_alignment_options, "noop if :alignment is not set")
assert(@styles.parse_alignment_options(:alignment => {}).is_a?(Axlsx::CellAlignment))
end
@@ -137,10 +147,12 @@ class TestStyles < Test::Unit::TestCase
@styles.add_style :b => 1, :sz => 99
created = @styles.fonts.last
original_attributes = Axlsx.instance_values_for(original)
+
assert_equal(1, created.b)
assert_equal(99, created.sz)
copied = original_attributes.reject { |key, _value| %w(b sz).include? key }
instance_vals = Axlsx.instance_values_for(created)
+
copied.each do |key, value|
assert_equal(instance_vals[key], value)
end
@@ -160,13 +172,15 @@ class TestStyles < Test::Unit::TestCase
:family => 1,
:font_name => "woot font"
}
- assert_equal(@styles.parse_font_options, nil, "noop if no font keys are set")
+
+ assert_nil(@styles.parse_font_options, "noop if no font keys are set")
assert(@styles.parse_font_options(:b => 1).is_a?(Integer), "return index of font if not :dxf type")
assert_equal(@styles.parse_font_options(:b => 1, :type => :dxf).class, Axlsx::Font, "return font object if :dxf type")
f = @styles.parse_font_options(options.merge(:type => :dxf))
color = options.delete(:fg_color)
options[:name] = options.delete(:font_name)
+
options.each do |key, value|
assert_equal(f.send(key), value, "assert that #{key} was parsed")
end
@@ -174,15 +188,16 @@ class TestStyles < Test::Unit::TestCase
end
def test_parse_fill_options
- assert_equal(@styles.parse_fill_options, nil, "noop if no fill keys are set")
+ assert_nil(@styles.parse_fill_options, "noop if no fill keys are set")
assert(@styles.parse_fill_options(:bg_color => "DE").is_a?(Integer), "return index of fill if not :dxf type")
assert_equal(@styles.parse_fill_options(:bg_color => "DE", :type => :dxf).class, Axlsx::Fill, "return fill object if :dxf type")
f = @styles.parse_fill_options(:bg_color => "DE", :type => :dxf)
- assert(f.fill_type.bgColor.rgb == "FFDEDEDE")
+
+ assert_equal("FFDEDEDE", f.fill_type.bgColor.rgb)
end
def test_parse_protection_options
- assert_equal(@styles.parse_protection_options, nil, "noop if no protection keys are set")
+ assert_nil(@styles.parse_protection_options, "noop if no protection keys are set")
assert_equal(@styles.parse_protection_options(:hidden => 1).class, Axlsx::CellProtection, "creates a new cell protection object")
end
@@ -192,39 +207,42 @@ class TestStyles < Test::Unit::TestCase
xf_count = @styles.cellXfs.size
@styles.add_style :bg_color => "FF000000", :fg_color => "FFFFFFFF", :sz => 13, :num_fmt => Axlsx::NUM_FMT_PERCENT, :alignment => { :horizontal => :left }, :border => Axlsx::STYLE_THIN_BORDER, :hidden => true, :locked => true
+
assert_equal(@styles.fills.size, fill_count + 1)
assert_equal(@styles.fonts.size, font_count + 1)
assert_equal(@styles.cellXfs.size, xf_count + 1)
xf = @styles.cellXfs.last
+
assert_equal(xf.fillId, (@styles.fills.size - 1), "points to the last created fill")
- assert_equal(@styles.fills.last.fill_type.fgColor.rgb, "FF000000", "fill created with color")
+ assert_equal("FF000000", @styles.fills.last.fill_type.fgColor.rgb, "fill created with color")
assert_equal(xf.fontId, (@styles.fonts.size - 1), "points to the last created font")
- assert_equal(@styles.fonts.last.sz, 13, "font sz applied")
- assert_equal(@styles.fonts.last.color.rgb, "FFFFFFFF", "font color applied")
+ assert_equal(13, @styles.fonts.last.sz, "font sz applied")
+ assert_equal("FFFFFFFF", @styles.fonts.last.color.rgb, "font color applied")
assert_equal(xf.borderId, Axlsx::STYLE_THIN_BORDER, "border id is set")
assert_equal(xf.numFmtId, Axlsx::NUM_FMT_PERCENT, "number format id is set")
assert(xf.alignment.is_a?(Axlsx::CellAlignment), "alignment was created")
- assert_equal(xf.alignment.horizontal, :left, "horizontal alignment applied")
- assert_equal(xf.protection.hidden, true, "hidden protection set")
- assert_equal(xf.protection.locked, true, "cell locking set")
+ assert_equal(:left, xf.alignment.horizontal, "horizontal alignment applied")
+ assert(xf.protection.hidden, "hidden protection set")
+ assert(xf.protection.locked, "cell locking set")
assert_raise(ArgumentError, "should reject invalid borderId") { @styles.add_style :border => 2 }
- assert_equal(xf.applyProtection, true, "protection applied")
- assert_equal(xf.applyBorder, true, "border applied")
- assert_equal(xf.applyNumberFormat, true, "number format applied")
- assert_equal(xf.applyAlignment, true, "alignment applied")
+ assert(xf.applyProtection, "protection applied")
+ assert(xf.applyBorder, "border applied")
+ assert(xf.applyNumberFormat, "number format applied")
+ assert(xf.applyAlignment, "alignment applied")
end
def test_basic_add_style_dxf
border_count = @styles.borders.size
@styles.add_style :border => { :style => :thin, :color => "FFFF0000" }, :type => :dxf
+
assert_equal(@styles.borders.size, border_count, "styles borders not affected")
- assert_equal(@styles.dxfs.last.border.prs.last.color.rgb, "FFFF0000")
+ assert_equal("FFFF0000", @styles.dxfs.last.border.prs.last.color.rgb)
assert_raise(ArgumentError) { @styles.add_style :border => { :color => "FFFF0000" }, :type => :dxf }
- assert_equal @styles.borders.last.prs.size, 4
+ assert_equal(4, @styles.borders.last.prs.size)
end
def test_add_style_dxf
@@ -233,30 +251,34 @@ class TestStyles < Test::Unit::TestCase
dxf_count = @styles.dxfs.size
style = @styles.add_style :bg_color => "FF000000", :fg_color => "FFFFFFFF", :sz => 13, :alignment => { :horizontal => :left }, :border => { :style => :thin, :color => "FFFF0000" }, :hidden => true, :locked => true, :type => :dxf
+
assert_equal(@styles.dxfs.size, dxf_count + 1)
assert_equal(0, style, "returns the zero-based dxfId")
dxf = @styles.dxfs.last
- assert_equal(@styles.dxfs.last.fill.fill_type.bgColor.rgb, "FF000000", "fill created with color")
+
+ assert_equal("FF000000", @styles.dxfs.last.fill.fill_type.bgColor.rgb, "fill created with color")
assert_equal(font_count, @styles.fonts.size, "font not created under styles")
assert_equal(fill_count, @styles.fills.size, "fill not created under styles")
assert(dxf.border.is_a?(Axlsx::Border), "border is set")
- assert_equal(nil, dxf.numFmt, "number format is not set")
+ assert_nil(dxf.numFmt, "number format is not set")
assert(dxf.alignment.is_a?(Axlsx::CellAlignment), "alignment was created")
- assert_equal(dxf.alignment.horizontal, :left, "horizontal alignment applied")
- assert_equal(dxf.protection.hidden, true, "hidden protection set")
- assert_equal(dxf.protection.locked, true, "cell locking set")
+ assert_equal(:left, dxf.alignment.horizontal, "horizontal alignment applied")
+ assert(dxf.protection.hidden, "hidden protection set")
+ assert(dxf.protection.locked, "cell locking set")
assert_raise(ArgumentError, "should reject invalid borderId") { @styles.add_style :border => 3 }
end
def test_multiple_dxf
# add a second style
style = @styles.add_style :bg_color => "00000000", :fg_color => "FFFFFFFF", :sz => 13, :alignment => { :horizontal => :left }, :border => { :style => :thin, :color => "FFFF0000" }, :hidden => true, :locked => true, :type => :dxf
+
assert_equal(0, style, "returns the first dxfId")
style = @styles.add_style :bg_color => "FF000000", :fg_color => "FFFFFFFF", :sz => 13, :alignment => { :horizontal => :left }, :border => { :style => :thin, :color => "FFFF0000" }, :hidden => true, :locked => true, :type => :dxf
+
assert_equal(1, style, "returns the second dxfId")
end
@@ -283,7 +305,8 @@ class TestStyles < Test::Unit::TestCase
errors.push error
puts error.message
end
- assert(errors.empty?)
+
+ assert_empty(errors)
end
def test_border_top_without_border_regression
@@ -302,6 +325,7 @@ class TestStyles < Test::Unit::TestCase
current_border = @styles.borders.last
border_pr = current_border.prs.detect { |x| x.name == edge }
+
assert_equal(border_pr.color.rgb, "FF#{b_opts[:color]}")
end
end
diff --git a/test/stylesheet/tc_table_style.rb b/test/stylesheet/tc_table_style.rb
index a003c37a..6c15ebae 100644
--- a/test/stylesheet/tc_table_style.rb
+++ b/test/stylesheet/tc_table_style.rb
@@ -8,35 +8,37 @@ class TestTableStyle < Test::Unit::TestCase
def teardown; end
def test_initialiation
- assert_equal(@item.name, "fisher")
- assert_equal(@item.pivot, nil)
- assert_equal(@item.table, nil)
+ assert_equal("fisher", @item.name)
+ assert_nil(@item.pivot)
+ assert_nil(@item.table)
ts = Axlsx::TableStyle.new 'price', :pivot => true, :table => true
- assert_equal(ts.name, 'price')
- assert_equal(ts.pivot, true)
- assert_equal(ts.table, true)
+
+ assert_equal('price', ts.name)
+ assert(ts.pivot)
+ assert(ts.table)
end
def test_name
assert_raise(ArgumentError) { @item.name = -1.1 }
assert_nothing_raised { @item.name = "lovely table style" }
- assert_equal(@item.name, "lovely table style")
+ assert_equal("lovely table style", @item.name)
end
def test_pivot
assert_raise(ArgumentError) { @item.pivot = -1.1 }
assert_nothing_raised { @item.pivot = true }
- assert_equal(@item.pivot, true)
+ assert(@item.pivot)
end
def test_table
assert_raise(ArgumentError) { @item.table = -1.1 }
assert_nothing_raised { @item.table = true }
- assert_equal(@item.table, true)
+ assert(@item.table)
end
def test_to_xml_string
doc = Nokogiri::XML(@item.to_xml_string)
+
assert(doc.xpath("//tableStyle[@name='#{@item.name}']"))
end
end
diff --git a/test/stylesheet/tc_table_style_element.rb b/test/stylesheet/tc_table_style_element.rb
index 2b52a23d..6dcbedd9 100644
--- a/test/stylesheet/tc_table_style_element.rb
+++ b/test/stylesheet/tc_table_style_element.rb
@@ -8,36 +8,38 @@ class TestTableStyleElement < Test::Unit::TestCase
def teardown; end
def test_initialiation
- assert_equal(@item.type, nil)
- assert_equal(@item.size, nil)
- assert_equal(@item.dxfId, nil)
+ assert_nil(@item.type)
+ assert_nil(@item.size)
+ assert_nil(@item.dxfId)
options = { :type => :headerRow, :size => 10, :dxfId => 1 }
tse = Axlsx::TableStyleElement.new options
+
options.each { |key, value| assert_equal(tse.send(key.to_sym), value) }
end
def test_type
assert_raise(ArgumentError) { @item.type = -1.1 }
assert_nothing_raised { @item.type = :blankRow }
- assert_equal(@item.type, :blankRow)
+ assert_equal(:blankRow, @item.type)
end
def test_size
assert_raise(ArgumentError) { @item.size = -1.1 }
assert_nothing_raised { @item.size = 2 }
- assert_equal(@item.size, 2)
+ assert_equal(2, @item.size)
end
def test_dxfId
assert_raise(ArgumentError) { @item.dxfId = -1.1 }
assert_nothing_raised { @item.dxfId = 7 }
- assert_equal(@item.dxfId, 7)
+ assert_equal(7, @item.dxfId)
end
def test_to_xml_string
doc = Nokogiri::XML(@item.to_xml_string)
@item.type = :headerRow
+
assert(doc.xpath("//tableStyleElement[@type='#{@item.type}']"))
end
end
diff --git a/test/stylesheet/tc_table_styles.rb b/test/stylesheet/tc_table_styles.rb
index 5ce315d5..4fdee796 100644
--- a/test/stylesheet/tc_table_styles.rb
+++ b/test/stylesheet/tc_table_styles.rb
@@ -8,19 +8,19 @@ class TestTableStyles < Test::Unit::TestCase
def teardown; end
def test_initialiation
- assert_equal(@item.defaultTableStyle, "TableStyleMedium9")
- assert_equal(@item.defaultPivotStyle, "PivotStyleLight16")
+ assert_equal("TableStyleMedium9", @item.defaultTableStyle)
+ assert_equal("PivotStyleLight16", @item.defaultPivotStyle)
end
def test_defaultTableStyle
assert_raise(ArgumentError) { @item.defaultTableStyle = -1.1 }
assert_nothing_raised { @item.defaultTableStyle = "anyones guess" }
- assert_equal(@item.defaultTableStyle, "anyones guess")
+ assert_equal("anyones guess", @item.defaultTableStyle)
end
def test_defaultPivotStyle
assert_raise(ArgumentError) { @item.defaultPivotStyle = -1.1 }
assert_nothing_raised { @item.defaultPivotStyle = "anyones guess" }
- assert_equal(@item.defaultPivotStyle, "anyones guess")
+ assert_equal("anyones guess", @item.defaultPivotStyle)
end
end
diff --git a/test/stylesheet/tc_xf.rb b/test/stylesheet/tc_xf.rb
index 9a972aaf..71ce71a4 100644
--- a/test/stylesheet/tc_xf.rb
+++ b/test/stylesheet/tc_xf.rb
@@ -8,21 +8,21 @@ class TestXf < Test::Unit::TestCase
def teardown; end
def test_initialiation
- assert_equal(@item.alignment, nil)
- assert_equal(@item.protection, nil)
- assert_equal(@item.numFmtId, nil)
- assert_equal(@item.fontId, nil)
- assert_equal(@item.fillId, nil)
- assert_equal(@item.borderId, nil)
- assert_equal(@item.xfId, nil)
- assert_equal(@item.quotePrefix, nil)
- assert_equal(@item.pivotButton, nil)
- assert_equal(@item.applyNumberFormat, nil)
- assert_equal(@item.applyFont, nil)
- assert_equal(@item.applyFill, nil)
- assert_equal(@item.applyBorder, nil)
- assert_equal(@item.applyAlignment, nil)
- assert_equal(@item.applyProtection, nil)
+ assert_nil(@item.alignment)
+ assert_nil(@item.protection)
+ assert_nil(@item.numFmtId)
+ assert_nil(@item.fontId)
+ assert_nil(@item.fillId)
+ assert_nil(@item.borderId)
+ assert_nil(@item.xfId)
+ assert_nil(@item.quotePrefix)
+ assert_nil(@item.pivotButton)
+ assert_nil(@item.applyNumberFormat)
+ assert_nil(@item.applyFont)
+ assert_nil(@item.applyFill)
+ assert_nil(@item.applyBorder)
+ assert_nil(@item.applyAlignment)
+ assert_nil(@item.applyProtection)
end
def test_alignment
@@ -40,78 +40,78 @@ class TestXf < Test::Unit::TestCase
def test_numFmtId
assert_raise(ArgumentError) { @item.numFmtId = -1.1 }
assert_nothing_raised { @item.numFmtId = 0 }
- assert_equal(@item.numFmtId, 0)
+ assert_equal(0, @item.numFmtId)
end
def test_fillId
assert_raise(ArgumentError) { @item.fillId = -1.1 }
assert_nothing_raised { @item.fillId = 0 }
- assert_equal(@item.fillId, 0)
+ assert_equal(0, @item.fillId)
end
def test_fontId
assert_raise(ArgumentError) { @item.fontId = -1.1 }
assert_nothing_raised { @item.fontId = 0 }
- assert_equal(@item.fontId, 0)
+ assert_equal(0, @item.fontId)
end
def test_borderId
assert_raise(ArgumentError) { @item.borderId = -1.1 }
assert_nothing_raised { @item.borderId = 0 }
- assert_equal(@item.borderId, 0)
+ assert_equal(0, @item.borderId)
end
def test_xfId
assert_raise(ArgumentError) { @item.xfId = -1.1 }
assert_nothing_raised { @item.xfId = 0 }
- assert_equal(@item.xfId, 0)
+ assert_equal(0, @item.xfId)
end
def test_quotePrefix
assert_raise(ArgumentError) { @item.quotePrefix = -1.1 }
assert_nothing_raised { @item.quotePrefix = false }
- assert_equal(@item.quotePrefix, false)
+ refute(@item.quotePrefix)
end
def test_pivotButton
assert_raise(ArgumentError) { @item.pivotButton = -1.1 }
assert_nothing_raised { @item.pivotButton = false }
- assert_equal(@item.pivotButton, false)
+ refute(@item.pivotButton)
end
def test_applyNumberFormat
assert_raise(ArgumentError) { @item.applyNumberFormat = -1.1 }
assert_nothing_raised { @item.applyNumberFormat = false }
- assert_equal(@item.applyNumberFormat, false)
+ refute(@item.applyNumberFormat)
end
def test_applyFont
assert_raise(ArgumentError) { @item.applyFont = -1.1 }
assert_nothing_raised { @item.applyFont = false }
- assert_equal(@item.applyFont, false)
+ refute(@item.applyFont)
end
def test_applyFill
assert_raise(ArgumentError) { @item.applyFill = -1.1 }
assert_nothing_raised { @item.applyFill = false }
- assert_equal(@item.applyFill, false)
+ refute(@item.applyFill)
end
def test_applyBorder
assert_raise(ArgumentError) { @item.applyBorder = -1.1 }
assert_nothing_raised { @item.applyBorder = false }
- assert_equal(@item.applyBorder, false)
+ refute(@item.applyBorder)
end
def test_applyAlignment
assert_raise(ArgumentError) { @item.applyAlignment = -1.1 }
assert_nothing_raised { @item.applyAlignment = false }
- assert_equal(@item.applyAlignment, false)
+ refute(@item.applyAlignment)
end
def test_applyProtection
assert_raise(ArgumentError) { @item.applyProtection = -1.1 }
assert_nothing_raised { @item.applyProtection = false }
- assert_equal(@item.applyProtection, false)
+ refute(@item.applyProtection)
end
end
diff --git a/test/tc_axlsx.rb b/test/tc_axlsx.rb
index ccfdbfab..fdc10119 100644
--- a/test/tc_axlsx.rb
+++ b/test/tc_axlsx.rb
@@ -15,11 +15,11 @@ class TestAxlsx < Test::Unit::TestCase
end
def test_cell_range_empty_if_no_cell
- assert_equal(Axlsx.cell_range([]), "")
+ assert_equal("", Axlsx.cell_range([]))
end
def test_do_not_trust_input_by_default
- assert_equal false, Axlsx.trust_input
+ refute Axlsx.trust_input
end
def test_trust_input_can_be_set_to_true
@@ -28,7 +28,8 @@ class TestAxlsx < Test::Unit::TestCase
old = Axlsx.trust_input
Axlsx.trust_input = true
- assert_equal true, Axlsx.trust_input
+
+ assert Axlsx.trust_input
Axlsx.trust_input = old
end
@@ -39,7 +40,8 @@ class TestAxlsx < Test::Unit::TestCase
row = ws.add_row
c1 = row.add_cell
c2 = row.add_cell
- assert_equal(Axlsx.cell_range([c2, c1], false), "A1:B1")
+
+ assert_equal("A1:B1", Axlsx.cell_range([c2, c1], false))
end
def test_cell_range_absolute
@@ -48,7 +50,8 @@ class TestAxlsx < Test::Unit::TestCase
row = ws.add_row
c1 = row.add_cell
c2 = row.add_cell
- assert_equal(Axlsx.cell_range([c2, c1], true), "'Sheet &lt;''&gt;&quot; 1'!$A$1:$B$1")
+
+ assert_equal("'Sheet &lt;''&gt;&quot; 1'!$A$1:$B$1", Axlsx.cell_range([c2, c1], true))
end
def test_cell_range_row
@@ -58,11 +61,13 @@ class TestAxlsx < Test::Unit::TestCase
row.add_cell
row.add_cell
row.add_cell
+
assert_equal("A1:C1", Axlsx.cell_range(row, false))
end
def test_name_to_indices
setup_wide
+
@wide_test_points.each do |key, value|
assert_equal(Axlsx.name_to_indices(key), [value, 2])
end
@@ -70,6 +75,7 @@ class TestAxlsx < Test::Unit::TestCase
def test_col_ref
setup_wide
+
@wide_test_points.each do |key, value|
assert_equal(Axlsx.col_ref(value), key.gsub(/\d+/, ''))
end
@@ -88,14 +94,14 @@ class TestAxlsx < Test::Unit::TestCase
def test_sanitize_frozen_control_strippped
needs_sanitize = "legit\x08".freeze # Backspace control char
- assert_equal(Axlsx.sanitize(needs_sanitize), 'legit', 'should strip control chars')
+ assert_equal('legit', Axlsx.sanitize(needs_sanitize), 'should strip control chars')
end
def test_sanitize_unfrozen_control_strippped
needs_sanitize = "legit\x08" # Backspace control char
sanitized_str = Axlsx.sanitize(needs_sanitize)
- assert_equal(sanitized_str, 'legit', 'should strip control chars')
+ assert_equal('legit', sanitized_str, 'should strip control chars')
assert_equal(sanitized_str.object_id, sanitized_str.object_id, 'should preserve object')
end
@@ -117,38 +123,47 @@ class TestAxlsx < Test::Unit::TestCase
def test_instance_values_for
empty = InstanceValuesSubject.new
- assert_equal({}, Axlsx.instance_values_for(empty), 'should generate with no ivars')
+
+ assert_empty(Axlsx.instance_values_for(empty), 'should generate with no ivars')
single = InstanceValuesSubject.new(a: 2)
+
assert_equal({ "a" => 2 }, Axlsx.instance_values_for(single), 'should generate for a single ivar')
double = InstanceValuesSubject.new(a: 2, b: "c")
+
assert_equal({ "a" => 2, "b" => "c" }, Axlsx.instance_values_for(double), 'should generate for multiple ivars')
inner_obj = Object.new
complex = InstanceValuesSubject.new(obj: inner_obj)
+
assert_equal({ "obj" => inner_obj }, Axlsx.instance_values_for(complex), 'should pass value of ivar directly')
nil_subject = InstanceValuesSubject.new(nil_obj: nil)
+
assert_equal({ "nil_obj" => nil }, Axlsx.instance_values_for(nil_subject), 'should return nil ivars')
end
def test_hash_deep_merge
h1 = { foo: { bar: true } }
h2 = { foo: { baz: true } }
+
assert_equal({ foo: { baz: true } }, h1.merge(h2))
assert_equal({ foo: { bar: true, baz: true } }, Axlsx.hash_deep_merge(h1, h2))
end
def test_escape_formulas
Axlsx.instance_variable_set(:@escape_formulas, nil)
- assert_equal false, Axlsx::escape_formulas
+
+ refute Axlsx::escape_formulas
Axlsx::escape_formulas = true
- assert_equal true, Axlsx::escape_formulas
+
+ assert Axlsx::escape_formulas
Axlsx::escape_formulas = false
- assert_equal false, Axlsx::escape_formulas
+
+ refute Axlsx::escape_formulas
ensure
Axlsx.instance_variable_set(:@escape_formulas, nil)
end
diff --git a/test/tc_package.rb b/test/tc_package.rb
index 58fe8e76..34b07aa4 100644
--- a/test/tc_package.rb
+++ b/test/tc_package.rb
@@ -94,7 +94,8 @@ class TestPackage < Test::Unit::TestCase
def test_use_autowidth
@package.use_autowidth = false
- assert(@package.workbook.use_autowidth == false)
+
+ refute(@package.workbook.use_autowidth)
end
def test_core_accessor
@@ -108,7 +109,7 @@ class TestPackage < Test::Unit::TestCase
end
def test_use_shared_strings
- assert_equal(@package.use_shared_strings, nil)
+ assert_nil(@package.use_shared_strings)
assert_raise(ArgumentError) { @package.use_shared_strings 9 }
assert_nothing_raised { @package.use_shared_strings = true }
assert_equal(@package.use_shared_strings, @package.workbook.use_shared_strings)
@@ -118,17 +119,19 @@ class TestPackage < Test::Unit::TestCase
assert(Axlsx.instance_values_for(@package)["app"].is_a?(Axlsx::App), 'App object not created')
assert(Axlsx.instance_values_for(@package)["core"].is_a?(Axlsx::Core), 'Core object not created')
assert(@package.workbook.is_a?(Axlsx::Workbook), 'Workbook object not created')
- assert(Axlsx::Package.new.workbook.worksheets.empty?, 'Workbook should not have sheets by default')
+ assert_empty(Axlsx::Package.new.workbook.worksheets, 'Workbook should not have sheets by default')
end
def test_created_at_is_propagated_to_core
time = Time.utc(2013, 1, 1, 12, 0)
p = Axlsx::Package.new :created_at => time
+
assert_equal(time, p.core.created)
end
def test_serialization
@package.serialize(@fname)
+
assert_zip_file_matches_package(@fname, @package)
assert_created_with_rubyzip(@fname, @package)
File.delete(@fname)
@@ -136,6 +139,7 @@ class TestPackage < Test::Unit::TestCase
def test_serialization_with_zip_command
@package.serialize(@fname, zip_command: "zip")
+
assert_zip_file_matches_package(@fname, @package)
assert_created_with_zip_command(@fname, @package)
File.delete(@fname)
@@ -144,6 +148,7 @@ class TestPackage < Test::Unit::TestCase
def test_serialization_with_zip_command_and_absolute_path
fname = "#{Dir.tmpdir}/#{@fname}"
@package.serialize(fname, zip_command: "zip")
+
assert_zip_file_matches_package(fname, @package)
assert_created_with_zip_command(fname, @package)
File.delete(fname)
@@ -169,7 +174,7 @@ class TestPackage < Test::Unit::TestCase
p.serialize(@fname)
- assert_equal true, wb.styles_applied
+ assert wb.styles_applied
assert_equal 1, wb.styles.style_index.count
File.delete(@fname)
@@ -199,6 +204,7 @@ class TestPackage < Test::Unit::TestCase
warnings = capture_warnings do
@package.serialize(@fname, false)
end
+
assert_equal 1, warnings.size
assert_includes warnings.first, "confirm_valid as a boolean is deprecated"
File.delete(@fname)
@@ -208,6 +214,7 @@ class TestPackage < Test::Unit::TestCase
warnings = capture_warnings do
@package.serialize(@fname, true, zip_command: "zip")
end
+
assert_zip_file_matches_package(@fname, @package)
assert_created_with_zip_command(@fname, @package)
assert_equal 2, warnings.size
@@ -221,7 +228,8 @@ class TestPackage < Test::Unit::TestCase
zip_content_now = @package.to_stream.string
Timecop.travel(3600) do
zip_content_then = @package.to_stream.string
- assert zip_content_then == zip_content_now, "zip files are not identical"
+
+ assert_equal zip_content_then, zip_content_now, "zip files are not identical"
end
end
@@ -233,30 +241,31 @@ class TestPackage < Test::Unit::TestCase
end
end
end
- assert package_1.to_stream.string == package_2.to_stream.string, "zip files are not identical"
+
+ assert_equal package_1.to_stream.string, package_2.to_stream.string, "zip files are not identical"
end
def test_serialization_creates_files_with_excel_mime_type
- assert_equal(Marcel::MimeType.for(@package.to_stream),
- 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet')
+ assert_equal('application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', Marcel::MimeType.for(@package.to_stream))
end
def test_validation
- assert_equal(@package.validate.size, 0, @package.validate)
+ assert_equal(0, @package.validate.size, @package.validate)
Axlsx::Workbook.send(:class_variable_set, :@@date1904, 9900)
+
+ refute_empty(@package.validate)
end
def test_parts
p = @package.send(:parts)
# all parts have an entry
- assert_equal(p.select { |part| part[:entry] =~ %r{_rels/\.rels} }.size, 1, "rels missing")
- assert_equal(p.select { |part| part[:entry] =~ %r{docProps/core\.xml} }.size, 1, "core missing")
- assert_equal(p.select { |part| part[:entry] =~ %r{docProps/app\.xml} }.size, 1, "app missing")
- assert_equal(p.select { |part| part[:entry] =~ %r{xl/_rels/workbook\.xml\.rels} }.size, 1, "workbook rels missing")
- assert_equal(p.select { |part| part[:entry] =~ %r{xl/workbook\.xml} }.size, 1, "workbook missing")
- assert_equal(p.select { |part| part[:entry] =~ /\[Content_Types\]\.xml/ }.size, 1, "content types missing")
- assert_equal(p.select { |part| part[:entry] =~ %r{xl/styles\.xml} }.size, 1, "styles missin")
+ assert_equal(1, p.select { |part| part[:entry] =~ %r{_rels/\.rels} }.size, "rels missing")
+ assert_equal(1, p.select { |part| part[:entry] =~ %r{docProps/core\.xml} }.size, "core missing")
+ assert_equal(1, p.select { |part| part[:entry] =~ %r{docProps/app\.xml} }.size, "app missing")
+ assert_equal(1, p.select { |part| part[:entry] =~ %r{xl/_rels/workbook\.xml\.rels} }.size, "workbook rels missing")
+ assert_equal(1, p.select { |part| part[:entry] =~ %r{xl/workbook\.xml} }.size, "workbook missing")
+ assert_equal(1, p.select { |part| part[:entry] =~ /\[Content_Types\]\.xml/ }.size, "content types missing")
+ assert_equal(1, p.select { |part| part[:entry] =~ %r{xl/styles\.xml} }.size, "styles missin")
assert_equal(p.select { |part| part[:entry] =~ %r{xl/drawings/_rels/drawing\d\.xml\.rels} }.size, @package.workbook.drawings.size, "one or more drawing rels missing")
assert_equal(p.select { |part| part[:entry] =~ %r{xl/drawings/drawing\d\.xml} }.size, @package.workbook.drawings.size, "one or more drawings missing")
assert_equal(p.select { |part| part[:entry] =~ %r{xl/charts/chart\d\.xml} }.size, @package.workbook.charts.size, "one or more charts missing")
@@ -280,7 +289,8 @@ class TestPackage < Test::Unit::TestCase
@package.use_shared_strings = true
@package.to_stream # ensure all cell_serializer paths are hit
p = @package.send(:parts)
- assert_equal(p.select { |part| part[:entry] =~ %r{xl/sharedStrings.xml} }.size, 1, "shared strings table missing")
+
+ assert_equal(1, p.select { |part| part[:entry] =~ %r{xl/sharedStrings.xml} }.size, "shared strings table missing")
end
def test_workbook_is_a_workbook
@@ -289,37 +299,40 @@ class TestPackage < Test::Unit::TestCase
def test_base_content_types
ct = @package.send(:base_content_types)
- assert(ct.select { |c| c.ContentType == Axlsx::RELS_CT }.size == 1, "rels content type missing")
- assert(ct.select { |c| c.ContentType == Axlsx::XML_CT }.size == 1, "xml content type missing")
- assert(ct.select { |c| c.ContentType == Axlsx::APP_CT }.size == 1, "app content type missing")
- assert(ct.select { |c| c.ContentType == Axlsx::CORE_CT }.size == 1, "core content type missing")
- assert(ct.select { |c| c.ContentType == Axlsx::STYLES_CT }.size == 1, "styles content type missing")
- assert(ct.select { |c| c.ContentType == Axlsx::WORKBOOK_CT }.size == 1, "workbook content type missing")
- assert(ct.size == 6)
+
+ assert_equal(1, ct.select { |c| c.ContentType == Axlsx::RELS_CT }.size, "rels content type missing")
+ assert_equal(1, ct.select { |c| c.ContentType == Axlsx::XML_CT }.size, "xml content type missing")
+ assert_equal(1, ct.select { |c| c.ContentType == Axlsx::APP_CT }.size, "app content type missing")
+ assert_equal(1, ct.select { |c| c.ContentType == Axlsx::CORE_CT }.size, "core content type missing")
+ assert_equal(1, ct.select { |c| c.ContentType == Axlsx::STYLES_CT }.size, "styles content type missing")
+ assert_equal(1, ct.select { |c| c.ContentType == Axlsx::WORKBOOK_CT }.size, "workbook content type missing")
+ assert_equal(6, ct.size)
end
def test_content_type_added_with_shared_strings
@package.use_shared_strings = true
ct = @package.send(:content_types)
- assert(ct.select { |type| type.ContentType == Axlsx::SHARED_STRINGS_CT }.size == 1)
+
+ assert_equal(1, ct.select { |type| type.ContentType == Axlsx::SHARED_STRINGS_CT }.size)
end
def test_name_to_indices
- assert(Axlsx::name_to_indices('A1') == [0, 0])
- assert(Axlsx::name_to_indices('A100') == [0, 99], 'needs to axcept rows that contain 0')
+ assert_equal([0, 0], Axlsx::name_to_indices('A1'))
+ assert_equal([0, 99], Axlsx::name_to_indices('A100'), 'needs to axcept rows that contain 0')
end
def test_to_stream
stream = @package.to_stream
+
assert(stream.is_a?(StringIO))
# this is just a roundabout guess for a package as it is build now
# in testing.
assert(stream.size > 80000)
# Stream (of zipped contents) should have appropriate default encoding
- assert stream.string.valid_encoding?
+ assert_predicate stream.string, :valid_encoding?
assert_equal(stream.external_encoding, Encoding::ASCII_8BIT)
# Cached ids should be cleared
- assert(Axlsx::Relationship.ids_cache.empty?)
+ assert_empty(Axlsx::Relationship.ids_cache)
end
def test_to_stream_automatically_performs_apply_styles
@@ -339,6 +352,6 @@ class TestPackage < Test::Unit::TestCase
def test_encrypt
# this is no where near close to ready yet
- assert(@package.encrypt('your_mom.xlsxl', 'has a password') == false)
+ refute(@package.encrypt('your_mom.xlsxl', 'has a password'))
end
end
diff --git a/test/util/tc_mime_type_utils.rb b/test/util/tc_mime_type_utils.rb
index e469f31e..796c8f3a 100644
--- a/test/util/tc_mime_type_utils.rb
+++ b/test/util/tc_mime_type_utils.rb
@@ -11,7 +11,7 @@ class TestMimeTypeUtils < Test::Unit::TestCase
def teardown; end
def test_mime_type_utils
- assert_equal(Axlsx::MimeTypeUtils::get_mime_type(@test_img), 'image/jpeg')
- assert_equal(Axlsx::MimeTypeUtils::get_mime_type_from_uri(@test_img_url), 'image/png')
+ assert_equal('image/jpeg', Axlsx::MimeTypeUtils::get_mime_type(@test_img))
+ assert_equal('image/png', Axlsx::MimeTypeUtils::get_mime_type_from_uri(@test_img_url))
end
end
diff --git a/test/util/tc_serialized_attributes.rb b/test/util/tc_serialized_attributes.rb
index 88c7536d..886bafde 100644
--- a/test/util/tc_serialized_attributes.rb
+++ b/test/util/tc_serialized_attributes.rb
@@ -14,6 +14,7 @@ class TestSeralizedAttributes < Test::Unit::TestCase
def test_camel_symbol
@object.camel_symbol = :foo_bar
+
assert_equal('camelSymbol="fooBar" ', @object.serialized_attributes)
end
end
diff --git a/test/util/tc_simple_typed_list.rb b/test/util/tc_simple_typed_list.rb
index 5624b903..651764e1 100644
--- a/test/util/tc_simple_typed_list.rb
+++ b/test/util/tc_simple_typed_list.rb
@@ -28,20 +28,22 @@ class TestSimpleTypedList < Test::Unit::TestCase
end
def test_concat_should_return_index
- assert(@list.empty?)
- assert(@list << 1 == 0)
- assert(@list << 2 == 1)
+ assert_empty(@list)
+ assert_equal(0, @list << 1)
+ assert_equal(1, @list << 2)
@list.delete_at 0
- assert(@list << 3 == 1)
- assert(@list.index(2) == 0)
+
+ assert_equal(1, @list << 3)
+ assert_equal(0, @list.index(2))
end
def test_push_should_return_index
- assert(@list.push(1) == 0)
- assert(@list.push(2) == 1)
+ assert_equal(0, @list.push(1))
+ assert_equal(1, @list.push(2))
@list.delete_at 0
- assert(@list.push(3) == 1)
- assert(@list.index(2) == 0)
+
+ assert_equal(1, @list.push(3))
+ assert_equal(0, @list.index(2))
end
def test_locking
@@ -63,14 +65,17 @@ class TestSimpleTypedList < Test::Unit::TestCase
def test_delete
@list.push 1
- assert(@list.size == 1)
+
+ assert_equal(1, @list.size)
@list.delete 1
- assert(@list.empty?)
+
+ assert_empty(@list)
end
def test_equality
@list.push 1
@list.push 2
- assert_equal(@list.to_ary, [1, 2])
+
+ assert_equal([1, 2], @list.to_ary)
end
end
diff --git a/test/workbook/tc_defined_name.rb b/test/workbook/tc_defined_name.rb
index e7fbe6b5..25db45db 100644
--- a/test/workbook/tc_defined_name.rb
+++ b/test/workbook/tc_defined_name.rb
@@ -31,7 +31,8 @@ class TestDefinedNames < Test::Unit::TestCase
def test_do_not_camelcase_value_for_name
@dn.name = '_xlnm._FilterDatabase'
doc = Nokogiri::XML(@dn.to_xml_string)
- assert_equal(doc.xpath("//definedName[@name='_xlnm._FilterDatabase']").size, 1)
+
+ assert_equal(1, doc.xpath("//definedName[@name='_xlnm._FilterDatabase']").size)
assert_equal('Sheet1!A1:A1', doc.xpath('//definedName').text)
end
@@ -40,8 +41,9 @@ class TestDefinedNames < Test::Unit::TestCase
@dn.name = '_xlnm.Print_Titles'
@dn.hidden = true
doc = Nokogiri::XML(@dn.to_xml_string)
- assert_equal(doc.xpath("//definedName[@name='_xlnm.Print_Titles']").size, 1)
- assert_equal(doc.xpath("//definedName[@hidden='1']").size, 1)
+
+ assert_equal(1, doc.xpath("//definedName[@name='_xlnm.Print_Titles']").size)
+ assert_equal(1, doc.xpath("//definedName[@hidden='1']").size)
assert_equal('Sheet1!A1:A1', doc.xpath('//definedName').text)
end
end
diff --git a/test/workbook/tc_shared_strings_table.rb b/test/workbook/tc_shared_strings_table.rb
index 775f6ae7..b8843f04 100644
--- a/test/workbook/tc_shared_strings_table.rb
+++ b/test/workbook/tc_shared_strings_table.rb
@@ -17,17 +17,20 @@ class TestSharedStringsTable < Test::Unit::TestCase
def test_count
sst = @p.workbook.shared_strings
- assert_equal(sst.count, 7)
+
+ assert_equal(7, sst.count)
end
def test_unique_count
sst = @p.workbook.shared_strings
- assert_equal(sst.unique_count, 4)
+
+ assert_equal(4, sst.unique_count)
end
def test_uses_workbook_xml_space
assert_equal(@p.workbook.xml_space, @p.workbook.shared_strings.xml_space)
@p.workbook.xml_space = :default
+
assert_equal(:default, @p.workbook.shared_strings.xml_space)
end
@@ -39,7 +42,8 @@ class TestSharedStringsTable < Test::Unit::TestCase
puts error.message
errors << error
end
- assert_equal(errors.size, 0, "sharedStirngs.xml Invalid" + errors.map(&:message).to_s)
+
+ assert_equal(0, errors.size, "sharedStirngs.xml Invalid" + errors.map(&:message).to_s)
end
def test_remove_control_characters_in_xml_serialization
diff --git a/test/workbook/tc_workbook.rb b/test/workbook/tc_workbook.rb
index f0a7ac19..1e8a35e4 100644
--- a/test/workbook/tc_workbook.rb
+++ b/test/workbook/tc_workbook.rb
@@ -11,37 +11,41 @@ class TestWorkbook < Test::Unit::TestCase
def test_worksheet_users_xml_space
sheet = @wb.add_worksheet(:name => 'foo')
ws_xml = Nokogiri::XML(sheet.to_xml_string)
+
assert(ws_xml.xpath("//xmlns:worksheet/@xml:space='preserve'"))
@wb.xml_space = :default
ws_xml = Nokogiri::XML(sheet.to_xml_string)
+
assert(ws_xml.xpath("//xmlns:worksheet/@xml:space='default'"))
end
def test_xml_space
assert_equal(:preserve, @wb.xml_space)
@wb.xml_space = :default
+
assert_equal(:default, @wb.xml_space)
assert_raise(ArgumentError) { @wb.xml_space = :none }
end
def test_no_autowidth
- assert_equal(@wb.use_autowidth, true)
+ assert(@wb.use_autowidth)
assert_raise(ArgumentError) { @wb.use_autowidth = 0.1 }
assert_nothing_raised { @wb.use_autowidth = false }
- assert_equal(@wb.use_autowidth, false)
+ refute(@wb.use_autowidth)
end
def test_is_reversed
- assert_equal(@wb.is_reversed, nil)
+ assert_nil(@wb.is_reversed)
assert_raise(ArgumentError) { @wb.is_reversed = 0.1 }
assert_nothing_raised { @wb.is_reversed = true }
- assert_equal(@wb.use_autowidth, true)
+ assert(@wb.use_autowidth)
end
def test_sheet_by_name_retrieval
@wb.add_worksheet(:name => 'foo')
@wb.add_worksheet(:name => 'bar')
+
assert_equal('foo', @wb.sheet_by_name('foo').name)
end
@@ -52,49 +56,57 @@ class TestWorkbook < Test::Unit::TestCase
def test_date1904
assert_equal(Axlsx::Workbook.date1904, @wb.date1904)
@wb.date1904 = :false
+
assert_equal(Axlsx::Workbook.date1904, @wb.date1904)
Axlsx::Workbook.date1904 = :true
+
assert_equal(Axlsx::Workbook.date1904, @wb.date1904)
end
def test_add_defined_name
@wb.add_defined_name 'Sheet1!1:1', :name => '_xlnm.Print_Titles', :hidden => true
+
assert_equal(1, @wb.defined_names.size)
end
def test_add_view
@wb.add_view visibility: :hidden, window_width: 800
+
assert_equal(1, @wb.views.size)
end
def test_shared_strings
- assert_equal(@wb.use_shared_strings, nil)
+ assert_nil(@wb.use_shared_strings)
assert_raise(ArgumentError) { @wb.use_shared_strings = 'bpb' }
assert_nothing_raised { @wb.use_shared_strings = :true }
end
def test_add_worksheet
- assert(@wb.worksheets.empty?, "worbook has no worksheets by default")
+ assert_empty(@wb.worksheets, "worbook has no worksheets by default")
ws = @wb.add_worksheet(:name => "bob")
- assert_equal(@wb.worksheets.size, 1, "add_worksheet adds a worksheet!")
+
+ assert_equal(1, @wb.worksheets.size, "add_worksheet adds a worksheet!")
assert_equal(@wb.worksheets.first, ws, "the worksheet returned is the worksheet added")
- assert_equal(ws.name, "bob", "name option gets passed to worksheet")
+ assert_equal("bob", ws.name, "name option gets passed to worksheet")
end
def test_insert_worksheet
@wb.add_worksheet(:name => 'A')
@wb.add_worksheet(:name => 'B')
ws3 = @wb.insert_worksheet(0, :name => 'C')
+
assert_equal(ws3.name, @wb.worksheets.first.name)
end
def test_relationships
# current relationship size is 1 due to style relation
- assert(@wb.relationships.size == 1)
+ assert_equal(1, @wb.relationships.size)
@wb.add_worksheet
- assert(@wb.relationships.size == 2)
+
+ assert_equal(2, @wb.relationships.size)
@wb.use_shared_strings = true
- assert(@wb.relationships.size == 3)
+
+ assert_equal(3, @wb.relationships.size)
end
def test_to_xml
@@ -105,7 +117,8 @@ class TestWorkbook < Test::Unit::TestCase
errors.push error
puts error.message
end
- assert(errors.empty?, "error free validation")
+
+ assert_empty(errors, "error free validation")
end
def test_to_xml_reversed
@@ -113,6 +126,7 @@ class TestWorkbook < Test::Unit::TestCase
@wb.add_worksheet(:name => 'first')
second = @wb.add_worksheet(:name => 'second')
doc = Nokogiri::XML(@wb.to_xml_string)
+
assert_equal second.name, doc.xpath('//xmlns:workbook/xmlns:sheets/*[1]/@name').to_s
end
@@ -121,13 +135,14 @@ class TestWorkbook < Test::Unit::TestCase
ws.add_row [1, 2, 3]
ws.add_row [4, 5, 6]
assert_raise(ArgumentError, "no sheet name part") { @wb["A1:C2"] }
- assert_equal @wb['fish!A1:C2'].size, 6
+ assert_equal(6, @wb['fish!A1:C2'].size)
end
def test_to_xml_adds_worksheet_when_worksheets_is_empty
- assert(@wb.worksheets.empty?)
+ assert_empty(@wb.worksheets)
@wb.to_xml_string
- assert(@wb.worksheets.size == 1)
+
+ assert_equal(1, @wb.worksheets.size)
end
def test_to_xml_string_defined_names
@@ -136,6 +151,7 @@ class TestWorkbook < Test::Unit::TestCase
sheet.auto_filter = "A1:B1"
end
doc = Nokogiri::XML(@wb.to_xml_string)
+
assert_equal(doc.xpath('//xmlns:workbook/xmlns:definedNames/xmlns:definedName').inner_text, @wb.worksheets[0].auto_filter.defined_name)
end
@@ -145,6 +161,7 @@ class TestWorkbook < Test::Unit::TestCase
end
@wb.add_view active_tab: 0, first_sheet: 0
doc = Nokogiri::XML(@wb.to_xml_string)
+
assert_equal(1, doc.xpath('//xmlns:workbook/xmlns:bookViews/xmlns:workbookView[@activeTab=0]').size)
end
@@ -152,12 +169,14 @@ class TestWorkbook < Test::Unit::TestCase
ws = @wb.add_worksheet
pivot_table = ws.add_pivot_table('G5:G6', 'A1:D5')
doc = Nokogiri::XML(@wb.to_xml_string)
+
assert_equal pivot_table.cache_definition.rId, doc.xpath("//xmlns:pivotCache").first["r:id"]
end
def test_worksheet_name_is_intact_after_serialized_into_xml
sheet = @wb.add_worksheet(:name => '_Example')
wb_xml = Nokogiri::XML(@wb.to_xml_string)
+
assert_equal sheet.name, wb_xml.xpath('//xmlns:workbook/xmlns:sheets/*[1]/@name').to_s
end
@@ -165,6 +184,7 @@ class TestWorkbook < Test::Unit::TestCase
Axlsx::escape_formulas = false
p = Axlsx::Package.new
@wb = p.workbook
+
assert_false @wb.escape_formulas
assert_false @wb.add_worksheet.escape_formulas
assert_false @wb.add_worksheet(escape_formulas: false).escape_formulas
@@ -173,12 +193,14 @@ class TestWorkbook < Test::Unit::TestCase
Axlsx::escape_formulas = true
p = Axlsx::Package.new
@wb = p.workbook
+
assert @wb.escape_formulas
assert @wb.add_worksheet.escape_formulas
assert_false @wb.add_worksheet(escape_formulas: false).escape_formulas
assert @wb.add_worksheet(escape_formulas: true).escape_formulas
@wb.escape_formulas = false
+
assert_false @wb.escape_formulas
assert_false @wb.add_worksheet.escape_formulas
assert_false @wb.add_worksheet(escape_formulas: false).escape_formulas
@@ -187,6 +209,7 @@ class TestWorkbook < Test::Unit::TestCase
@wb.escape_formulas = true
p = Axlsx::Package.new
@wb = p.workbook
+
assert @wb.escape_formulas
assert @wb.add_worksheet.escape_formulas
assert_false @wb.add_worksheet(escape_formulas: false).escape_formulas
diff --git a/test/workbook/tc_workbook_view.rb b/test/workbook/tc_workbook_view.rb
index 8829924f..07f21f6a 100644
--- a/test/workbook/tc_workbook_view.rb
+++ b/test/workbook/tc_workbook_view.rb
@@ -43,6 +43,7 @@ class TestWorkbookView < Test::Unit::TestCase
value = value ? 1 : 0
end
path = "workbookView[@#{Axlsx.camel(key, false)}='#{value}']"
+
assert_equal(1, doc.xpath(path).size)
end
end
diff --git a/test/workbook/worksheet/auto_filter/tc_auto_filter.rb b/test/workbook/worksheet/auto_filter/tc_auto_filter.rb
index eb561554..e14591da 100644
--- a/test/workbook/worksheet/auto_filter/tc_auto_filter.rb
+++ b/test/workbook/worksheet/auto_filter/tc_auto_filter.rb
@@ -15,6 +15,7 @@ class TestAutoFilter < Test::Unit::TestCase
def test_to_xml_string
doc = Nokogiri::XML(@auto_filter.to_xml_string)
+
assert(doc.xpath("autoFilter[@ref='#{@auto_filter.range}']"))
end
@@ -30,8 +31,9 @@ class TestAutoFilter < Test::Unit::TestCase
end
def test_applya
- assert_equal nil, @auto_filter.worksheet.rows.last.hidden
+ assert_nil @auto_filter.worksheet.rows.last.hidden
@auto_filter.apply
- assert_equal true, @auto_filter.worksheet.rows.last.hidden
+
+ assert @auto_filter.worksheet.rows.last.hidden
end
end
diff --git a/test/workbook/worksheet/auto_filter/tc_filter_column.rb b/test/workbook/worksheet/auto_filter/tc_filter_column.rb
index 88f73e0d..bf92bd44 100644
--- a/test/workbook/worksheet/auto_filter/tc_filter_column.rb
+++ b/test/workbook/worksheet/auto_filter/tc_filter_column.rb
@@ -27,17 +27,18 @@ class TestFilterColumn < Test::Unit::TestCase
filter_column = Axlsx::FilterColumn.new(0, :filters) do |filters|
filters.filter_items = [700, 100, 5]
end
+
assert_equal 3, filter_column.filter.filter_items.size
assert_equal 700, filter_column.filter.filter_items.first.val
assert_equal 5, filter_column.filter.filter_items.last.val
end
def test_default_show_button
- assert_equal true, @filter_column.show_button
+ assert @filter_column.show_button
end
def test_default_hidden_button
- assert_equal false, @filter_column.hidden_button
+ refute @filter_column.hidden_button
end
def test_show_button
@@ -63,6 +64,7 @@ class TestFilterColumn < Test::Unit::TestCase
def test_to_xml_string
doc = Nokogiri::XML(@filter_column.to_xml_string)
+
assert doc.xpath("//filterColumn[@colId=#{@filter_column.col_id}]")
assert doc.xpath("//filterColumn[@hiddenButton=#{@filter_column.hidden_button}]")
assert doc.xpath("//filterColumn[@showButton=#{@filter_column.show_button}]")
diff --git a/test/workbook/worksheet/auto_filter/tc_filters.rb b/test/workbook/worksheet/auto_filter/tc_filters.rb
index 8e853772..2002d510 100644
--- a/test/workbook/worksheet/auto_filter/tc_filters.rb
+++ b/test/workbook/worksheet/auto_filter/tc_filters.rb
@@ -8,15 +8,17 @@ class TestFilters < Test::Unit::TestCase
end
def test_blank
- assert_equal true, @filters.blank
+ assert @filters.blank
assert_raise(ArgumentError) { @filters.blank = :only_if_you_want_it }
@filters.blank = true
- assert_equal true, @filters.blank
+
+ assert @filters.blank
end
def test_calendar_type
assert_raise(ArgumentError) { @filters.calendar_type = 'monkey calendar' }
@filters.calendar_type = 'japan'
+
assert_equal('japan', @filters.calendar_type)
end
@@ -33,17 +35,20 @@ class TestFilters < Test::Unit::TestCase
def test_apply_is_false_for_matching_values
keeper = Object.new
def keeper.value; 'a'; end
- assert_equal false, @filters.apply(keeper)
+
+ refute @filters.apply(keeper)
end
def test_apply_is_true_for_non_matching_values
hidden = Object.new
def hidden.value; 'b'; end
- assert_equal true, @filters.apply(hidden)
+
+ assert @filters.apply(hidden)
end
def test_to_xml_string
doc = Nokogiri::XML(@filters.to_xml_string)
+
assert_equal(1, doc.xpath('//filters[@blank=1]').size)
end
end
diff --git a/test/workbook/worksheet/tc_border_creator.rb b/test/workbook/worksheet/tc_border_creator.rb
index c9f3df8f..f1418bb4 100644
--- a/test/workbook/worksheet/tc_border_creator.rb
+++ b/test/workbook/worksheet/tc_border_creator.rb
@@ -11,27 +11,32 @@ class TestBorderCreator < Test::Unit::TestCase
@ws.add_row [1, 2, 3]
bc = Axlsx::BorderCreator.new(worksheet: @ws, cells: @ws["A1:B1"])
+
assert_equal bc.instance_variable_get(:@edges), Axlsx::Border::EDGES
- assert_equal bc.instance_variable_get(:@style), :thin
- assert_equal bc.instance_variable_get(:@color), "000000"
+ assert_equal(:thin, bc.instance_variable_get(:@style))
+ assert_equal("000000", bc.instance_variable_get(:@color))
bc = Axlsx::BorderCreator.new(worksheet: @ws, cells: @ws["A1:B1"], edges: [:top], style: :thick, color: "ffffff")
- assert_equal bc.instance_variable_get(:@edges), [:top]
- assert_equal bc.instance_variable_get(:@style), :thick
- assert_equal bc.instance_variable_get(:@color), "ffffff"
+
+ assert_equal([:top], bc.instance_variable_get(:@edges))
+ assert_equal(:thick, bc.instance_variable_get(:@style))
+ assert_equal("ffffff", bc.instance_variable_get(:@color))
end
def test_initialize_edges
@ws.add_row [1, 2, 3]
bc = Axlsx::BorderCreator.new(worksheet: @ws, cells: @ws["A1:B1"], edges: nil)
+
assert_equal bc.instance_variable_get(:@edges), Axlsx::Border::EDGES
bc = Axlsx::BorderCreator.new(worksheet: @ws, cells: @ws["A1:B1"], edges: :all)
+
assert_equal bc.instance_variable_get(:@edges), Axlsx::Border::EDGES
bc = Axlsx::BorderCreator.new(worksheet: @ws, cells: @ws["A1:B1"], edges: [])
- assert_equal bc.instance_variable_get(:@edges), []
+
+ assert_empty(bc.instance_variable_get(:@edges))
assert_raises(ArgumentError) do
bc = Axlsx::BorderCreator.new(worksheet: @ws, cells: @ws["A1:B1"], edges: [:foo])
diff --git a/test/workbook/worksheet/tc_break.rb b/test/workbook/worksheet/tc_break.rb
index 2c67fed7..de71f591 100644
--- a/test/workbook/worksheet/tc_break.rb
+++ b/test/workbook/worksheet/tc_break.rb
@@ -27,14 +27,14 @@ class TestBreak < Test::Unit::TestCase
end
def test_man
- assert_equal(true, @break.man)
+ assert(@break.man)
assert_raises ArgumentError do
Axlsx::Break.new(:man => -1)
end
end
def test_pt
- assert_equal(false, @break.pt)
+ refute(@break.pt)
assert_raises ArgumentError do
Axlsx::Break.new(:pt => -1)
end
@@ -42,6 +42,7 @@ class TestBreak < Test::Unit::TestCase
def test_to_xml_string
doc = Nokogiri::XML(@break.to_xml_string)
- assert_equal(doc.xpath('//brk[@id="1"][@min="1"][@max="10"][@pt=0][@man=1]').size, 1)
+
+ assert_equal(1, doc.xpath('//brk[@id="1"][@min="1"][@max="10"][@pt=0][@man=1]').size)
end
end
diff --git a/test/workbook/worksheet/tc_cell.rb b/test/workbook/worksheet/tc_cell.rb
index 959304c8..9e1ebb0a 100644
--- a/test/workbook/worksheet/tc_cell.rb
+++ b/test/workbook/worksheet/tc_cell.rb
@@ -15,14 +15,15 @@ class TestCell < Test::Unit::TestCase
def test_initialize
assert_equal(@row.cells.last, @c, "the cell was added to the row")
- assert_equal(@c.type, :float, "type option is applied")
- assert_equal(@c.style, 1, "style option is applied")
- assert_equal(@c.value, 1.0, "type option is applied and value is casted")
- assert_equal(@c.escape_formulas, true, "escape formulas option is applied")
+ assert_equal(:float, @c.type, "type option is applied")
+ assert_equal(1, @c.style, "style option is applied")
+ assert_in_delta(@c.value, 1.0, 0.001, "type option is applied and value is casted")
+ assert(@c.escape_formulas, "escape formulas option is applied")
end
def test_style_date_data
c = Axlsx::Cell.new(@c.row, Time.now)
+
assert_equal(Axlsx::STYLE_DATE, c.style)
end
@@ -39,20 +40,21 @@ class TestCell < Test::Unit::TestCase
end
def test_r
- assert_equal(@c.r, "A1", "calculate cell reference")
+ assert_equal("A1", @c.r, "calculate cell reference")
end
def test_wide_r
- assert_equal(@cAA.r, "AA2", "calculate cell reference")
+ assert_equal("AA2", @cAA.r, "calculate cell reference")
end
def test_r_abs
- assert_equal(@c.r_abs, "$A$1", "calculate absolute cell reference")
- assert_equal(@cAA.r_abs, "$AA$2", "needs to accept multi-digit columns")
+ assert_equal("$A$1", @c.r_abs, "calculate absolute cell reference")
+ assert_equal("$AA$2", @cAA.r_abs, "needs to accept multi-digit columns")
end
def test_name
@c.name = 'foo'
+
assert_equal(1, @ws.workbook.defined_names.size)
assert_equal('foo', @ws.workbook.defined_names.last.name)
end
@@ -60,6 +62,7 @@ class TestCell < Test::Unit::TestCase
def test_autowidth
style = @c.row.worksheet.workbook.styles.add_style({ :alignment => { :horizontal => :center, :vertical => :center, :wrap_text => true } })
@c.style = style
+
assert_in_delta(6.6, @c.autowidth, 0.01)
end
@@ -67,11 +70,13 @@ class TestCell < Test::Unit::TestCase
style = @c.row.worksheet.workbook.styles.add_style(b: true)
@c.row.worksheet.workbook.bold_font_multiplier = 1.05
@c.style = style
+
assert_in_delta(6.93, @c.autowidth, 0.01)
end
def test_autowidth_with_font_scale_divisor
@c.row.worksheet.workbook.font_scale_divisor = 11.0
+
assert_in_delta(6.0, @c.autowidth, 0.01)
end
@@ -79,6 +84,7 @@ class TestCell < Test::Unit::TestCase
@c.type = :time
now = DateTime.now
@c.value = now
+
assert_equal(@c.value, now.to_time)
end
@@ -86,55 +92,56 @@ class TestCell < Test::Unit::TestCase
@c.type = :date
now = Time.now
@c.value = now
+
assert_equal(@c.value, now.to_date)
end
def test_style
assert_raise(ArgumentError, "must reject invalid style indexes") { @c.style = @c.row.worksheet.workbook.styles.cellXfs.size }
assert_nothing_raised("must allow valid style index changes") { @c.style = 1 }
- assert_equal(@c.style, 1)
+ assert_equal(1, @c.style)
end
def test_type
assert_raise(ArgumentError, "type must be :string, :integer, :float, :date, :time, :boolean") { @c.type = :array }
assert_nothing_raised("type can be changed") { @c.type = :string }
- assert_equal(@c.value, "1.0", "changing type casts the value")
+ assert_equal("1.0", @c.value, "changing type casts the value")
assert_equal(:float, @row.add_cell(1.0 / (10**7)).type, 'properly identify exponential floats as float type')
- assert_equal(@row.add_cell(Time.now).type, :time, 'time should be time')
- assert_equal(@row.add_cell(Date.today).type, :date, 'date should be date')
- assert_equal(@row.add_cell(true).type, :boolean, 'boolean should be boolean')
+ assert_equal(:time, @row.add_cell(Time.now).type, 'time should be time')
+ assert_equal(:date, @row.add_cell(Date.today).type, 'date should be date')
+ assert_equal(:boolean, @row.add_cell(true).type, 'boolean should be boolean')
end
def test_value
assert_raise(ArgumentError, "type must be :string, :integer, :float, :date, :time, :boolean") { @c.type = :array }
assert_nothing_raised("type can be changed") { @c.type = :string }
- assert_equal(@c.value, "1.0", "changing type casts the value")
+ assert_equal("1.0", @c.value, "changing type casts the value")
end
def test_col_ref
# TODO: move to axlsx spec
- assert_equal(Axlsx.col_ref(0), "A")
+ assert_equal("A", Axlsx.col_ref(0))
end
def test_cell_type_from_value
- assert_equal(@c.send(:cell_type_from_value, 1.0), :float)
- assert_equal(@c.send(:cell_type_from_value, "1e1"), :float)
- assert_equal(@c.send(:cell_type_from_value, "1e#{Float::MAX_10_EXP}"), :float)
- assert_equal(@c.send(:cell_type_from_value, "1e#{Float::MAX_10_EXP + 1}"), :string)
- assert_equal(@c.send(:cell_type_from_value, "1e-1"), :float)
- assert_equal(@c.send(:cell_type_from_value, "1e#{Float::MIN_10_EXP}"), :float)
- assert_equal(@c.send(:cell_type_from_value, "1e#{Float::MIN_10_EXP - 1}"), :string)
- assert_equal(@c.send(:cell_type_from_value, 1), :integer)
- assert_equal(@c.send(:cell_type_from_value, Date.today), :date)
- assert_equal(@c.send(:cell_type_from_value, Time.now), :time)
- assert_equal(@c.send(:cell_type_from_value, []), :string)
- assert_equal(@c.send(:cell_type_from_value, "d"), :string)
- assert_equal(@c.send(:cell_type_from_value, nil), :string)
- assert_equal(@c.send(:cell_type_from_value, -1), :integer)
- assert_equal(@c.send(:cell_type_from_value, true), :boolean)
- assert_equal(@c.send(:cell_type_from_value, false), :boolean)
- assert_equal(@c.send(:cell_type_from_value, 1.0 / (10**6)), :float)
- assert_equal(@c.send(:cell_type_from_value, Axlsx::RichText.new), :richtext)
+ assert_equal(:float, @c.send(:cell_type_from_value, 1.0))
+ assert_equal(:float, @c.send(:cell_type_from_value, "1e1"))
+ assert_equal(:float, @c.send(:cell_type_from_value, "1e#{Float::MAX_10_EXP}"))
+ assert_equal(:string, @c.send(:cell_type_from_value, "1e#{Float::MAX_10_EXP + 1}"))
+ assert_equal(:float, @c.send(:cell_type_from_value, "1e-1"))
+ assert_equal(:float, @c.send(:cell_type_from_value, "1e#{Float::MIN_10_EXP}"))
+ assert_equal(:string, @c.send(:cell_type_from_value, "1e#{Float::MIN_10_EXP - 1}"))
+ assert_equal(:integer, @c.send(:cell_type_from_value, 1))
+ assert_equal(:date, @c.send(:cell_type_from_value, Date.today))
+ assert_equal(:time, @c.send(:cell_type_from_value, Time.now))
+ assert_equal(:string, @c.send(:cell_type_from_value, []))
+ assert_equal(:string, @c.send(:cell_type_from_value, "d"))
+ assert_equal(:string, @c.send(:cell_type_from_value, nil))
+ assert_equal(:integer, @c.send(:cell_type_from_value, -1))
+ assert_equal(:boolean, @c.send(:cell_type_from_value, true))
+ assert_equal(:boolean, @c.send(:cell_type_from_value, false))
+ assert_equal(:float, @c.send(:cell_type_from_value, 1.0 / (10**6)))
+ assert_equal(:richtext, @c.send(:cell_type_from_value, Axlsx::RichText.new))
assert_equal(:iso_8601, @c.send(:cell_type_from_value, '2008-08-30T01:45:36.123+09:00'))
end
@@ -159,27 +166,35 @@ class TestCell < Test::Unit::TestCase
]
number_strings.each do |number_string|
- assert_equal(@c.send(:cell_type_from_value, mimic_number.new(number_string)), :string)
+ assert_equal(:string, @c.send(:cell_type_from_value, mimic_number.new(number_string)))
end
end
def test_cast_value
@c.type = :string
- assert_equal(@c.send(:cast_value, 1.0), "1.0")
+
+ assert_equal("1.0", @c.send(:cast_value, 1.0))
@c.type = :integer
- assert_equal(@c.send(:cast_value, 1.0), 1)
+
+ assert_equal(1, @c.send(:cast_value, 1.0))
@c.type = :float
- assert_equal(@c.send(:cast_value, "1.0"), 1.0)
+
+ assert_in_delta(@c.send(:cast_value, "1.0"), 1.0)
@c.type = :string
- assert_equal(@c.send(:cast_value, nil), nil)
+
+ assert_nil(@c.send(:cast_value, nil))
@c.type = :richtext
- assert_equal(@c.send(:cast_value, nil), nil)
+
+ assert_nil(@c.send(:cast_value, nil))
@c.type = :float
- assert_equal(@c.send(:cast_value, nil), nil)
+
+ assert_nil(@c.send(:cast_value, nil))
@c.type = :boolean
- assert_equal(@c.send(:cast_value, true), 1)
- assert_equal(@c.send(:cast_value, false), 0)
+
+ assert_equal(1, @c.send(:cast_value, true))
+ assert_equal(0, @c.send(:cast_value, false))
@c.type = :iso_8601
+
assert_equal("2012-10-10T12:24", @c.send(:cast_value, "2012-10-10T12:24"))
end
@@ -193,173 +208,190 @@ class TestCell < Test::Unit::TestCase
time = subtime.now
@c.type = :time
+
assert_equal(time, @c.send(:cast_value, time))
end
def test_color
assert_raise(ArgumentError) { @c.color = -1.1 }
assert_nothing_raised { @c.color = "FF00FF00" }
- assert_equal(@c.color.rgb, "FF00FF00")
+ assert_equal("FF00FF00", @c.color.rgb)
end
def test_scheme
assert_raise(ArgumentError) { @c.scheme = -1.1 }
assert_nothing_raised { @c.scheme = :major }
- assert_equal(@c.scheme, :major)
+ assert_equal(:major, @c.scheme)
end
def test_vertAlign
assert_raise(ArgumentError) { @c.vertAlign = -1.1 }
assert_nothing_raised { @c.vertAlign = :baseline }
- assert_equal(@c.vertAlign, :baseline)
+ assert_equal(:baseline, @c.vertAlign)
end
def test_sz
assert_raise(ArgumentError) { @c.sz = -1.1 }
assert_nothing_raised { @c.sz = 12 }
- assert_equal(@c.sz, 12)
+ assert_equal(12, @c.sz)
end
def test_extend
assert_raise(ArgumentError) { @c.extend = -1.1 }
assert_nothing_raised { @c.extend = false }
- assert_equal(@c.extend, false)
+ refute(@c.extend)
end
def test_condense
assert_raise(ArgumentError) { @c.condense = -1.1 }
assert_nothing_raised { @c.condense = false }
- assert_equal(@c.condense, false)
+ refute(@c.condense)
end
def test_shadow
assert_raise(ArgumentError) { @c.shadow = -1.1 }
assert_nothing_raised { @c.shadow = false }
- assert_equal(@c.shadow, false)
+ refute(@c.shadow)
end
def test_outline
assert_raise(ArgumentError) { @c.outline = -1.1 }
assert_nothing_raised { @c.outline = false }
- assert_equal(@c.outline, false)
+ refute(@c.outline)
end
def test_strike
assert_raise(ArgumentError) { @c.strike = -1.1 }
assert_nothing_raised { @c.strike = false }
- assert_equal(@c.strike, false)
+ refute(@c.strike)
end
def test_u
@c.type = :string
assert_raise(ArgumentError) { @c.u = -1.1 }
assert_nothing_raised { @c.u = :single }
- assert_equal(@c.u, :single)
+ assert_equal(:single, @c.u)
doc = Nokogiri::XML(@c.to_xml_string(1, 1))
+
assert(doc.xpath('//u[@val="single"]'))
end
def test_i
assert_raise(ArgumentError) { @c.i = -1.1 }
assert_nothing_raised { @c.i = false }
- assert_equal(@c.i, false)
+ refute(@c.i)
end
def test_rFont
assert_raise(ArgumentError) { @c.font_name = -1.1 }
assert_nothing_raised { @c.font_name = "Arial" }
- assert_equal(@c.font_name, "Arial")
+ assert_equal("Arial", @c.font_name)
end
def test_charset
assert_raise(ArgumentError) { @c.charset = -1.1 }
assert_nothing_raised { @c.charset = 1 }
- assert_equal(@c.charset, 1)
+ assert_equal(1, @c.charset)
end
def test_family
assert_raise(ArgumentError) { @c.family = -1.1 }
assert_nothing_raised { @c.family = 5 }
- assert_equal(@c.family, 5)
+ assert_equal(5, @c.family)
end
def test_b
assert_raise(ArgumentError) { @c.b = -1.1 }
assert_nothing_raised { @c.b = false }
- assert_equal(@c.b, false)
+ refute(@c.b)
end
def test_merge_with_string
@c.row.add_cell 2
@c.row.add_cell 3
@c.merge "A2"
- assert_equal(@c.row.worksheet.send(:merged_cells).last, "A1:A2")
+
+ assert_equal("A1:A2", @c.row.worksheet.send(:merged_cells).last)
end
def test_merge_with_cell
@c.row.add_cell 2
@c.row.add_cell 3
@c.merge @row.cells.last
- assert_equal(@c.row.worksheet.send(:merged_cells).last, "A1:C1")
+
+ assert_equal("A1:C1", @c.row.worksheet.send(:merged_cells).last)
end
def test_reverse_merge_with_cell
@c.row.add_cell 2
@c.row.add_cell 3
@row.cells.last.merge @c
- assert_equal(@c.row.worksheet.send(:merged_cells).last, "A1:C1")
+
+ assert_equal("A1:C1", @c.row.worksheet.send(:merged_cells).last)
end
def test_ssti
assert_raise(ArgumentError, "ssti must be an unsigned integer!") { @c.send(:ssti=, -1) }
@c.send :ssti=, 1
- assert_equal(@c.ssti, 1)
+
+ assert_equal(1, @c.ssti)
end
def test_plain_string
@c.escape_formulas = false
@c.type = :integer
- assert_equal(@c.plain_string?, false)
+
+ refute_predicate(@c, :plain_string?)
@c.type = :string
@c.value = 'plain string'
- assert_equal(@c.plain_string?, true)
+
+ assert_predicate(@c, :plain_string?)
@c.value = nil
- assert_equal(@c.plain_string?, false)
+
+ refute_predicate(@c, :plain_string?)
@c.value = ''
- assert_equal(@c.plain_string?, false)
+
+ refute_predicate(@c, :plain_string?)
@c.value = '=sum'
- assert_equal(@c.plain_string?, false)
+
+ refute_predicate(@c, :plain_string?)
@c.value = '{=sum}'
- assert_equal(@c.plain_string?, false)
+
+ refute_predicate(@c, :plain_string?)
@c.escape_formulas = true
@c.value = '=sum'
- assert_equal(@c.plain_string?, true)
+
+ assert_predicate(@c, :plain_string?)
@c.value = '{=sum}'
- assert_equal(@c.plain_string?, true)
+
+ assert_predicate(@c, :plain_string?)
@c.value = 'plain string'
@c.font_name = 'Arial'
- assert_equal(@c.plain_string?, false)
+
+ refute_predicate(@c, :plain_string?)
end
def test_to_xml_string
c_xml = Nokogiri::XML(@c.to_xml_string(1, 1))
- assert_equal(c_xml.xpath("/c[@s=1]").size, 1)
+
+ assert_equal(1, c_xml.xpath("/c[@s=1]").size)
end
def test_to_xml_string_nil
@c.value = nil
c_xml = Nokogiri::XML(@c.to_xml_string(1, 1))
- assert_equal(c_xml.xpath("/c[@s=1]").size, 1)
+
+ assert_equal(1, c_xml.xpath("/c[@s=1]").size)
end
def test_to_xml_string_with_run
@@ -371,7 +403,8 @@ class TestCell < Test::Unit::TestCase
@c.font_name = 'arial'
@c.color = 'FF0000'
c_xml = Nokogiri::XML(@c.to_xml_string(1, 1))
- assert(c_xml.xpath("//b").any?)
+
+ assert_predicate(c_xml.xpath("//b"), :any?)
end
def test_to_xml_string_formula
@@ -381,7 +414,8 @@ class TestCell < Test::Unit::TestCase
end
doc = Nokogiri::XML(ws.to_xml_string)
doc.remove_namespaces!
- assert(doc.xpath("//f[text()='IF(2+2=4,4,5)']").any?)
+
+ assert_predicate(doc.xpath("//f[text()='IF(2+2=4,4,5)']"), :any?)
end
def test_to_xml_string_formula_escaped
@@ -391,7 +425,8 @@ class TestCell < Test::Unit::TestCase
end
doc = Nokogiri::XML(ws.to_xml_string)
doc.remove_namespaces!
- assert(doc.xpath("//t[text()='=IF(2+2=4,4,5)']").any?)
+
+ assert_predicate(doc.xpath("//t[text()='=IF(2+2=4,4,5)']"), :any?)
end
def test_to_xml_string_numeric_escaped
@@ -401,8 +436,9 @@ class TestCell < Test::Unit::TestCase
end
doc = Nokogiri::XML(ws.to_xml_string)
doc.remove_namespaces!
- assert(doc.xpath("//t[text()='-1']").any?)
- assert(doc.xpath("//t[text()='+2']").any?)
+
+ assert_predicate(doc.xpath("//t[text()='-1']"), :any?)
+ assert_predicate(doc.xpath("//t[text()='+2']"), :any?)
end
def test_to_xml_string_owasp_prefixes_that_are_no_excel_formulas
@@ -422,11 +458,12 @@ class TestCell < Test::Unit::TestCase
end
doc = Nokogiri::XML(ws.to_xml_string)
doc.remove_namespaces!
- assert(doc.xpath("//t[text()='@1']").any?)
- assert(doc.xpath("//t[text()='%2']").any?)
- assert(doc.xpath("//t[text()='|3']").any?)
- assert(doc.xpath("//t[text()='\nfoo']").any?)
- assert(doc.xpath("//t[text()='\tbar']").any?)
+
+ assert_predicate(doc.xpath("//t[text()='@1']"), :any?)
+ assert_predicate(doc.xpath("//t[text()='%2']"), :any?)
+ assert_predicate(doc.xpath("//t[text()='|3']"), :any?)
+ assert_predicate(doc.xpath("//t[text()='\nfoo']"), :any?)
+ assert_predicate(doc.xpath("//t[text()='\tbar']"), :any?)
end
def test_to_xml_string_owasp_prefixes_that_are_no_excel_formulas_with_escape_formulas
@@ -446,11 +483,12 @@ class TestCell < Test::Unit::TestCase
end
doc = Nokogiri::XML(ws.to_xml_string)
doc.remove_namespaces!
- assert(doc.xpath("//t[text()='@1']").any?)
- assert(doc.xpath("//t[text()='%2']").any?)
- assert(doc.xpath("//t[text()='|3']").any?)
- assert(doc.xpath("//t[text()='\nfoo']").any?)
- assert(doc.xpath("//t[text()='\tbar']").any?)
+
+ assert_predicate(doc.xpath("//t[text()='@1']"), :any?)
+ assert_predicate(doc.xpath("//t[text()='%2']"), :any?)
+ assert_predicate(doc.xpath("//t[text()='|3']"), :any?)
+ assert_predicate(doc.xpath("//t[text()='\nfoo']"), :any?)
+ assert_predicate(doc.xpath("//t[text()='\tbar']"), :any?)
end
def test_to_xml_string_formula_escape_array_parameter
@@ -465,9 +503,9 @@ class TestCell < Test::Unit::TestCase
doc = Nokogiri::XML(ws.to_xml_string)
doc.remove_namespaces!
- assert(doc.xpath("//t[text()='=IF(2+2=4,4,5)']").any?)
- assert(doc.xpath("//f[text()='IF(13+13=4,4,5)']").any?)
- assert(doc.xpath("//t[text()='=IF(99+99=4,4,5)']").any?)
+ assert_predicate(doc.xpath("//t[text()='=IF(2+2=4,4,5)']"), :any?)
+ assert_predicate(doc.xpath("//f[text()='IF(13+13=4,4,5)']"), :any?)
+ assert_predicate(doc.xpath("//t[text()='=IF(99+99=4,4,5)']"), :any?)
end
def test_to_xml_string_array_formula
@@ -477,9 +515,10 @@ class TestCell < Test::Unit::TestCase
end
doc = Nokogiri::XML(ws.to_xml_string)
doc.remove_namespaces!
- assert(doc.xpath("//f[text()='SUM(C2:C11*D2:D11)']").any?)
- assert(doc.xpath("//f[@t='array']").any?)
- assert(doc.xpath("//f[@ref='A1']").any?)
+
+ assert_predicate(doc.xpath("//f[text()='SUM(C2:C11*D2:D11)']"), :any?)
+ assert_predicate(doc.xpath("//f[@t='array']"), :any?)
+ assert_predicate(doc.xpath("//f[@ref='A1']"), :any?)
end
def test_to_xml_string_text_formula
@@ -490,32 +529,36 @@ class TestCell < Test::Unit::TestCase
doc = Nokogiri::XML(ws.to_xml_string)
doc.remove_namespaces!
- assert(doc.xpath("//f[text()='1+1']").empty?)
- assert(doc.xpath("//t[text()='=1+1']").any?)
+ assert_empty(doc.xpath("//f[text()='1+1']"))
+ assert_predicate(doc.xpath("//t[text()='=1+1']"), :any?)
- assert(doc.xpath("//f[text()='1+1']").empty?)
- assert(doc.xpath("//t[text()='-1+1']").any?)
+ assert_empty(doc.xpath("//f[text()='1+1']"))
+ assert_predicate(doc.xpath("//t[text()='-1+1']"), :any?)
end
def test_font_size_with_custom_style_and_no_sz
@c.style = @c.row.worksheet.workbook.styles.add_style :bg_color => 'FF00FF'
sz = @c.send(:font_size)
+
assert_equal(sz, @c.row.worksheet.workbook.styles.fonts.first.sz)
end
def test_font_size_with_bolding
@c.style = @c.row.worksheet.workbook.styles.add_style :b => true
+
assert_equal(@c.row.worksheet.workbook.styles.fonts.first.sz * 1.5, @c.send(:font_size))
end
def test_font_size_with_custom_sz
@c.style = @c.row.worksheet.workbook.styles.add_style :sz => 52
sz = @c.send(:font_size)
- assert_equal(sz, 52)
+
+ assert_equal(52, sz)
end
def test_cell_with_sz
@c.sz = 25
+
assert_equal(25, @c.send(:font_size))
end
@@ -531,6 +574,7 @@ class TestCell < Test::Unit::TestCase
errors.push error
puts error.message
end
- assert(errors.empty?, "error free validation")
+
+ assert_empty(errors, "error free validation")
end
end
diff --git a/test/workbook/worksheet/tc_cfvo.rb b/test/workbook/worksheet/tc_cfvo.rb
index 71ba6bbc..de3aa5d8 100644
--- a/test/workbook/worksheet/tc_cfvo.rb
+++ b/test/workbook/worksheet/tc_cfvo.rb
@@ -7,24 +7,25 @@ class TestCfvo < Test::Unit::TestCase
def test_val
assert_nothing_raised { @cfvo.val = "abc" }
- assert_equal(@cfvo.val, "abc")
+ assert_equal("abc", @cfvo.val)
end
def test_type
assert_raise(ArgumentError) { @cfvo.type = :invalid_type }
assert_nothing_raised { @cfvo.type = :max }
- assert_equal(@cfvo.type, :max)
+ assert_equal(:max, @cfvo.type)
end
def test_gte
assert_raise(ArgumentError) { @cfvo.gte = :bob }
- assert_equal(@cfvo.gte, true)
+ assert(@cfvo.gte)
assert_nothing_raised { @cfvo.gte = false }
- assert_equal(@cfvo.gte, false)
+ refute(@cfvo.gte)
end
def test_to_xml_string
doc = Nokogiri::XML.parse(@cfvo.to_xml_string)
+
assert doc.xpath(".//cfvo[@type='min'][@val=0][@gte=true]")
end
end
diff --git a/test/workbook/worksheet/tc_col.rb b/test/workbook/worksheet/tc_col.rb
index 986c6bb7..f9108b1a 100644
--- a/test/workbook/worksheet/tc_col.rb
+++ b/test/workbook/worksheet/tc_col.rb
@@ -9,6 +9,7 @@ class TestCol < Test::Unit::TestCase
options = { :width => 12, :collapsed => true, :hidden => true, :outline_level => 1, :phonetic => true, :style => 1 }
col = Axlsx::Col.new 0, 0, options
+
options.each { |key, value| assert_equal(col.send(key.to_sym), value) }
end
@@ -19,55 +20,59 @@ class TestCol < Test::Unit::TestCase
end
def test_bestFit
- assert_equal(@col.bestFit, nil)
+ assert_nil(@col.bestFit)
assert_raise(NoMethodError, 'bestFit is read only') { @col.bestFit = 'bob' }
@col.width = 1.999
- assert_equal(@col.bestFit, true, 'bestFit should be true when width has been set')
+
+ assert(@col.bestFit, 'bestFit should be true when width has been set')
end
def test_collapsed
- assert_equal(@col.collapsed, nil)
+ assert_nil(@col.collapsed)
assert_raise(ArgumentError, 'collapsed must be boolean(ish)') { @col.collapsed = 'bob' }
assert_nothing_raised('collapsed must be boolean(ish)') { @col.collapsed = true }
end
def test_customWidth
- assert_equal(@col.customWidth, nil)
+ assert_nil(@col.customWidth)
@col.width = 3
assert_raise(NoMethodError, 'customWidth is read only') { @col.customWidth = 3 }
- assert_equal(@col.customWidth, true, 'customWidth is true when width is set')
+ assert(@col.customWidth, 'customWidth is true when width is set')
end
def test_widthUnderLimit
@col.width = 3
- assert_equal(@col.width, 3, 'width is set to exact value')
+
+ assert_equal(3, @col.width, 'width is set to exact value')
end
def test_widthOverLimit
@col.width = 31337
- assert_equal(@col.width, 255, 'width is set to maximum allowed value')
+
+ assert_equal(255, @col.width, 'width is set to maximum allowed value')
end
def test_widthSetToNil
@col.width = nil
- assert_equal(@col.width, nil, 'width is set to unspecified value')
+
+ assert_nil(@col.width, 'width is set to unspecified value')
end
def test_hidden
- assert_equal(@col.hidden, nil)
+ assert_nil(@col.hidden)
assert_raise(ArgumentError, 'hidden must be boolean(ish)') { @col.hidden = 'bob' }
assert_nothing_raised(ArgumentError, 'hidden must be boolean(ish)') { @col.hidden = true }
end
def test_outlineLevel
- assert_equal(@col.outlineLevel, nil)
+ assert_nil(@col.outlineLevel)
assert_raise(ArgumentError, 'outline level cannot be negative') { @col.outlineLevel = -1 }
assert_raise(ArgumentError, 'outline level cannot be greater than 7') { @col.outlineLevel = 8 }
assert_nothing_raised('can set outlineLevel') { @col.outlineLevel = 1 }
end
def test_phonetic
- assert_equal(@col.phonetic, nil)
+ assert_nil(@col.phonetic)
assert_raise(ArgumentError, 'phonetic must be boolean(ish)') { @col.phonetic = 'bob' }
assert_nothing_raised(ArgumentError, 'phonetic must be boolean(ish)') { @col.phonetic = true }
end
@@ -75,6 +80,7 @@ class TestCol < Test::Unit::TestCase
def test_to_xml_string
@col.width = 100
doc = Nokogiri::XML(@col.to_xml_string)
+
assert_equal(1, doc.xpath("//col [@bestFit='#{@col.best_fit ? 1 : 0}']").size)
assert_equal(1, doc.xpath("//col [@max=#{@col.max}]").size)
assert_equal(1, doc.xpath("//col [@min=#{@col.min}]").size)
@@ -83,9 +89,10 @@ class TestCol < Test::Unit::TestCase
end
def test_style
- assert_equal(@col.style, nil)
+ assert_nil(@col.style)
@col.style = 1
- assert_equal(@col.style, 1)
+
+ assert_equal(1, @col.style)
# TODO: check that the style specified is actually in the styles xfs collection
end
end
diff --git a/test/workbook/worksheet/tc_color_scale.rb b/test/workbook/worksheet/tc_color_scale.rb
index 073cd71f..a4e5816b 100644
--- a/test/workbook/worksheet/tc_color_scale.rb
+++ b/test/workbook/worksheet/tc_color_scale.rb
@@ -7,12 +7,14 @@ class TestColorScale < Test::Unit::TestCase
def test_three_tone
color_scale = Axlsx::ColorScale.three_tone
+
assert_equal 3, color_scale.value_objects.size
assert_equal 3, color_scale.colors.size
end
def test_two_tone
color_scale = Axlsx::ColorScale.two_tone
+
assert_equal 2, color_scale.value_objects.size
assert_equal 2, color_scale.colors.size
end
@@ -20,6 +22,7 @@ class TestColorScale < Test::Unit::TestCase
def test_default_cfvo
first = Axlsx::ColorScale.default_cfvos.first
second = Axlsx::ColorScale.default_cfvos.last
+
assert_equal 'FFFF7128', first[:color]
assert_equal :min, first[:type]
assert_equal 0, first[:val]
@@ -32,6 +35,7 @@ class TestColorScale < Test::Unit::TestCase
def test_partial_default_cfvo_override
first_def = { :type => :percent, :val => "10.0", :color => 'FF00FF00' }
color_scale = Axlsx::ColorScale.new(first_def)
+
assert_equal color_scale.value_objects.first.val, first_def[:val]
assert_equal color_scale.value_objects.first.type, first_def[:type]
assert_equal color_scale.colors.first.rgb, first_def[:color]
@@ -39,20 +43,22 @@ class TestColorScale < Test::Unit::TestCase
def test_add
@color_scale.add :type => :max, :val => 5, :color => "FFDEDEDE"
- assert_equal(@color_scale.value_objects.size, 3)
- assert_equal(@color_scale.colors.size, 3)
+
+ assert_equal(3, @color_scale.value_objects.size)
+ assert_equal(3, @color_scale.colors.size)
end
def test_delete_at
@color_scale.add :type => :max, :val => 5, :color => "FFDEDEDE"
assert_nothing_raised { @color_scale.delete_at 2 }
- assert_equal(@color_scale.value_objects.size, 2)
- assert_equal(@color_scale.colors.size, 2)
+ assert_equal(2, @color_scale.value_objects.size)
+ assert_equal(2, @color_scale.colors.size)
end
def test_to_xml_string
doc = Nokogiri::XML.parse(@color_scale.to_xml_string)
- assert_equal(doc.xpath(".//colorScale//cfvo").size, 2)
- assert_equal(doc.xpath(".//colorScale//color").size, 2)
+
+ assert_equal(2, doc.xpath(".//colorScale//cfvo").size)
+ assert_equal(2, doc.xpath(".//colorScale//color").size)
end
end
diff --git a/test/workbook/worksheet/tc_comment.rb b/test/workbook/worksheet/tc_comment.rb
index 8d5df652..9ada0b4e 100644
--- a/test/workbook/worksheet/tc_comment.rb
+++ b/test/workbook/worksheet/tc_comment.rb
@@ -14,59 +14,63 @@ class TestComment < Test::Unit::TestCase
end
def test_author
- assert(@c1.author == 'author with special char <')
- assert(@c2.author == 'PO')
+ assert_equal('author with special char <', @c1.author)
+ assert_equal('PO', @c2.author)
end
def test_text
- assert(@c1.text == 'text with special char <')
- assert(@c2.text == 'rust bucket')
+ assert_equal('text with special char <', @c1.text)
+ assert_equal('rust bucket', @c2.text)
end
def test_author_index
- assert_equal(@c1.author_index, 1)
- assert_equal(@c2.author_index, 0)
+ assert_equal(1, @c1.author_index)
+ assert_equal(0, @c2.author_index)
end
def test_visible
- assert_equal(false, @c1.visible)
- assert_equal(true, @c2.visible)
+ refute(@c1.visible)
+ assert(@c2.visible)
end
def test_ref
- assert(@c1.ref == 'A1')
- assert(@c2.ref == 'C3')
+ assert_equal('A1', @c1.ref)
+ assert_equal('C3', @c2.ref)
end
def test_vml_shape
pos = Axlsx::name_to_indices(@c1.ref)
+
assert(@c1.vml_shape.is_a?(Axlsx::VmlShape))
- assert(@c1.vml_shape.column == pos[0])
- assert(@c1.vml_shape.row == pos[1])
- assert(@c1.vml_shape.row == pos[1])
+ assert_equal(@c1.vml_shape.column, pos[0])
+ assert_equal(@c1.vml_shape.row, pos[1])
+ assert_equal(@c1.vml_shape.row, pos[1])
assert_equal(pos[0], @c1.vml_shape.left_column)
- assert(@c1.vml_shape.top_row == pos[1])
+ assert_equal(@c1.vml_shape.top_row, pos[1])
assert_equal(pos[0] + 2, @c1.vml_shape.right_column)
- assert(@c1.vml_shape.bottom_row == pos[1] + 4)
+ assert_equal(@c1.vml_shape.bottom_row, pos[1] + 4)
end
def test_to_xml_string
doc = Nokogiri::XML(@c1.to_xml_string)
- assert_equal(doc.xpath("//comment[@ref='#{@c1.ref}']").size, 1)
- assert_equal(doc.xpath("//comment[@authorId='#{@c1.author_index}']").size, 1)
- assert_equal(doc.xpath("//t[text()='#{@c1.author}:\n']").size, 1)
- assert_equal(doc.xpath("//t[text()='#{@c1.text}']").size, 1)
+
+ assert_equal(1, doc.xpath("//comment[@ref='#{@c1.ref}']").size)
+ assert_equal(1, doc.xpath("//comment[@authorId='#{@c1.author_index}']").size)
+ assert_equal(1, doc.xpath("//t[text()='#{@c1.author}:\n']").size)
+ assert_equal(1, doc.xpath("//t[text()='#{@c1.text}']").size)
end
def test_comment_text_contain_author_and_text
comment = @ws.add_comment :ref => 'C4', :text => 'some text', :author => 'Bob'
doc = Nokogiri::XML(comment.to_xml_string)
+
assert_equal("Bob:\nsome text", doc.xpath("//comment/text").text)
end
def test_comment_text_does_not_contain_stray_colon_if_author_blank
comment = @ws.add_comment :ref => 'C5', :text => 'some text', :author => ''
doc = Nokogiri::XML(comment.to_xml_string)
+
assert_equal("some text", doc.xpath("//comment/text").text)
end
end
diff --git a/test/workbook/worksheet/tc_comments.rb b/test/workbook/worksheet/tc_comments.rb
index cb2e3741..55ba744f 100644
--- a/test/workbook/worksheet/tc_comments.rb
+++ b/test/workbook/worksheet/tc_comments.rb
@@ -15,21 +15,23 @@ class TestComments < Test::Unit::TestCase
end
def test_add_comment
- assert_equal(@ws.comments.size, 2)
+ assert_equal(2, @ws.comments.size)
assert_raise(ArgumentError) { @ws.comments.add_comment }
assert_raise(ArgumentError) { @ws.comments.add_comment(:text => 'Yes We Can', :ref => 'A1') }
assert_raise(ArgumentError) { @ws.comments.add_comment(:author => 'bob', :ref => 'A1') }
assert_raise(ArgumentError) { @ws.comments.add_comment(:author => 'bob', :text => 'Yes We Can') }
assert_nothing_raised { @ws.comments.add_comment(:author => 'bob', :text => 'Yes We Can', :ref => 'A1') }
- assert_equal(@ws.comments.size, 3)
+ assert_equal(3, @ws.comments.size)
end
def test_authors
assert_equal(@ws.comments.authors.size, @ws.comments.size)
@ws.add_comment(:text => 'Yes We Can!', :author => 'bob', :ref => 'F1')
- assert_equal(@ws.comments.authors.size, 3)
+
+ assert_equal(3, @ws.comments.authors.size)
@ws.add_comment(:text => 'Yes We Can!', :author => 'bob', :ref => 'F1')
- assert_equal(@ws.comments.authors.size, 3, 'only unique authors are returned')
+
+ assert_equal(3, @ws.comments.authors.size, 'only unique authors are returned')
end
def test_pn
@@ -47,6 +49,7 @@ class TestComments < Test::Unit::TestCase
schema.validate(doc).each do |error|
errors << error
end
+
assert_equal(0, errors.length)
# TODO: figure out why these xpath expressions dont work!
diff --git a/test/workbook/worksheet/tc_conditional_formatting.rb b/test/workbook/worksheet/tc_conditional_formatting.rb
index e6fc6324..1ee26ca0 100644
--- a/test/workbook/worksheet/tc_conditional_formatting.rb
+++ b/test/workbook/worksheet/tc_conditional_formatting.rb
@@ -11,6 +11,7 @@ class TestConditionalFormatting < Test::Unit::TestCase
def test_initialize_with_options
optioned = Axlsx::ConditionalFormatting.new(:sqref => "AA1:AB100", :rules => [1, 2])
+
assert_equal("AA1:AB100", optioned.sqref)
assert_equal([1, 2], optioned.rules)
end
@@ -37,24 +38,28 @@ class TestConditionalFormatting < Test::Unit::TestCase
assert(cfr.color_scale.is_a?(Axlsx::ColorScale))
cfs = @ws.add_conditional_formatting("B2:B2", [cfr])
doc = Nokogiri::XML.parse(cfs.last.to_xml_string)
+
assert_equal(1, doc.xpath(".//conditionalFormatting[@sqref='B2:B2']//cfRule[@type='containsText'][@dxfId=0][@priority=1]").size)
assert doc.xpath(".//conditionalFormatting//cfRule[@type='containsText'][@dxfId=0][@priority=1]//formula='NOT(ISERROR(SEARCH(\"FALSE\",AB1)))'")
cfs.last.rules.last.type = :colorScale
doc = Nokogiri::XML.parse(cfs.last.to_xml_string)
- assert_equal(doc.xpath(".//conditionalFormatting//cfRule//colorScale//cfvo").size, 2)
- assert_equal(doc.xpath(".//conditionalFormatting//cfRule//colorScale//color").size, 2)
+
+ assert_equal(2, doc.xpath(".//conditionalFormatting//cfRule//colorScale//cfvo").size)
+ assert_equal(2, doc.xpath(".//conditionalFormatting//cfRule//colorScale//color").size)
cfs.last.rules.last.type = :dataBar
doc = Nokogiri::XML.parse(cfs.last.to_xml_string)
- assert_equal(doc.xpath(".//conditionalFormatting//cfRule//dataBar").size, 1)
- assert_equal(doc.xpath(".//conditionalFormatting//cfRule//dataBar//cfvo").size, 2)
- assert_equal(doc.xpath(".//conditionalFormatting//cfRule//dataBar//color[@rgb='FFFF0000']").size, 1)
+
+ assert_equal(1, doc.xpath(".//conditionalFormatting//cfRule//dataBar").size)
+ assert_equal(2, doc.xpath(".//conditionalFormatting//cfRule//dataBar//cfvo").size)
+ assert_equal(1, doc.xpath(".//conditionalFormatting//cfRule//dataBar//color[@rgb='FFFF0000']").size)
cfs.last.rules.last.type = :iconSet
doc = Nokogiri::XML.parse(cfs.last.to_xml_string)
- assert_equal(doc.xpath(".//conditionalFormatting//cfRule//iconSet//cfvo").size, 3)
- assert_equal(doc.xpath(".//conditionalFormatting//cfRule//iconSet[@iconSet='5Rating']").size, 1)
+
+ assert_equal(3, doc.xpath(".//conditionalFormatting//cfRule//iconSet//cfvo").size)
+ assert_equal(1, doc.xpath(".//conditionalFormatting//cfRule//iconSet[@iconSet='5Rating']").size)
end
def test_add_as_hash
@@ -75,28 +80,33 @@ class TestConditionalFormatting < Test::Unit::TestCase
:data_bar => data_bar,
:icon_set => icon_set }])
doc = Nokogiri::XML.parse(cfs.last.to_xml_string)
+
assert_equal(1, doc.xpath(".//conditionalFormatting[@sqref='B2:B2']//cfRule[@type='containsText'][@dxfId=0][@priority=1]").size)
assert doc.xpath(".//conditionalFormatting//cfRule[@type='containsText'][@dxfId=0][@priority=1]//formula='NOT(ISERROR(SEARCH(\"FALSE\",AB1)))'")
cfs.last.rules.last.type = :colorScale
doc = Nokogiri::XML.parse(cfs.last.to_xml_string)
- assert_equal(doc.xpath(".//conditionalFormatting//cfRule//colorScale//cfvo").size, 2)
- assert_equal(doc.xpath(".//conditionalFormatting//cfRule//colorScale//color").size, 2)
+
+ assert_equal(2, doc.xpath(".//conditionalFormatting//cfRule//colorScale//cfvo").size)
+ assert_equal(2, doc.xpath(".//conditionalFormatting//cfRule//colorScale//color").size)
cfs.last.rules.last.type = :dataBar
doc = Nokogiri::XML.parse(cfs.last.to_xml_string)
- assert_equal(doc.xpath(".//conditionalFormatting//cfRule//dataBar").size, 1)
- assert_equal(doc.xpath(".//conditionalFormatting//cfRule//dataBar//cfvo").size, 2)
- assert_equal(doc.xpath(".//conditionalFormatting//cfRule//dataBar//color[@rgb='FFFF0000']").size, 1)
+
+ assert_equal(1, doc.xpath(".//conditionalFormatting//cfRule//dataBar").size)
+ assert_equal(2, doc.xpath(".//conditionalFormatting//cfRule//dataBar//cfvo").size)
+ assert_equal(1, doc.xpath(".//conditionalFormatting//cfRule//dataBar//color[@rgb='FFFF0000']").size)
cfs.last.rules.last.type = :iconSet
doc = Nokogiri::XML.parse(cfs.last.to_xml_string)
- assert_equal(doc.xpath(".//conditionalFormatting//cfRule//iconSet//cfvo").size, 3)
- assert_equal(doc.xpath(".//conditionalFormatting//cfRule//iconSet[@iconSet='5Rating']").size, 1)
+
+ assert_equal(3, doc.xpath(".//conditionalFormatting//cfRule//iconSet//cfvo").size)
+ assert_equal(1, doc.xpath(".//conditionalFormatting//cfRule//iconSet[@iconSet='5Rating']").size)
end
def test_single_rule
doc = Nokogiri::XML.parse(@cf.to_xml_string)
+
assert_equal(1, doc.xpath(".//conditionalFormatting//cfRule[@type='cellIs'][@dxfId=0][@priority=1][@operator='greaterThan']").size)
assert doc.xpath(".//conditionalFormatting//cfRule[@type='cellIs'][@dxfId=0][@priority=1][@operator='greaterThan']//formula='0.5'")
end
@@ -108,12 +118,14 @@ class TestConditionalFormatting < Test::Unit::TestCase
:percent => false, :rank => 0, :stdDev => 1, :stopIfTrue => true, :timePeriod => :today,
:formula => "0.0" })
doc = Nokogiri::XML.parse(cf.to_xml_string)
+
assert_equal(1, doc.xpath(".//conditionalFormatting//cfRule[@type='cellIs'][@aboveAverage=0][@bottom=0][@dxfId=0][@equalAverage=0][@priority=2][@operator='lessThan'][@text=''][@percent=0][@rank=0][@stdDev=1][@stopIfTrue=1][@timePeriod='today']").size)
assert doc.xpath(".//conditionalFormatting//cfRule[@type='cellIs'][@aboveAverage=0][@bottom=0][@dxfId=0][@equalAverage=0][@priority=2][@operator='lessThan'][@text=''][@percent=0][@rank=0][@stdDev=1][@stopIfTrue=1][@timePeriod='today']//formula=0.0")
end
def test_to_xml
doc = Nokogiri::XML.parse(@ws.to_xml_string)
+
assert_equal(1, doc.xpath("//xmlns:worksheet/xmlns:conditionalFormatting//xmlns:cfRule[@type='cellIs'][@dxfId=0][@priority=1][@operator='greaterThan']").size)
assert doc.xpath("//xmlns:worksheet/xmlns:conditionalFormatting//xmlns:cfRule[@type='cellIs'][@dxfId=0][@priority=1][@operator='greaterThan']//xmlns:formula='0.5'")
end
@@ -121,6 +133,7 @@ class TestConditionalFormatting < Test::Unit::TestCase
def test_multiple_formats
@ws.add_conditional_formatting "B3:B3", { :type => :cellIs, :dxfId => 0, :priority => 1, :operator => :greaterThan, :formula => "1" }
doc = Nokogiri::XML.parse(@ws.to_xml_string)
+
assert doc.xpath("//xmlns:worksheet/xmlns:conditionalFormatting//xmlns:cfRule[@type='cellIs'][@dxfId=0][@priority=1][@operator='greaterThan']//xmlns:formula='1'")
assert doc.xpath("//xmlns:worksheet/xmlns:conditionalFormatting//xmlns:cfRule[@type='cellIs'][@dxfId=0][@priority=1][@operator='greaterThan']//xmlns:formula='0.5'")
end
@@ -128,6 +141,7 @@ class TestConditionalFormatting < Test::Unit::TestCase
def test_multiple_formulas
@ws.add_conditional_formatting "B3:B3", { :type => :cellIs, :dxfId => 0, :priority => 1, :operator => :between, :formula => ["1 <> 2", "5"] }
doc = Nokogiri::XML.parse(@ws.to_xml_string)
+
assert doc.xpath("//xmlns:worksheet/xmlns:conditionalFormatting//xmlns:cfRule[@type='cellIs'][@dxfId=0][@priority=1][@operator='between']//xmlns:formula='1 <> 2'")
assert doc.xpath("//xmlns:worksheet/xmlns:conditionalFormatting//xmlns:cfRule[@type='cellIs'][@dxfId=0][@priority=1][@operator='between']//xmlns:formula='5'")
end
@@ -135,84 +149,84 @@ class TestConditionalFormatting < Test::Unit::TestCase
def test_sqref
assert_raise(ArgumentError) { @cf.sqref = 10 }
assert_nothing_raised { @cf.sqref = "A1:A1" }
- assert_equal(@cf.sqref, "A1:A1")
+ assert_equal("A1:A1", @cf.sqref)
end
def test_type
assert_raise(ArgumentError) { @cfr.type = "illegal" }
assert_nothing_raised { @cfr.type = :containsBlanks }
- assert_equal(@cfr.type, :containsBlanks)
+ assert_equal(:containsBlanks, @cfr.type)
end
def test_above_average
assert_raise(ArgumentError) { @cfr.aboveAverage = "illegal" }
assert_nothing_raised { @cfr.aboveAverage = true }
- assert_equal(@cfr.aboveAverage, true)
+ assert(@cfr.aboveAverage)
end
def test_equal_average
assert_raise(ArgumentError) { @cfr.equalAverage = "illegal" }
assert_nothing_raised { @cfr.equalAverage = true }
- assert_equal(@cfr.equalAverage, true)
+ assert(@cfr.equalAverage)
end
def test_bottom
assert_raise(ArgumentError) { @cfr.bottom = "illegal" }
assert_nothing_raised { @cfr.bottom = true }
- assert_equal(@cfr.bottom, true)
+ assert(@cfr.bottom)
end
def test_operator
assert_raise(ArgumentError) { @cfr.operator = "cellIs" }
assert_nothing_raised { @cfr.operator = :notBetween }
- assert_equal(@cfr.operator, :notBetween)
+ assert_equal(:notBetween, @cfr.operator)
end
def test_dxf_id
assert_raise(ArgumentError) { @cfr.dxfId = "illegal" }
assert_nothing_raised { @cfr.dxfId = 1 }
- assert_equal(@cfr.dxfId, 1)
+ assert_equal(1, @cfr.dxfId)
end
def test_priority
assert_raise(ArgumentError) { @cfr.priority = -1.0 }
assert_nothing_raised { @cfr.priority = 1 }
- assert_equal(@cfr.priority, 1)
+ assert_equal(1, @cfr.priority)
end
def test_text
assert_raise(ArgumentError) { @cfr.text = 1.0 }
assert_nothing_raised { @cfr.text = "testing" }
- assert_equal(@cfr.text, "testing")
+ assert_equal("testing", @cfr.text)
end
def test_percent
assert_raise(ArgumentError) { @cfr.percent = "10%" } # WRONG!
assert_nothing_raised { @cfr.percent = true }
- assert_equal(@cfr.percent, true)
+ assert(@cfr.percent)
end
def test_rank
assert_raise(ArgumentError) { @cfr.rank = -1 }
assert_nothing_raised { @cfr.rank = 1 }
- assert_equal(@cfr.rank, 1)
+ assert_equal(1, @cfr.rank)
end
def test_std_dev
assert_raise(ArgumentError) { @cfr.stdDev = -1 }
assert_nothing_raised { @cfr.stdDev = 1 }
- assert_equal(@cfr.stdDev, 1)
+ assert_equal(1, @cfr.stdDev)
end
def test_stop_if_true
assert_raise(ArgumentError) { @cfr.stopIfTrue = "illegal" }
assert_nothing_raised { @cfr.stopIfTrue = false }
- assert_equal(@cfr.stopIfTrue, false)
+ refute(@cfr.stopIfTrue)
end
def test_time_period
assert_raise(ArgumentError) { @cfr.timePeriod = "illegal" }
assert_nothing_raised { @cfr.timePeriod = :today }
- assert_equal(@cfr.timePeriod, :today)
+ assert_equal(:today, @cfr.timePeriod)
end
end
diff --git a/test/workbook/worksheet/tc_data_bar.rb b/test/workbook/worksheet/tc_data_bar.rb
index aa39c48b..ccb31d40 100644
--- a/test/workbook/worksheet/tc_data_bar.rb
+++ b/test/workbook/worksheet/tc_data_bar.rb
@@ -6,13 +6,14 @@ class TestDataBar < Test::Unit::TestCase
end
def test_defaults
- assert_equal @data_bar.minLength, 10
- assert_equal @data_bar.maxLength, 90
- assert_equal @data_bar.showValue, true
+ assert_equal(10, @data_bar.minLength)
+ assert_equal(90, @data_bar.maxLength)
+ assert(@data_bar.showValue)
end
def test_override_default_cfvos
data_bar = Axlsx::DataBar.new({ :color => 'FF00FF00' }, { :type => :min, :val => "20" })
+
assert_equal("20", data_bar.value_objects.first.val)
assert_equal("0", data_bar.value_objects.last.val)
end
@@ -20,25 +21,26 @@ class TestDataBar < Test::Unit::TestCase
def test_minLength
assert_raise(ArgumentError) { @data_bar.minLength = :invalid_type }
assert_nothing_raised { @data_bar.minLength = 0 }
- assert_equal(@data_bar.minLength, 0)
+ assert_equal(0, @data_bar.minLength)
end
def test_maxLength
assert_raise(ArgumentError) { @data_bar.maxLength = :invalid_type }
assert_nothing_raised { @data_bar.maxLength = 0 }
- assert_equal(@data_bar.maxLength, 0)
+ assert_equal(0, @data_bar.maxLength)
end
def test_showValue
assert_raise(ArgumentError) { @data_bar.showValue = :invalid_type }
assert_nothing_raised { @data_bar.showValue = false }
- assert_equal(@data_bar.showValue, false)
+ refute(@data_bar.showValue)
end
def test_to_xml_string
doc = Nokogiri::XML.parse(@data_bar.to_xml_string)
- assert_equal(doc.xpath(".//dataBar[@minLength=10][@maxLength=90][@showValue=1]").size, 1)
- assert_equal(doc.xpath(".//dataBar//cfvo").size, 2)
- assert_equal(doc.xpath(".//dataBar//color").size, 1)
+
+ assert_equal(1, doc.xpath(".//dataBar[@minLength=10][@maxLength=90][@showValue=1]").size)
+ assert_equal(2, doc.xpath(".//dataBar//cfvo").size)
+ assert_equal(1, doc.xpath(".//dataBar//color").size)
end
end
diff --git a/test/workbook/worksheet/tc_data_validation.rb b/test/workbook/worksheet/tc_data_validation.rb
index aac2019d..aa4efd55 100644
--- a/test/workbook/worksheet/tc_data_validation.rb
+++ b/test/workbook/worksheet/tc_data_validation.rb
@@ -28,7 +28,7 @@ class TestDataValidation < Test::Unit::TestCase
end
@nil_options.each do |key, value|
- assert_equal(nil, dv.send(key.to_sym), "initialized default #{key} should be nil")
+ assert_nil(dv.send(key.to_sym), "initialized default #{key} should be nil")
assert_equal(value, @dv.send(key.to_sym), "initialized options #{key} should be #{value}")
end
@@ -67,62 +67,62 @@ class TestDataValidation < Test::Unit::TestCase
def test_formula1
assert_raise(ArgumentError) { @dv.formula1 = 10 }
assert_nothing_raised { @dv.formula1 = "=SUM(A1:A1)" }
- assert_equal(@dv.formula1, "=SUM(A1:A1)")
+ assert_equal("=SUM(A1:A1)", @dv.formula1)
end
def test_formula2
assert_raise(ArgumentError) { @dv.formula2 = 10 }
assert_nothing_raised { @dv.formula2 = "=SUM(A1:A1)" }
- assert_equal(@dv.formula2, "=SUM(A1:A1)")
+ assert_equal("=SUM(A1:A1)", @dv.formula2)
end
def test_allowBlank
assert_raise(ArgumentError) { @dv.allowBlank = "foo´" }
assert_nothing_raised { @dv.allowBlank = false }
- assert_equal(@dv.allowBlank, false)
+ refute(@dv.allowBlank)
end
def test_error
assert_raise(ArgumentError) { @dv.error = :symbol }
assert_nothing_raised { @dv.error = "This is a error message" }
- assert_equal(@dv.error, "This is a error message")
+ assert_equal("This is a error message", @dv.error)
end
def test_errorStyle
assert_raise(ArgumentError) { @dv.errorStyle = "foo" }
assert_nothing_raised { @dv.errorStyle = :information }
- assert_equal(@dv.errorStyle, :information)
+ assert_equal(:information, @dv.errorStyle)
end
def test_errorTitle
assert_raise(ArgumentError) { @dv.errorTitle = :symbol }
assert_nothing_raised { @dv.errorTitle = "This is the error title" }
- assert_equal(@dv.errorTitle, "This is the error title")
+ assert_equal("This is the error title", @dv.errorTitle)
end
def test_operator
assert_raise(ArgumentError) { @dv.operator = "foo" }
assert_nothing_raised { @dv.operator = :greaterThan }
- assert_equal(@dv.operator, :greaterThan)
+ assert_equal(:greaterThan, @dv.operator)
end
def test_prompt
assert_raise(ArgumentError) { @dv.prompt = :symbol }
assert_nothing_raised { @dv.prompt = "This is a prompt message" }
- assert_equal(@dv.prompt, "This is a prompt message")
+ assert_equal("This is a prompt message", @dv.prompt)
end
def test_promptTitle
assert_raise(ArgumentError) { @dv.promptTitle = :symbol }
assert_nothing_raised { @dv.promptTitle = "This is the prompt title" }
- assert_equal(@dv.promptTitle, "This is the prompt title")
+ assert_equal("This is the prompt title", @dv.promptTitle)
end
def test_showDropDown
warnings = capture_warnings do
assert_raise(ArgumentError) { @dv.showDropDown = "foo´" }
assert_nothing_raised { @dv.showDropDown = false }
- assert_equal(@dv.showDropDown, false)
+ refute(@dv.showDropDown)
end
assert_equal 2, warnings.size
@@ -132,33 +132,33 @@ class TestDataValidation < Test::Unit::TestCase
def test_hideDropDown
assert_raise(ArgumentError) { @dv.hideDropDown = "foo´" }
assert_nothing_raised { @dv.hideDropDown = false }
- assert_equal(@dv.hideDropDown, false)
+ refute(@dv.hideDropDown)
# As hideDropdown is just an alias for showDropDown, we should test the original value too
- assert_equal(@dv.showDropDown, false)
+ refute(@dv.showDropDown)
end
def test_showErrorMessage
assert_raise(ArgumentError) { @dv.showErrorMessage = "foo´" }
assert_nothing_raised { @dv.showErrorMessage = false }
- assert_equal(@dv.showErrorMessage, false)
+ refute(@dv.showErrorMessage)
end
def test_showInputMessage
assert_raise(ArgumentError) { @dv.showInputMessage = "foo´" }
assert_nothing_raised { @dv.showInputMessage = false }
- assert_equal(@dv.showInputMessage, false)
+ refute(@dv.showInputMessage)
end
def test_sqref
assert_raise(ArgumentError) { @dv.sqref = 10 }
assert_nothing_raised { @dv.sqref = "A1:A1" }
- assert_equal(@dv.sqref, "A1:A1")
+ assert_equal("A1:A1", @dv.sqref)
end
def test_type
assert_raise(ArgumentError) { @dv.type = "foo" }
assert_nothing_raised { @dv.type = :list }
- assert_equal(@dv.type, :list)
+ assert_equal(:list, @dv.type)
end
def test_whole_decimal_data_time_textLength_to_xml
@@ -273,6 +273,7 @@ class TestDataValidation < Test::Unit::TestCase
def test_empty_attributes
v = Axlsx::DataValidation.new
- assert_equal(nil, v.send(:get_valid_attributes))
+
+ assert_nil(v.send(:get_valid_attributes))
end
end
diff --git a/test/workbook/worksheet/tc_date_time_converter.rb b/test/workbook/worksheet/tc_date_time_converter.rb
index 891fa80f..4bf0e930 100644
--- a/test/workbook/worksheet/tc_date_time_converter.rb
+++ b/test/workbook/worksheet/tc_date_time_converter.rb
@@ -32,6 +32,7 @@ class TestDateTimeConverter < Test::Unit::TestCase
end
tests.each do |date_string, expected|
serial = Axlsx::DateTimeConverter::date_to_serial Date.parse(date_string)
+
assert_equal expected, serial
end
end
@@ -56,6 +57,7 @@ class TestDateTimeConverter < Test::Unit::TestCase
end
tests.each do |date_string, expected|
serial = Axlsx::DateTimeConverter::date_to_serial Date.parse(date_string)
+
assert_equal expected, serial
end
end
@@ -80,6 +82,7 @@ class TestDateTimeConverter < Test::Unit::TestCase
end
tests.each do |time_string, expected|
serial = Axlsx::DateTimeConverter::time_to_serial Time.parse(time_string)
+
assert_in_delta expected, serial, @margin_of_error
end
end
@@ -105,6 +108,7 @@ class TestDateTimeConverter < Test::Unit::TestCase
end
tests.each do |time_string, expected|
serial = Axlsx::DateTimeConverter::time_to_serial Time.parse(time_string)
+
assert_in_delta expected, serial, @margin_of_error
end
end
@@ -116,6 +120,7 @@ class TestDateTimeConverter < Test::Unit::TestCase
assert_equal local, utc
assert_equal Axlsx::DateTimeConverter::time_to_serial(local) - (local.utc_offset.to_f / 86400), Axlsx::DateTimeConverter::time_to_serial(utc)
Axlsx::Workbook.date1904 = true
+
assert_equal Axlsx::DateTimeConverter::time_to_serial(local) - (local.utc_offset.to_f / 86400), Axlsx::DateTimeConverter::time_to_serial(utc)
end
end
diff --git a/test/workbook/worksheet/tc_header_footer.rb b/test/workbook/worksheet/tc_header_footer.rb
index 1ecea096..45a90825 100644
--- a/test/workbook/worksheet/tc_header_footer.rb
+++ b/test/workbook/worksheet/tc_header_footer.rb
@@ -8,17 +8,17 @@ class TestHeaderFooter < Test::Unit::TestCase
end
def test_initialize
- assert_equal(nil, @hf.odd_header)
- assert_equal(nil, @hf.odd_footer)
+ assert_nil(@hf.odd_header)
+ assert_nil(@hf.odd_footer)
- assert_equal(nil, @hf.even_header)
- assert_equal(nil, @hf.even_footer)
+ assert_nil(@hf.even_header)
+ assert_nil(@hf.even_footer)
- assert_equal(nil, @hf.first_header)
- assert_equal(nil, @hf.first_footer)
+ assert_nil(@hf.first_header)
+ assert_nil(@hf.first_footer)
- assert_equal(nil, @hf.different_first)
- assert_equal(nil, @hf.different_odd_even)
+ assert_nil(@hf.different_first)
+ assert_nil(@hf.different_odd_even)
end
def test_initialize_with_options
@@ -46,8 +46,8 @@ class TestHeaderFooter < Test::Unit::TestCase
assert_equal('fh', optioned.first_header)
assert_equal('ff', optioned.first_footer)
- assert_equal(true, optioned.different_first)
- assert_equal(true, optioned.different_odd_even)
+ assert(optioned.different_first)
+ assert(optioned.different_odd_even)
end
def test_string_attributes
@@ -88,8 +88,8 @@ class TestHeaderFooter < Test::Unit::TestCase
assert_equal('fh', @hf.first_header)
assert_equal('ff', @hf.first_footer)
- assert_equal(true, @hf.different_first)
- assert_equal(true, @hf.different_odd_even)
+ assert(@hf.different_first)
+ assert(@hf.different_odd_even)
end
def test_to_xml_all_values
@@ -108,6 +108,7 @@ class TestHeaderFooter < Test::Unit::TestCase
)
doc = Nokogiri::XML.parse(@hf.to_xml_string)
+
assert_equal(1, doc.xpath(".//headerFooter[@differentFirst=1][@differentOddEven=1]").size)
assert_equal(1, doc.xpath(".//headerFooter/oddHeader").size)
@@ -133,6 +134,7 @@ class TestHeaderFooter < Test::Unit::TestCase
)
doc = Nokogiri::XML.parse(@hf.to_xml_string)
+
assert_equal(1, doc.xpath(".//headerFooter[@differentOddEven=0]").size)
assert_equal(0, doc.xpath(".//headerFooter[@differentFirst]").size)
diff --git a/test/workbook/worksheet/tc_icon_set.rb b/test/workbook/worksheet/tc_icon_set.rb
index 3a4079bf..3a52cb98 100644
--- a/test/workbook/worksheet/tc_icon_set.rb
+++ b/test/workbook/worksheet/tc_icon_set.rb
@@ -6,39 +6,40 @@ class TestIconSet < Test::Unit::TestCase
end
def test_defaults
- assert_equal @icon_set.iconSet, "3TrafficLights1"
- assert_equal @icon_set.percent, true
- assert_equal @icon_set.reverse, false
- assert_equal @icon_set.showValue, true
+ assert_equal("3TrafficLights1", @icon_set.iconSet)
+ assert(@icon_set.percent)
+ refute(@icon_set.reverse)
+ assert(@icon_set.showValue)
end
def test_icon_set
assert_raise(ArgumentError) { @icon_set.iconSet = "invalid_value" }
assert_nothing_raised { @icon_set.iconSet = "5Rating" }
- assert_equal(@icon_set.iconSet, "5Rating")
+ assert_equal("5Rating", @icon_set.iconSet)
end
def test_percent
assert_raise(ArgumentError) { @icon_set.percent = :invalid_type }
assert_nothing_raised { @icon_set.percent = false }
- assert_equal(@icon_set.percent, false)
+ refute(@icon_set.percent)
end
def test_showValue
assert_raise(ArgumentError) { @icon_set.showValue = :invalid_type }
assert_nothing_raised { @icon_set.showValue = false }
- assert_equal(@icon_set.showValue, false)
+ refute(@icon_set.showValue)
end
def test_reverse
assert_raise(ArgumentError) { @icon_set.reverse = :invalid_type }
assert_nothing_raised { @icon_set.reverse = false }
- assert_equal(@icon_set.reverse, false)
+ refute(@icon_set.reverse)
end
def test_to_xml_string
doc = Nokogiri::XML.parse(@icon_set.to_xml_string)
- assert_equal(doc.xpath(".//iconSet[@iconSet='3TrafficLights1'][@percent=1][@reverse=0][@showValue=1]").size, 1)
- assert_equal(doc.xpath(".//iconSet//cfvo").size, 3)
+
+ assert_equal(1, doc.xpath(".//iconSet[@iconSet='3TrafficLights1'][@percent=1][@reverse=0][@showValue=1]").size)
+ assert_equal(3, doc.xpath(".//iconSet//cfvo").size)
end
end
diff --git a/test/workbook/worksheet/tc_outline_pr.rb b/test/workbook/worksheet/tc_outline_pr.rb
index d2906a61..c6b086fe 100644
--- a/test/workbook/worksheet/tc_outline_pr.rb
+++ b/test/workbook/worksheet/tc_outline_pr.rb
@@ -6,14 +6,14 @@ class TestOutlinePr < Test::Unit::TestCase
end
def test_summary_below
- assert_equal false, @outline_pr.summary_below
+ refute @outline_pr.summary_below
end
def test_summary_right
- assert_equal true, @outline_pr.summary_right
+ assert @outline_pr.summary_right
end
def test_apply_styles
- assert_equal false, @outline_pr.apply_styles
+ refute @outline_pr.apply_styles
end
end
diff --git a/test/workbook/worksheet/tc_page_margins.rb b/test/workbook/worksheet/tc_page_margins.rb
index ba532e7f..26aa4850 100644
--- a/test/workbook/worksheet/tc_page_margins.rb
+++ b/test/workbook/worksheet/tc_page_margins.rb
@@ -18,28 +18,31 @@ class TestPageMargins < Test::Unit::TestCase
def test_initialize_with_options
optioned = Axlsx::PageMargins.new(:left => 2, :right => 3, :top => 2, :bottom => 1, :header => 0.1, :footer => 0.1)
+
assert_equal(2, optioned.left)
assert_equal(3, optioned.right)
assert_equal(2, optioned.top)
assert_equal(1, optioned.bottom)
- assert_equal(0.1, optioned.header)
- assert_equal(0.1, optioned.footer)
+ assert_in_delta(0.1, optioned.header)
+ assert_in_delta(0.1, optioned.footer)
end
def test_set_all_values
@pm.set(:left => 1.1, :right => 1.2, :top => 1.3, :bottom => 1.4, :header => 0.8, :footer => 0.9)
- assert_equal(1.1, @pm.left)
- assert_equal(1.2, @pm.right)
- assert_equal(1.3, @pm.top)
- assert_equal(1.4, @pm.bottom)
- assert_equal(0.8, @pm.header)
- assert_equal(0.9, @pm.footer)
+
+ assert_in_delta(1.1, @pm.left)
+ assert_in_delta(1.2, @pm.right)
+ assert_in_delta(1.3, @pm.top)
+ assert_in_delta(1.4, @pm.bottom)
+ assert_in_delta(0.8, @pm.header)
+ assert_in_delta(0.9, @pm.footer)
end
def test_set_some_values
@pm.set(:left => 1.1, :right => 1.2)
- assert_equal(1.1, @pm.left)
- assert_equal(1.2, @pm.right)
+
+ assert_in_delta(1.1, @pm.left)
+ assert_in_delta(1.2, @pm.right)
assert_equal(Axlsx::PageMargins::DEFAULT_TOP_BOTTOM, @pm.top)
assert_equal(Axlsx::PageMargins::DEFAULT_TOP_BOTTOM, @pm.bottom)
assert_equal(Axlsx::PageMargins::DEFAULT_HEADER_FOOTER, @pm.header)
@@ -54,42 +57,43 @@ class TestPageMargins < Test::Unit::TestCase
@pm.header = 0.8
@pm.footer = 0.9
doc = Nokogiri::XML.parse(@pm.to_xml_string)
+
assert_equal(1, doc.xpath(".//pageMargins[@left=1.1][@right=1.2][@top=1.3][@bottom=1.4][@header=0.8][@footer=0.9]").size)
end
def test_left
assert_raise(ArgumentError) { @pm.left = -1.2 }
assert_nothing_raised { @pm.left = 1.5 }
- assert_equal(@pm.left, 1.5)
+ assert_in_delta(@pm.left, 1.5)
end
def test_right
assert_raise(ArgumentError) { @pm.right = -1.2 }
assert_nothing_raised { @pm.right = 1.5 }
- assert_equal(@pm.right, 1.5)
+ assert_in_delta(@pm.right, 1.5)
end
def test_top
assert_raise(ArgumentError) { @pm.top = -1.2 }
assert_nothing_raised { @pm.top = 1.5 }
- assert_equal(@pm.top, 1.5)
+ assert_in_delta(@pm.top, 1.5)
end
def test_bottom
assert_raise(ArgumentError) { @pm.bottom = -1.2 }
assert_nothing_raised { @pm.bottom = 1.5 }
- assert_equal(@pm.bottom, 1.5)
+ assert_in_delta(@pm.bottom, 1.5)
end
def test_header
assert_raise(ArgumentError) { @pm.header = -1.2 }
assert_nothing_raised { @pm.header = 1.5 }
- assert_equal(@pm.header, 1.5)
+ assert_in_delta(@pm.header, 1.5)
end
def test_footer
assert_raise(ArgumentError) { @pm.footer = -1.2 }
assert_nothing_raised { @pm.footer = 1.5 }
- assert_equal(@pm.footer, 1.5)
+ assert_in_delta(@pm.footer, 1.5)
end
end
diff --git a/test/workbook/worksheet/tc_page_set_up_pr.rb b/test/workbook/worksheet/tc_page_set_up_pr.rb
index 8ca4f825..f634ba38 100644
--- a/test/workbook/worksheet/tc_page_set_up_pr.rb
+++ b/test/workbook/worksheet/tc_page_set_up_pr.rb
@@ -6,10 +6,10 @@ class TestPageSetUpPr < Test::Unit::TestCase
end
def test_fit_to_page
- assert_equal true, @page_setup_pr.fit_to_page
+ assert @page_setup_pr.fit_to_page
end
def test_auto_page_breaks
- assert_equal true, @page_setup_pr.auto_page_breaks
+ assert @page_setup_pr.auto_page_breaks
end
end
diff --git a/test/workbook/worksheet/tc_page_setup.rb b/test/workbook/worksheet/tc_page_setup.rb
index 6dca8b0a..85b0013a 100644
--- a/test/workbook/worksheet/tc_page_setup.rb
+++ b/test/workbook/worksheet/tc_page_setup.rb
@@ -8,12 +8,12 @@ class TestPageSetup < Test::Unit::TestCase
end
def test_initialize
- assert_equal(nil, @ps.fit_to_height)
- assert_equal(nil, @ps.fit_to_width)
- assert_equal(nil, @ps.orientation)
- assert_equal(nil, @ps.paper_height)
- assert_equal(nil, @ps.paper_width)
- assert_equal(nil, @ps.scale)
+ assert_nil(@ps.fit_to_height)
+ assert_nil(@ps.fit_to_width)
+ assert_nil(@ps.orientation)
+ assert_nil(@ps.paper_height)
+ assert_nil(@ps.paper_width)
+ assert_nil(@ps.scale)
end
def test_initialize_with_options
@@ -25,6 +25,7 @@ class TestPageSetup < Test::Unit::TestCase
:scale => 50 }
optioned = @p.workbook.add_worksheet(:name => 'optioned', :page_setup => page_setup).page_setup
+
assert_equal(1, optioned.fit_to_height)
assert_equal(2, optioned.fit_to_width)
assert_equal(:landscape, optioned.orientation)
@@ -35,6 +36,7 @@ class TestPageSetup < Test::Unit::TestCase
def test_set_all_values
@ps.set(:fit_to_height => 1, :fit_to_width => 2, :orientation => :landscape, :paper_height => "297mm", :paper_width => "210mm", :scale => 50)
+
assert_equal(1, @ps.fit_to_height)
assert_equal(2, @ps.fit_to_width)
assert_equal(:landscape, @ps.orientation)
@@ -50,40 +52,45 @@ class TestPageSetup < Test::Unit::TestCase
def test_set_some_values
@ps.set(:fit_to_width => 2, :orientation => :portrait)
+
assert_equal(2, @ps.fit_to_width)
assert_equal(:portrait, @ps.orientation)
- assert_equal(nil, @ps.fit_to_height)
- assert_equal(nil, @ps.paper_height)
- assert_equal(nil, @ps.paper_width)
- assert_equal(nil, @ps.scale)
+ assert_nil(@ps.fit_to_height)
+ assert_nil(@ps.paper_height)
+ assert_nil(@ps.paper_width)
+ assert_nil(@ps.scale)
end
def test_default_fit_to_page?
assert(@ps.fit_to_width.nil? && @ps.fit_to_height.nil?)
- assert(@ps.fit_to_page? == false)
+ refute_predicate(@ps, :fit_to_page?)
end
def test_with_height_fit_to_page?
assert(@ps.fit_to_width.nil? && @ps.fit_to_height.nil?)
@ps.set(:fit_to_height => 1)
- assert(@ps.fit_to_page?)
+
+ assert_predicate(@ps, :fit_to_page?)
end
def test_with_width_fit_to_page?
assert(@ps.fit_to_width.nil? && @ps.fit_to_height.nil?)
@ps.set(:fit_to_width => 1)
- assert(@ps.fit_to_page?)
+
+ assert_predicate(@ps, :fit_to_page?)
end
def test_to_xml_all_values
@ps.set(:fit_to_height => 1, :fit_to_width => 2, :orientation => :landscape, :paper_height => "297mm", :paper_width => "210mm", :scale => 50)
doc = Nokogiri::XML.parse(@ps.to_xml_string)
+
assert_equal(1, doc.xpath(".//pageSetup[@fitToHeight='1'][@fitToWidth='2'][@orientation='landscape'][@paperHeight='297mm'][@paperWidth='210mm'][@scale='50']").size)
end
def test_to_xml_some_values
@ps.set(:orientation => :portrait)
doc = Nokogiri::XML.parse(@ps.to_xml_string)
+
assert_equal(1, doc.xpath(".//pageSetup[@orientation='portrait']").size)
assert_equal(0, doc.xpath(".//pageSetup[@fitToHeight]").size)
assert_equal(0, doc.xpath(".//pageSetup[@fitToWidth]").size)
@@ -130,11 +137,14 @@ class TestPageSetup < Test::Unit::TestCase
def test_fit_to
fits = @ps.fit_to(:width => 1)
+
assert_equal([1, 999], fits)
fits = @ps.fit_to :height => 1
- assert_equal(fits, [999, 1])
+
+ assert_equal([999, 1], fits)
fits = @ps.fit_to :height => 7, :width => 2
- assert_equal(fits, [2, 7])
+
+ assert_equal([2, 7], fits)
assert_raise(ArgumentError) { puts @ps.fit_to(:width => true) }
end
end
diff --git a/test/workbook/worksheet/tc_pane.rb b/test/workbook/worksheet/tc_pane.rb
index 9a16866b..0e0c98fb 100644
--- a/test/workbook/worksheet/tc_pane.rb
+++ b/test/workbook/worksheet/tc_pane.rb
@@ -13,41 +13,43 @@ class TestPane < Test::Unit::TestCase
def test_active_pane
assert_raise(ArgumentError) { @pane.active_pane = "10" }
assert_nothing_raised { @pane.active_pane = :top_left }
- assert_equal(@pane.active_pane, "topLeft")
+ assert_equal("topLeft", @pane.active_pane)
end
def test_state
assert_raise(ArgumentError) { @pane.state = "foo" }
assert_nothing_raised { @pane.state = :frozen_split }
- assert_equal(@pane.state, "frozenSplit")
+ assert_equal("frozenSplit", @pane.state)
end
def test_x_split
assert_raise(ArgumentError) { @pane.x_split = "foo´" }
assert_nothing_raised { @pane.x_split = 200 }
- assert_equal(@pane.x_split, 200)
+ assert_equal(200, @pane.x_split)
end
def test_y_split
assert_raise(ArgumentError) { @pane.y_split = 'foo' }
assert_nothing_raised { @pane.y_split = 300 }
- assert_equal(@pane.y_split, 300)
+ assert_equal(300, @pane.y_split)
end
def test_top_left_cell
assert_raise(ArgumentError) { @pane.top_left_cell = :cell }
assert_nothing_raised { @pane.top_left_cell = "A2" }
- assert_equal(@pane.top_left_cell, "A2")
+ assert_equal("A2", @pane.top_left_cell)
end
def test_to_xml
doc = Nokogiri::XML.parse(@pane.to_xml_string)
+
assert_equal(1, doc.xpath("//pane[@ySplit=2][@xSplit='2'][@topLeftCell='A2'][@state='frozen'][@activePane='bottomLeft']").size)
end
def test_to_xml_frozen
pane = Axlsx::Pane.new :state => :frozen, :y_split => 2
doc = Nokogiri::XML(pane.to_xml_string)
+
assert_equal(1, doc.xpath("//pane[@topLeftCell='A3']").size)
end
end
diff --git a/test/workbook/worksheet/tc_pivot_table.rb b/test/workbook/worksheet/tc_pivot_table.rb
index a5bb8906..91df5597 100644
--- a/test/workbook/worksheet/tc_pivot_table.rb
+++ b/test/workbook/worksheet/tc_pivot_table.rb
@@ -8,7 +8,8 @@ def shared_test_pivot_table_xml_validity(pivot_table)
errors.push error
puts error.message
end
- assert(errors.empty?, "error free validation")
+
+ assert_empty(errors, "error free validation")
end
class TestPivotTable < Test::Unit::TestCase
@@ -21,12 +22,13 @@ class TestPivotTable < Test::Unit::TestCase
end
def test_initialization
- assert(@ws.workbook.pivot_tables.empty?)
- assert(@ws.pivot_tables.empty?)
+ assert_empty(@ws.workbook.pivot_tables)
+ assert_empty(@ws.pivot_tables)
end
def test_add_pivot_table
pivot_table = @ws.add_pivot_table('G5:G6', 'A1:D5')
+
assert_equal('G5:G6', pivot_table.ref, 'ref assigned from first parameter')
assert_equal('A1:D5', pivot_table.range, 'range assigned from second parameter')
assert_equal('PivotTable1', pivot_table.name, 'name automatically generated')
@@ -42,6 +44,7 @@ class TestPivotTable < Test::Unit::TestCase
assert_equal(pivot_table.data_sheet.name, @ws.name, "must default to the same sheet the pivot table is added to")
pivot_table.data_sheet = data_sheet
+
assert_equal(pivot_table.data_sheet.name, data_sheet.name, "data sheet assigned to pivot table")
end
@@ -52,6 +55,7 @@ class TestPivotTable < Test::Unit::TestCase
pt.data = ['Sales']
pt.pages = ['Region']
end
+
assert_equal(['Year', 'Month'], pivot_table.rows)
assert_equal(['Type'], pivot_table.columns)
assert_equal([{ :ref => "Sales" }], pivot_table.data)
@@ -63,6 +67,7 @@ class TestPivotTable < Test::Unit::TestCase
pivot_table = @ws.add_pivot_table('G5:G6', 'A1:D5') do |pt|
pt.data = [{ :ref => "Sales", :subtotal => 'average' }]
end
+
assert_equal([{ :ref => "Sales", :subtotal => 'average' }], pivot_table.data)
end
@@ -74,6 +79,7 @@ class TestPivotTable < Test::Unit::TestCase
pt.data = ['Sales']
pt.pages = ['Region']
end
+
assert_equal(style_info_data, pivot_table.style_info)
shared_test_pivot_table_xml_validity(pivot_table)
end
@@ -83,6 +89,7 @@ class TestPivotTable < Test::Unit::TestCase
pt.data = ['Sales']
pt.rows = ['Year', 'Month']
end
+
assert_equal(['Year'], pivot_table.no_subtotals_on_headers)
end
@@ -91,9 +98,11 @@ class TestPivotTable < Test::Unit::TestCase
pt.data = ['Sales']
pt.rows = ['Year', 'Month']
end
+
assert_equal({ 'Month' => :ascending }, pivot_table.sort_on_headers)
pivot_table.sort_on_headers = { 'Month' => :descending }
+
assert_equal({ 'Month' => :descending }, pivot_table.sort_on_headers)
shared_test_pivot_table_xml_validity(pivot_table)
@@ -101,31 +110,36 @@ class TestPivotTable < Test::Unit::TestCase
def test_header_indices
pivot_table = @ws.add_pivot_table('G5:G6', 'A1:E5')
+
assert_equal(0, pivot_table.header_index_of('Year'))
assert_equal(1, pivot_table.header_index_of('Month'))
assert_equal(2, pivot_table.header_index_of('Region'))
assert_equal(3, pivot_table.header_index_of('Type'))
assert_equal(4, pivot_table.header_index_of('Sales'))
- assert_equal(nil, pivot_table.header_index_of('Missing'))
+ assert_nil(pivot_table.header_index_of('Missing'))
assert_equal(%w(A1 B1 C1 D1 E1), pivot_table.header_cell_refs)
end
def test_pn
@ws.add_pivot_table('G5:G6', 'A1:D5')
- assert_equal(@ws.pivot_tables.first.pn, "pivotTables/pivotTable1.xml")
+
+ assert_equal("pivotTables/pivotTable1.xml", @ws.pivot_tables.first.pn)
end
def test_index
@ws.add_pivot_table('G5:G6', 'A1:D5')
+
assert_equal(@ws.pivot_tables.first.index, @ws.workbook.pivot_tables.index(@ws.pivot_tables.first))
end
def test_relationships
- assert(@ws.relationships.empty?)
+ assert_empty(@ws.relationships)
@ws.add_pivot_table('G5:G6', 'A1:D5')
- assert_equal(@ws.relationships.size, 1, "adding a pivot table adds a relationship")
+
+ assert_equal(1, @ws.relationships.size, "adding a pivot table adds a relationship")
@ws.add_pivot_table('G10:G11', 'A1:D5')
- assert_equal(@ws.relationships.size, 2, "adding a pivot table adds a relationship")
+
+ assert_equal(2, @ws.relationships.size, "adding a pivot table adds a relationship")
end
def test_to_xml_string
@@ -150,6 +164,7 @@ class TestPivotTable < Test::Unit::TestCase
pt.data = [{ :ref => "Sales", :subtotal => 'sum', num_fmt: 4 }]
end
doc = Nokogiri::XML(pivot_table.to_xml_string)
+
assert_equal('4', doc.at_css('dataFields dataField')['numFmtId'], 'adding format options to pivot_table')
end
@@ -167,9 +182,9 @@ class TestPivotTable < Test::Unit::TestCase
xml = pivot_table.to_xml_string
- assert(!xml.include?('dataOnRows'))
- assert(xml.include?('colFields'))
- assert(xml.include?('colItems'))
+ refute_includes(xml, 'dataOnRows')
+ assert_includes(xml, 'colFields')
+ assert_includes(xml, 'colItems')
doc = Nokogiri::XML(pivot_table.to_xml_string)
@@ -195,9 +210,9 @@ class TestPivotTable < Test::Unit::TestCase
xml = pivot_table.to_xml_string
- assert(xml.include?('dataOnRows'))
- assert(xml.include?('colItems'))
+ assert_includes(xml, 'dataOnRows')
+ assert_includes(xml, 'colItems')
- assert(!xml.include?('colFields'))
+ refute_includes(xml, 'colFields')
end
end
diff --git a/test/workbook/worksheet/tc_pivot_table_cache_definition.rb b/test/workbook/worksheet/tc_pivot_table_cache_definition.rb
index 2127c4b3..b3a4484d 100644
--- a/test/workbook/worksheet/tc_pivot_table_cache_definition.rb
+++ b/test/workbook/worksheet/tc_pivot_table_cache_definition.rb
@@ -37,7 +37,7 @@ class TestPivotTableCacheDefinition < Test::Unit::TestCase
data_sheet.name = "Pivot Table Data Source"
@pivot_table.data_sheet = data_sheet
- assert(@cache_definition.to_xml_string.include?(data_sheet.name), "must set the data source correctly")
+ assert_includes(@cache_definition.to_xml_string, data_sheet.name, "must set the data source correctly")
end
def test_to_xml_string
@@ -48,7 +48,8 @@ class TestPivotTableCacheDefinition < Test::Unit::TestCase
errors.push error
puts error.message
end
- assert(errors.empty?, "error free validation")
+
+ assert_empty(errors, "error free validation")
end
def test_to_xml_string_for_special_characters
@@ -57,6 +58,7 @@ class TestPivotTableCacheDefinition < Test::Unit::TestCase
doc = Nokogiri::XML(@cache_definition.to_xml_string)
errors = doc.errors
- assert(errors.empty?, "invalid xml: #{errors.map(&:to_s).join(', ')}")
+
+ assert_empty(errors, "invalid xml: #{errors.map(&:to_s).join(', ')}")
end
end
diff --git a/test/workbook/worksheet/tc_print_options.rb b/test/workbook/worksheet/tc_print_options.rb
index 8dc2b804..40812b3e 100644
--- a/test/workbook/worksheet/tc_print_options.rb
+++ b/test/workbook/worksheet/tc_print_options.rb
@@ -8,63 +8,67 @@ class TestPrintOptions < Test::Unit::TestCase
end
def test_initialize
- assert_equal(false, @po.grid_lines)
- assert_equal(false, @po.headings)
- assert_equal(false, @po.horizontal_centered)
- assert_equal(false, @po.vertical_centered)
+ refute(@po.grid_lines)
+ refute(@po.headings)
+ refute(@po.horizontal_centered)
+ refute(@po.vertical_centered)
end
def test_initialize_with_options
optioned = Axlsx::PrintOptions.new(:grid_lines => true, :headings => true, :horizontal_centered => true, :vertical_centered => true)
- assert_equal(true, optioned.grid_lines)
- assert_equal(true, optioned.headings)
- assert_equal(true, optioned.horizontal_centered)
- assert_equal(true, optioned.vertical_centered)
+
+ assert(optioned.grid_lines)
+ assert(optioned.headings)
+ assert(optioned.horizontal_centered)
+ assert(optioned.vertical_centered)
end
def test_set_all_values
@po.set(:grid_lines => true, :headings => true, :horizontal_centered => true, :vertical_centered => true)
- assert_equal(true, @po.grid_lines)
- assert_equal(true, @po.headings)
- assert_equal(true, @po.horizontal_centered)
- assert_equal(true, @po.vertical_centered)
+
+ assert(@po.grid_lines)
+ assert(@po.headings)
+ assert(@po.horizontal_centered)
+ assert(@po.vertical_centered)
end
def test_set_some_values
@po.set(:grid_lines => true, :headings => true)
- assert_equal(true, @po.grid_lines)
- assert_equal(true, @po.headings)
- assert_equal(false, @po.horizontal_centered)
- assert_equal(false, @po.vertical_centered)
+
+ assert(@po.grid_lines)
+ assert(@po.headings)
+ refute(@po.horizontal_centered)
+ refute(@po.vertical_centered)
end
def test_to_xml
@po.set(:grid_lines => true, :headings => true, :horizontal_centered => true, :vertical_centered => true)
doc = Nokogiri::XML.parse(@po.to_xml_string)
+
assert_equal(1, doc.xpath(".//printOptions[@gridLines=1][@headings=1][@horizontalCentered=1][@verticalCentered=1]").size)
end
def test_grid_lines
assert_raise(ArgumentError) { @po.grid_lines = 99 }
assert_nothing_raised { @po.grid_lines = true }
- assert_equal(@po.grid_lines, true)
+ assert(@po.grid_lines)
end
def test_headings
assert_raise(ArgumentError) { @po.headings = 99 }
assert_nothing_raised { @po.headings = true }
- assert_equal(@po.headings, true)
+ assert(@po.headings)
end
def test_horizontal_centered
assert_raise(ArgumentError) { @po.horizontal_centered = 99 }
assert_nothing_raised { @po.horizontal_centered = true }
- assert_equal(@po.horizontal_centered, true)
+ assert(@po.horizontal_centered)
end
def test_vertical_centered
assert_raise(ArgumentError) { @po.vertical_centered = 99 }
assert_nothing_raised { @po.vertical_centered = true }
- assert_equal(@po.vertical_centered, true)
+ assert(@po.vertical_centered)
end
end
diff --git a/test/workbook/worksheet/tc_protected_range.rb b/test/workbook/worksheet/tc_protected_range.rb
index 906c6014..db1ab93a 100644
--- a/test/workbook/worksheet/tc_protected_range.rb
+++ b/test/workbook/worksheet/tc_protected_range.rb
@@ -11,6 +11,7 @@ class TestProtectedRange < Test::Unit::TestCase
def test_range
r = @ws.protect_range('A1:B1')
+
assert_equal('A1:B1', r.sqref)
end
end
diff --git a/test/workbook/worksheet/tc_rich_text.rb b/test/workbook/worksheet/tc_rich_text.rb
index 6c9627d4..6ed8e5f0 100644
--- a/test/workbook/worksheet/tc_rich_text.rb
+++ b/test/workbook/worksheet/tc_rich_text.rb
@@ -19,19 +19,22 @@ class RichText < Test::Unit::TestCase
rt_direct = Axlsx::RichText.new('hi', :i => true)
rt_indirect = Axlsx::RichText.new
rt_indirect.add_run('hi', :i => true)
- assert_equal(rt_direct.runs.length, 1)
- assert_equal(rt_indirect.runs.length, 1)
+
+ assert_equal(1, rt_direct.runs.length)
+ assert_equal(1, rt_indirect.runs.length)
row = @ws.add_row [rt_direct, rt_indirect]
+
assert_equal(row[0].to_xml_string(0, 0), row[1].to_xml_string(0, 0))
end
def test_textruns
runs = @rt.runs
- assert_equal(runs.length, 27)
- assert_equal(runs.first.b, false)
- assert_equal(runs.first.i, true)
- assert_equal(runs[1].b, true)
- assert_equal(runs[1].i, false)
+
+ assert_equal(27, runs.length)
+ refute(runs.first.b)
+ assert(runs.first.i)
+ assert(runs[1].b)
+ refute(runs[1].i)
end
def test_implicit_richtext
@@ -39,6 +42,7 @@ class RichText < Test::Unit::TestCase
row_rt = @ws.add_row [rt]
row_imp = @ws.add_row ['a']
row_imp[0].b = true
+
assert_equal(row_rt[0].to_xml_string(0, 0), row_imp[0].to_xml_string(0, 0))
end
end
diff --git a/test/workbook/worksheet/tc_rich_text_run.rb b/test/workbook/worksheet/tc_rich_text_run.rb
index d21329a9..61c462f0 100644
--- a/test/workbook/worksheet/tc_rich_text_run.rb
+++ b/test/workbook/worksheet/tc_rich_text_run.rb
@@ -15,21 +15,24 @@ class RichTextRun < Test::Unit::TestCase
end
def test_initialize
- assert_equal(@rtr.value, 'hihihi')
- assert_equal(@rtr.b, true)
- assert_equal(@rtr.i, false)
+ assert_equal('hihihi', @rtr.value)
+ assert(@rtr.b)
+ refute(@rtr.i)
end
def test_font_size_with_custom_style_and_no_sz
@c.style = @c.row.worksheet.workbook.styles.add_style :bg_color => 'FF00FF'
sz = @rtr.send(:font_size)
+
assert_equal(sz, @c.row.worksheet.workbook.styles.fonts.first.sz * 1.5)
sz = @rtr2.send(:font_size)
+
assert_equal(sz, @c.row.worksheet.workbook.styles.fonts.first.sz)
end
def test_font_size_with_bolding
@c.style = @c.row.worksheet.workbook.styles.add_style :b => true
+
assert_equal(@c.row.worksheet.workbook.styles.fonts.first.sz * 1.5, @rtr.send(:font_size))
assert_equal(@c.row.worksheet.workbook.styles.fonts.first.sz * 1.5, @rtr2.send(:font_size)) # is this the correct behaviour?
end
@@ -37,107 +40,111 @@ class RichTextRun < Test::Unit::TestCase
def test_font_size_with_custom_sz
@c.style = @c.row.worksheet.workbook.styles.add_style :sz => 52
sz = @rtr.send(:font_size)
- assert_equal(sz, 52 * 1.5)
+
+ assert_equal(52 * 1.5, sz)
sz2 = @rtr2.send(:font_size)
- assert_equal(sz2, 52)
+
+ assert_equal(52, sz2)
end
def test_rtr_with_sz
@rtr.sz = 25
+
assert_equal(25, @rtr.send(:font_size))
end
def test_color
assert_raise(ArgumentError) { @rtr.color = -1.1 }
assert_nothing_raised { @rtr.color = "FF00FF00" }
- assert_equal(@rtr.color.rgb, "FF00FF00")
+ assert_equal("FF00FF00", @rtr.color.rgb)
end
def test_scheme
assert_raise(ArgumentError) { @rtr.scheme = -1.1 }
assert_nothing_raised { @rtr.scheme = :major }
- assert_equal(@rtr.scheme, :major)
+ assert_equal(:major, @rtr.scheme)
end
def test_vertAlign
assert_raise(ArgumentError) { @rtr.vertAlign = -1.1 }
assert_nothing_raised { @rtr.vertAlign = :baseline }
- assert_equal(@rtr.vertAlign, :baseline)
+ assert_equal(:baseline, @rtr.vertAlign)
end
def test_sz
assert_raise(ArgumentError) { @rtr.sz = -1.1 }
assert_nothing_raised { @rtr.sz = 12 }
- assert_equal(@rtr.sz, 12)
+ assert_equal(12, @rtr.sz)
end
def test_extend
assert_raise(ArgumentError) { @rtr.extend = -1.1 }
assert_nothing_raised { @rtr.extend = false }
- assert_equal(@rtr.extend, false)
+ refute(@rtr.extend)
end
def test_condense
assert_raise(ArgumentError) { @rtr.condense = -1.1 }
assert_nothing_raised { @rtr.condense = false }
- assert_equal(@rtr.condense, false)
+ refute(@rtr.condense)
end
def test_shadow
assert_raise(ArgumentError) { @rtr.shadow = -1.1 }
assert_nothing_raised { @rtr.shadow = false }
- assert_equal(@rtr.shadow, false)
+ refute(@rtr.shadow)
end
def test_outline
assert_raise(ArgumentError) { @rtr.outline = -1.1 }
assert_nothing_raised { @rtr.outline = false }
- assert_equal(@rtr.outline, false)
+ refute(@rtr.outline)
end
def test_strike
assert_raise(ArgumentError) { @rtr.strike = -1.1 }
assert_nothing_raised { @rtr.strike = false }
- assert_equal(@rtr.strike, false)
+ refute(@rtr.strike)
end
def test_u
@c.type = :string
assert_raise(ArgumentError) { @c.u = -1.1 }
assert_nothing_raised { @c.u = :single }
- assert_equal(@c.u, :single)
+ assert_equal(:single, @c.u)
doc = Nokogiri::XML(@c.to_xml_string(1, 1))
+
assert(doc.xpath('//u[@val="single"]'))
end
def test_i
assert_raise(ArgumentError) { @c.i = -1.1 }
assert_nothing_raised { @c.i = false }
- assert_equal(@c.i, false)
+ refute(@c.i)
end
def test_rFont
assert_raise(ArgumentError) { @c.font_name = -1.1 }
assert_nothing_raised { @c.font_name = "Arial" }
- assert_equal(@c.font_name, "Arial")
+ assert_equal("Arial", @c.font_name)
end
def test_charset
assert_raise(ArgumentError) { @c.charset = -1.1 }
assert_nothing_raised { @c.charset = 1 }
- assert_equal(@c.charset, 1)
+ assert_equal(1, @c.charset)
end
def test_family
assert_raise(ArgumentError) { @rtr.family = 0 }
assert_nothing_raised { @rtr.family = 1 }
- assert_equal(@rtr.family, 1)
+ assert_equal(1, @rtr.family)
end
def test_b
assert_raise(ArgumentError) { @c.b = -1.1 }
assert_nothing_raised { @c.b = false }
- assert_equal(@c.b, false)
+ refute(@c.b)
end
def test_multiline_autowidth
@@ -148,8 +155,9 @@ class RichTextRun < Test::Unit::TestCase
@ws.add_row [rt], :style => wrap
ar = [0]
awtr.autowidth(ar)
+
assert_equal(2, ar.length)
- assert_equal(13.2, ar[0])
+ assert_in_delta(13.2, ar[0])
assert_equal(0, ar[1])
end
@@ -161,7 +169,8 @@ class RichTextRun < Test::Unit::TestCase
puts error.message
errors.push error
end
- assert(errors.empty?, "error free validation")
+
+ assert_empty(errors, "error free validation")
assert(doc.xpath('//rPr/b[@val=1]'))
assert(doc.xpath('//rPr/i[@val=0]'))
diff --git a/test/workbook/worksheet/tc_row.rb b/test/workbook/worksheet/tc_row.rb
index cf8fa7c3..0d1c724d 100644
--- a/test/workbook/worksheet/tc_row.rb
+++ b/test/workbook/worksheet/tc_row.rb
@@ -8,14 +8,15 @@ class TestRow < Test::Unit::TestCase
end
def test_initialize
- assert(@row.cells.empty?, "no cells by default")
+ assert_empty(@row.cells, "no cells by default")
assert_equal(@row.worksheet, @ws, "has a reference to the worksheet")
assert_nil(@row.height, "height defaults to nil")
- assert([email protected]_height, "no custom height by default")
+ refute(@row.custom_height, "no custom height by default")
end
def test_initialize_with_fixed_height
row = @ws.add_row([1, 2, 3, 4, 5], :height => 40)
+
assert_equal(40, row.height)
assert(row.custom_height)
end
@@ -23,13 +24,15 @@ class TestRow < Test::Unit::TestCase
def test_style
r = @ws.add_row([1, 2, 3, 4, 5])
r.style = 1
- r.cells.each { |c| assert_equal(c.style, 1) }
+
+ r.cells.each { |c| assert_equal(1, c.style) }
end
def test_color
r = @ws.add_row([1, 2, 3, 4, 5])
r.color = "FF00FF00"
- r.cells.each { |c| assert_equal(c.color.rgb, "FF00FF00") }
+
+ r.cells.each { |c| assert_equal("FF00FF00", c.color.rgb) }
end
def test_index
@@ -38,45 +41,50 @@ class TestRow < Test::Unit::TestCase
def test_add_cell
c = @row.add_cell(1)
+
assert_equal(@row.cells.last, c)
end
def test_add_cell_autowidth_info
cell = @row.add_cell("this is the cell of cells")
width = cell.send(:autowidth)
+
assert_equal(@ws.column_info.last.width, width)
end
def test_array_to_cells
r = @ws.add_row [1, 2, 3], :style => 1, :types => [:integer, :string, :float]
- assert_equal(r.cells.size, 3)
+
+ assert_equal(3, r.cells.size)
r.cells.each do |c|
- assert_equal(c.style, 1)
+ assert_equal(1, c.style)
end
r = @ws.add_row [1, 2, 3], :style => [1]
- assert_equal(r.cells.first.style, 1, "only apply style to cells with at the same index of of the style array")
- assert_equal(r.cells.last.style, 0, "only apply style to cells with at the same index of of the style array")
+
+ assert_equal(1, r.cells.first.style, "only apply style to cells with at the same index of of the style array")
+ assert_equal(0, r.cells.last.style, "only apply style to cells with at the same index of of the style array")
end
def test_array_to_cells_with_escape_formulas
row = ['=HYPERLINK("http://www.example.com", "CSV Payload")', '=Bar']
@ws.add_row row, escape_formulas: true
- assert_equal @ws.rows.last.cells[0].escape_formulas, true
- assert_equal @ws.rows.last.cells[1].escape_formulas, true
+ assert(@ws.rows.last.cells[0].escape_formulas)
+ assert(@ws.rows.last.cells[1].escape_formulas)
end
def test_array_to_cells_with_escape_formulas_as_an_array
row = ['=HYPERLINK("http://www.example.com", "CSV Payload")', '+Foo', '-Bar']
@ws.add_row row, escape_formulas: [true, false, true]
- assert_equal @ws.rows.last.cells.first.escape_formulas, true
- assert_equal @ws.rows.last.cells[1].escape_formulas, false
- assert_equal @ws.rows.last.cells[2].escape_formulas, true
+ assert(@ws.rows.last.cells.first.escape_formulas)
+ refute(@ws.rows.last.cells[1].escape_formulas)
+ assert(@ws.rows.last.cells[2].escape_formulas)
end
def test_custom_height
@row.height = 20
+
assert(@row.custom_height)
end
@@ -89,19 +97,19 @@ class TestRow < Test::Unit::TestCase
def test_ph
assert_raise(ArgumentError) { @row.ph = -3 }
assert_nothing_raised { @row.ph = true }
- assert_equal(true, @row.ph)
+ assert(@row.ph)
end
def test_hidden
assert_raise(ArgumentError) { @row.hidden = -3 }
assert_nothing_raised { @row.hidden = true }
- assert_equal(true, @row.hidden)
+ assert(@row.hidden)
end
def test_collapsed
assert_raise(ArgumentError) { @row.collapsed = -3 }
assert_nothing_raised { @row.collapsed = true }
- assert_equal(true, @row.collapsed)
+ assert(@row.collapsed)
end
def test_outlineLevel
@@ -112,6 +120,7 @@ class TestRow < Test::Unit::TestCase
def test_to_xml_without_custom_height
doc = Nokogiri::XML.parse(@row.to_xml_string(0))
+
assert_equal(0, doc.xpath(".//row[@ht]").size)
assert_equal(0, doc.xpath(".//row[@customHeight]").size)
end
@@ -123,14 +132,16 @@ class TestRow < Test::Unit::TestCase
@row.collapsed = true
@row.hidden = true
r_s_xml = Nokogiri::XML(@row.to_xml_string(0, ''))
- assert_equal(r_s_xml.xpath(".//row[@r=1]").size, 1)
+
+ assert_equal(1, r_s_xml.xpath(".//row[@r=1]").size)
end
def test_to_xml_string_with_custom_height
@row.add_cell 1
@row.height = 20
r_s_xml = Nokogiri::XML(@row.to_xml_string(0, ''))
- assert_equal(r_s_xml.xpath(".//row[@r=1][@ht=20][@customHeight=1]").size, 1)
+
+ assert_equal(1, r_s_xml.xpath(".//row[@r=1][@ht=20][@customHeight=1]").size)
end
def test_offsets
@@ -157,11 +168,13 @@ class TestRow < Test::Unit::TestCase
def test_escape_formulas
@ws.escape_formulas = false
@row = @ws.add_row
+
assert_false @row.add_cell('').escape_formulas
assert_false @row.add_cell('', escape_formulas: false).escape_formulas
assert @row.add_cell('', escape_formulas: true).escape_formulas
@row = Axlsx::Row.new(@ws)
+
assert_false @row.add_cell('').escape_formulas
@ws.escape_formulas = true
@@ -172,12 +185,15 @@ class TestRow < Test::Unit::TestCase
assert @row.add_cell('', escape_formulas: true).escape_formulas
@row.escape_formulas = false
+
assert_equal [false, false, false], @row.cells.map(&:escape_formulas)
@row.escape_formulas = true
+
assert_equal [true, true, true], @row.cells.map(&:escape_formulas)
@row.escape_formulas = [false, true, false]
+
assert_equal [false, true, false], @row.cells.map(&:escape_formulas)
end
end
diff --git a/test/workbook/worksheet/tc_selection.rb b/test/workbook/worksheet/tc_selection.rb
index d600aa67..97419a64 100644
--- a/test/workbook/worksheet/tc_selection.rb
+++ b/test/workbook/worksheet/tc_selection.rb
@@ -9,25 +9,25 @@ class TestSelection < Test::Unit::TestCase
def test_active_cell
assert_raise(ArgumentError) { @selection.active_cell = :active_cell }
assert_nothing_raised { @selection.active_cell = "F5" }
- assert_equal(@selection.active_cell, "F5")
+ assert_equal("F5", @selection.active_cell)
end
def test_active_cell_id
assert_raise(ArgumentError) { @selection.active_cell_id = "foo" }
assert_nothing_raised { @selection.active_cell_id = 11 }
- assert_equal(@selection.active_cell_id, 11)
+ assert_equal(11, @selection.active_cell_id)
end
def test_pane
assert_raise(ArgumentError) { @selection.pane = "foo´" }
assert_nothing_raised { @selection.pane = :bottom_right }
- assert_equal(@selection.pane, "bottomRight")
+ assert_equal("bottomRight", @selection.pane)
end
def test_sqref
assert_raise(ArgumentError) { @selection.sqref = :sqref }
assert_nothing_raised { @selection.sqref = "G32" }
- assert_equal(@selection.sqref, "G32")
+ assert_equal("G32", @selection.sqref)
end
def test_to_xml
diff --git a/test/workbook/worksheet/tc_sheet_calc_pr.rb b/test/workbook/worksheet/tc_sheet_calc_pr.rb
index 9473c94b..0d810378 100644
--- a/test/workbook/worksheet/tc_sheet_calc_pr.rb
+++ b/test/workbook/worksheet/tc_sheet_calc_pr.rb
@@ -6,12 +6,13 @@ class TestSheetCalcPr < Test::Unit::TestCase
end
def test_full_calc_on_load
- assert_equal false, @sheet_calc_pr.full_calc_on_load
+ refute @sheet_calc_pr.full_calc_on_load
assert Axlsx::SheetCalcPr.new.full_calc_on_load
end
def test_to_xml_string
doc = Nokogiri::XML(@sheet_calc_pr.to_xml_string)
+
assert_equal 1, doc.xpath('//sheetCalcPr[@fullCalcOnLoad=0]').size
end
end
diff --git a/test/workbook/worksheet/tc_sheet_format_pr.rb b/test/workbook/worksheet/tc_sheet_format_pr.rb
index 1240da26..6a8141c4 100644
--- a/test/workbook/worksheet/tc_sheet_format_pr.rb
+++ b/test/workbook/worksheet/tc_sheet_format_pr.rb
@@ -18,6 +18,7 @@ class TestSheetFormatPr < Test::Unit::TestCase
def test_default_initialization
sheet_format_pr = Axlsx::SheetFormatPr.new
+
assert_equal 8, sheet_format_pr.base_col_width
assert_equal 18, sheet_format_pr.default_row_height
end
@@ -75,6 +76,7 @@ class TestSheetFormatPr < Test::Unit::TestCase
def test_to_xml_string
doc = Nokogiri::XML(@sheet_format_pr.to_xml_string)
+
assert doc.xpath("sheetFormatPr[@thickBottom=1]")
assert doc.xpath("sheetFormatPr[@baseColWidth=5]")
assert doc.xpath("sheetFormatPr[@default_col_width=7.2]")
diff --git a/test/workbook/worksheet/tc_sheet_pr.rb b/test/workbook/worksheet/tc_sheet_pr.rb
index 70ce0428..819b265a 100644
--- a/test/workbook/worksheet/tc_sheet_pr.rb
+++ b/test/workbook/worksheet/tc_sheet_pr.rb
@@ -22,7 +22,8 @@ class TestSheetPr < Test::Unit::TestCase
@options.each do |key, value|
if key == :tab_color
stored_value = @sheet_pr.send(key)
- assert_equal Axlsx::Color, stored_value.class
+
+ assert_instance_of Axlsx::Color, stored_value
assert_equal value, stored_value.rgb
else
assert_equal value, @sheet_pr.send(key)
@@ -32,16 +33,17 @@ class TestSheetPr < Test::Unit::TestCase
def test_to_xml_string
doc = Nokogiri::XML(@sheet_pr.to_xml_string)
- assert_equal(doc.xpath("//sheetPr[@syncHorizontal='0']").size, 1)
- assert_equal(doc.xpath("//sheetPr[@syncVertical='0']").size, 1)
- assert_equal(doc.xpath("//sheetPr[@transitionEvaluation='1']").size, 1)
- assert_equal(doc.xpath("//sheetPr[@transitionEntry='1']").size, 1)
- assert_equal(doc.xpath("//sheetPr[@published='0']").size, 1)
- assert_equal(doc.xpath("//sheetPr[@filterMode='1']").size, 1)
- assert_equal(doc.xpath("//sheetPr[@enableFormatConditionsCalculation='0']").size, 1)
- assert_equal(doc.xpath("//sheetPr[@codeName='007']").size, 1)
- assert_equal(doc.xpath("//sheetPr[@syncRef='foo']").size, 1)
- assert_equal(doc.xpath("//sheetPr/tabColor[@rgb='FFFF6666']").size, 1)
- assert_equal(doc.xpath("//sheetPr/pageSetUpPr[@fitToPage='0']").size, 1)
+
+ assert_equal(1, doc.xpath("//sheetPr[@syncHorizontal='0']").size)
+ assert_equal(1, doc.xpath("//sheetPr[@syncVertical='0']").size)
+ assert_equal(1, doc.xpath("//sheetPr[@transitionEvaluation='1']").size)
+ assert_equal(1, doc.xpath("//sheetPr[@transitionEntry='1']").size)
+ assert_equal(1, doc.xpath("//sheetPr[@published='0']").size)
+ assert_equal(1, doc.xpath("//sheetPr[@filterMode='1']").size)
+ assert_equal(1, doc.xpath("//sheetPr[@enableFormatConditionsCalculation='0']").size)
+ assert_equal(1, doc.xpath("//sheetPr[@codeName='007']").size)
+ assert_equal(1, doc.xpath("//sheetPr[@syncRef='foo']").size)
+ assert_equal(1, doc.xpath("//sheetPr/tabColor[@rgb='FFFF6666']").size)
+ assert_equal(1, doc.xpath("//sheetPr/pageSetUpPr[@fitToPage='0']").size)
end
end
diff --git a/test/workbook/worksheet/tc_sheet_protection.rb b/test/workbook/worksheet/tc_sheet_protection.rb
index e8f18df5..08fe1cb9 100644
--- a/test/workbook/worksheet/tc_sheet_protection.rb
+++ b/test/workbook/worksheet/tc_sheet_protection.rb
@@ -54,6 +54,7 @@ class TestSheetProtection < Test::Unit::TestCase
def test_to_xml_string
@sp.password = 'fish' # -> CA3F
doc = Nokogiri::XML(@sp.to_xml_string)
+
@options.each do |key, value|
assert(doc.xpath("//sheetProtection[@#{key.to_s.gsub(/_(.)/) { $1.upcase }}='#{value}']"))
end
diff --git a/test/workbook/worksheet/tc_sheet_view.rb b/test/workbook/worksheet/tc_sheet_view.rb
index 18bb3308..f53eb506 100644
--- a/test/workbook/worksheet/tc_sheet_view.rb
+++ b/test/workbook/worksheet/tc_sheet_view.rb
@@ -29,7 +29,7 @@ class TestSheetView < Test::Unit::TestCase
end
@nil_options.each do |key, value|
- assert_equal(nil, sv.send(key.to_sym), "initialized default #{key} should be nil")
+ assert_nil(sv.send(key.to_sym), "initialized default #{key} should be nil")
assert_equal(value, @sv.send(key.to_sym), "initialized options #{key} should be #{value}")
end
@@ -75,115 +75,115 @@ class TestSheetView < Test::Unit::TestCase
def test_color_id
assert_raise(ArgumentError) { @sv.color_id = "10" }
assert_nothing_raised { @sv.color_id = 2 }
- assert_equal(@sv.color_id, 2)
+ assert_equal(2, @sv.color_id)
end
def test_default_grid_color
assert_raise(ArgumentError) { @sv.default_grid_color = "foo" }
assert_nothing_raised { @sv.default_grid_color = false }
- assert_equal(@sv.default_grid_color, false)
+ refute(@sv.default_grid_color)
end
def test_right_to_left
assert_raise(ArgumentError) { @sv.right_to_left = "foo´" }
assert_nothing_raised { @sv.right_to_left = true }
- assert_equal(@sv.right_to_left, true)
+ assert(@sv.right_to_left)
end
def test_show_formulas
assert_raise(ArgumentError) { @sv.show_formulas = 'foo' }
assert_nothing_raised { @sv.show_formulas = false }
- assert_equal(@sv.show_formulas, false)
+ refute(@sv.show_formulas)
end
def test_show_grid_lines
assert_raise(ArgumentError) { @sv.show_grid_lines = "foo" }
assert_nothing_raised { @sv.show_grid_lines = false }
- assert_equal(@sv.show_grid_lines, false)
+ refute(@sv.show_grid_lines)
end
def test_show_outline_symbols
assert_raise(ArgumentError) { @sv.show_outline_symbols = 'foo' }
assert_nothing_raised { @sv.show_outline_symbols = false }
- assert_equal(@sv.show_outline_symbols, false)
+ refute(@sv.show_outline_symbols)
end
def test_show_row_col_headers
assert_raise(ArgumentError) { @sv.show_row_col_headers = "foo" }
assert_nothing_raised { @sv.show_row_col_headers = false }
- assert_equal(@sv.show_row_col_headers, false)
+ refute(@sv.show_row_col_headers)
end
def test_show_ruler
assert_raise(ArgumentError) { @sv.show_ruler = 'foo' }
assert_nothing_raised { @sv.show_ruler = false }
- assert_equal(@sv.show_ruler, false)
+ refute(@sv.show_ruler)
end
def test_show_white_space
assert_raise(ArgumentError) { @sv.show_white_space = 'foo' }
assert_nothing_raised { @sv.show_white_space = false }
- assert_equal(@sv.show_white_space, false)
+ refute(@sv.show_white_space)
end
def test_show_zeros
assert_raise(ArgumentError) { @sv.show_zeros = "foo" }
assert_nothing_raised { @sv.show_zeros = false }
- assert_equal(@sv.show_zeros, false)
+ refute(@sv.show_zeros)
end
def test_tab_selected
assert_raise(ArgumentError) { @sv.tab_selected = "foo" }
assert_nothing_raised { @sv.tab_selected = false }
- assert_equal(@sv.tab_selected, false)
+ refute(@sv.tab_selected)
end
def test_top_left_cell
assert_raise(ArgumentError) { @sv.top_left_cell = :cell_adress }
assert_nothing_raised { @sv.top_left_cell = "A2" }
- assert_equal(@sv.top_left_cell, "A2")
+ assert_equal("A2", @sv.top_left_cell)
end
def test_view
assert_raise(ArgumentError) { @sv.view = 'view' }
assert_nothing_raised { @sv.view = :page_break_preview }
- assert_equal(@sv.view, :page_break_preview)
+ assert_equal(:page_break_preview, @sv.view)
end
def test_window_protection
assert_raise(ArgumentError) { @sv.window_protection = "foo" }
assert_nothing_raised { @sv.window_protection = false }
- assert_equal(@sv.window_protection, false)
+ refute(@sv.window_protection)
end
def test_workbook_view_id
assert_raise(ArgumentError) { @sv.workbook_view_id = "1" }
assert_nothing_raised { @sv.workbook_view_id = 1 }
- assert_equal(@sv.workbook_view_id, 1)
+ assert_equal(1, @sv.workbook_view_id)
end
def test_zoom_scale
assert_raise(ArgumentError) { @sv.zoom_scale = "50" }
assert_nothing_raised { @sv.zoom_scale = 50 }
- assert_equal(@sv.zoom_scale, 50)
+ assert_equal(50, @sv.zoom_scale)
end
def test_zoom_scale_normal
assert_raise(ArgumentError) { @sv.zoom_scale_normal = "50" }
assert_nothing_raised { @sv.zoom_scale_normal = 50 }
- assert_equal(@sv.zoom_scale_normal, 50)
+ assert_equal(50, @sv.zoom_scale_normal)
end
def test_zoom_scale_page_layout_view
assert_raise(ArgumentError) { @sv.zoom_scale_page_layout_view = "50" }
assert_nothing_raised { @sv.zoom_scale_page_layout_view = 50 }
- assert_equal(@sv.zoom_scale_page_layout_view, 50)
+ assert_equal(50, @sv.zoom_scale_page_layout_view)
end
def test_zoom_scale_sheet_layout_view
assert_raise(ArgumentError) { @sv.zoom_scale_sheet_layout_view = "50" }
assert_nothing_raised { @sv.zoom_scale_sheet_layout_view = 50 }
- assert_equal(@sv.zoom_scale_sheet_layout_view, 50)
+ assert_equal(50, @sv.zoom_scale_sheet_layout_view)
end
def test_to_xml
@@ -206,6 +206,7 @@ class TestSheetView < Test::Unit::TestCase
def test_add_selection
@sv.add_selection(:top_left, :active_cell => "A1")
+
assert_equal('A1', @sv.selections[:top_left].active_cell)
end
end
diff --git a/test/workbook/worksheet/tc_table.rb b/test/workbook/worksheet/tc_table.rb
index 7a2e5987..0ea0166f 100644
--- a/test/workbook/worksheet/tc_table.rb
+++ b/test/workbook/worksheet/tc_table.rb
@@ -10,19 +10,21 @@ class TestTable < Test::Unit::TestCase
end
def test_initialization
- assert(@ws.workbook.tables.empty?)
- assert(@ws.tables.empty?)
+ assert_empty(@ws.workbook.tables)
+ assert_empty(@ws.tables)
end
def test_table_style_info
table = @ws.add_table('A1:D5', :name => 'foo', :style_info => { :show_row_stripes => true, :name => "TableStyleMedium25" })
+
assert_equal('TableStyleMedium25', table.table_style_info.name)
- assert_equal(true, table.table_style_info.show_row_stripes)
+ assert(table.table_style_info.show_row_stripes)
end
def test_add_table
name = "test"
table = @ws.add_table("A1:D5", :name => name)
+
assert(table.is_a?(Axlsx::Table), "must create a table")
assert_equal(@ws.workbook.tables.last, table, "must be added to workbook table collection")
assert_equal(@ws.tables.last, table, "must be added to worksheet table collection")
@@ -31,25 +33,30 @@ class TestTable < Test::Unit::TestCase
def test_pn
@ws.add_table("A1:D5")
- assert_equal(@ws.tables.first.pn, "tables/table1.xml")
+
+ assert_equal("tables/table1.xml", @ws.tables.first.pn)
end
def test_rId
table = @ws.add_table("A1:D5")
+
assert_equal @ws.relationships.for(table).Id, table.rId
end
def test_index
@ws.add_table("A1:D5")
+
assert_equal(@ws.tables.first.index, @ws.workbook.tables.index(@ws.tables.first))
end
def test_relationships
- assert(@ws.relationships.empty?)
+ assert_empty(@ws.relationships)
@ws.add_table("A1:D5")
- assert_equal(@ws.relationships.size, 1, "adding a table adds a relationship")
+
+ assert_equal(1, @ws.relationships.size, "adding a table adds a relationship")
@ws.add_table("F1:J5")
- assert_equal(@ws.relationships.size, 2, "adding a table adds a relationship")
+
+ assert_equal(2, @ws.relationships.size, "adding a table adds a relationship")
end
def test_to_xml_string
@@ -61,7 +68,8 @@ class TestTable < Test::Unit::TestCase
errors.push error
puts error.message
end
- assert(errors.empty?, "error free validation")
+
+ assert_empty(errors, "error free validation")
end
def test_to_xml_string_for_special_characters
@@ -71,6 +79,7 @@ class TestTable < Test::Unit::TestCase
table = @ws.add_table("A1:D5")
doc = Nokogiri::XML(table.to_xml_string)
errors = doc.errors
- assert(errors.empty?, "invalid xml: #{errors.map(&:to_s).join(', ')}")
+
+ assert_empty(errors, "invalid xml: #{errors.map(&:to_s).join(', ')}")
end
end
diff --git a/test/workbook/worksheet/tc_table_style_info.rb b/test/workbook/worksheet/tc_table_style_info.rb
index f6606225..794073ef 100644
--- a/test/workbook/worksheet/tc_table_style_info.rb
+++ b/test/workbook/worksheet/tc_table_style_info.rb
@@ -17,6 +17,7 @@ class TestTableStyleInfo < Test::Unit::TestCase
def test_initialize
table_style = Axlsx::TableStyleInfo.new @options
+
@options.each do |key, value|
assert_equal(value, table_style.send(key.to_sym))
end
diff --git a/test/workbook/worksheet/tc_worksheet.rb b/test/workbook/worksheet/tc_worksheet.rb
index fde0611d..103d1641 100644
--- a/test/workbook/worksheet/tc_worksheet.rb
+++ b/test/workbook/worksheet/tc_worksheet.rb
@@ -8,14 +8,16 @@ class TestWorksheet < Test::Unit::TestCase
end
def test_pn
- assert_equal(@ws.pn, "worksheets/sheet1.xml")
+ assert_equal("worksheets/sheet1.xml", @ws.pn)
ws = @ws.workbook.add_worksheet
- assert_equal(ws.pn, "worksheets/sheet2.xml")
+
+ assert_equal("worksheets/sheet2.xml", ws.pn)
end
def test_name_is_html_encoded
@ws.name = '<foo> & <bar>'
- assert_equal(@ws.name, '&lt;foo&gt; &amp; &lt;bar&gt;')
+
+ assert_equal('&lt;foo&gt; &amp; &lt;bar&gt;', @ws.name)
end
def test_name_exception_on_invalid_character
@@ -59,7 +61,7 @@ class TestWorksheet < Test::Unit::TestCase
def test_page_margins_yeild
@ws.page_margins do |pm|
assert(pm.is_a?(Axlsx::PageMargins))
- assert(@ws.page_margins == pm)
+ assert_equal(@ws.page_margins, pm)
end
end
@@ -70,7 +72,7 @@ class TestWorksheet < Test::Unit::TestCase
def test_page_setup_yield
@ws.page_setup do |ps|
assert(ps.is_a?(Axlsx::PageSetup))
- assert(@ws.page_setup == ps)
+ assert_equal(@ws.page_setup, ps)
end
end
@@ -81,7 +83,7 @@ class TestWorksheet < Test::Unit::TestCase
def test_print_options_yield
@ws.print_options do |po|
assert(po.is_a?(Axlsx::PrintOptions))
- assert(@ws.print_options == po)
+ assert_equal(@ws.print_options, po)
end
end
@@ -92,7 +94,7 @@ class TestWorksheet < Test::Unit::TestCase
def test_header_footer_yield
@ws.header_footer do |hf|
assert(hf.is_a?(Axlsx::HeaderFooter))
- assert(@ws.header_footer == hf)
+ assert_equal(@ws.header_footer, hf)
end
end
@@ -108,7 +110,8 @@ class TestWorksheet < Test::Unit::TestCase
def test_no_autowidth
@ws.workbook.use_autowidth = false
@ws.add_row [1, 2, 3, 4]
- assert_equal(@ws.column_info[0].width, nil)
+
+ assert_nil(@ws.column_info[0].width)
end
def test_initialization_options
@@ -117,6 +120,7 @@ class TestWorksheet < Test::Unit::TestCase
print_options = { :grid_lines => true, :headings => true, :horizontal_centered => true, :vertical_centered => true }
header_footer = { :different_first => false, :different_odd_even => false, :odd_header => 'Header' }
optioned = @ws.workbook.add_worksheet(:name => 'bob', :page_margins => page_margins, :page_setup => page_setup, :print_options => print_options, :header_footer => header_footer)
+
page_margins.each_key do |key|
assert_equal(page_margins[key], optioned.page_margins.send(key))
end
@@ -129,7 +133,7 @@ class TestWorksheet < Test::Unit::TestCase
header_footer.each_key do |key|
assert_equal(header_footer[key], optioned.header_footer.send(key))
end
- assert_equal(optioned.name, 'bob')
+ assert_equal('bob', optioned.name)
end
# def test_use_gridlines
@@ -145,9 +149,10 @@ class TestWorksheet < Test::Unit::TestCase
# end
def test_rels_pn
- assert_equal(@ws.rels_pn, "worksheets/_rels/sheet1.xml.rels")
+ assert_equal("worksheets/_rels/sheet1.xml.rels", @ws.rels_pn)
ws = @ws.workbook.add_worksheet
- assert_equal(ws.rels_pn, "worksheets/_rels/sheet2.xml.rels")
+
+ assert_equal("worksheets/_rels/sheet2.xml.rels", ws.rels_pn)
end
def test_rId
@@ -161,11 +166,13 @@ class TestWorksheet < Test::Unit::TestCase
def test_dimension
@ws.add_row [1, 2, 3]
@ws.add_row [4, 5, 6]
- assert_equal @ws.dimension.sqref, "A1:C2"
+
+ assert_equal("A1:C2", @ws.dimension.sqref)
end
def test_dimension_with_empty_row
@ws.add_row
+
assert_equal "A1:AA200", @ws.dimension.sqref
end
@@ -175,30 +182,34 @@ class TestWorksheet < Test::Unit::TestCase
range = @ws["A1:C2"]
first_row = @ws[0]
last_row = @ws[1]
+
assert_equal(@ws.rows[0], first_row)
assert_equal(@ws.rows[1], last_row)
- assert_equal(range.size, 6)
+ assert_equal(6, range.size)
assert_equal(range.first, @ws.rows.first.cells.first)
assert_equal(range.last, @ws.rows.last.cells.last)
end
def test_add_row
- assert(@ws.rows.empty?, "sheet has no rows by default")
+ assert_empty(@ws.rows, "sheet has no rows by default")
r = @ws.add_row([1, 2, 3])
- assert_equal(@ws.rows.size, 1, "add_row adds a row")
+
+ assert_equal(1, @ws.rows.size, "add_row adds a row")
assert_equal(@ws.rows.first, r, "the row returned is the row added")
end
def test_add_chart
- assert(@ws.workbook.charts.empty?, "the sheet's workbook should not have any charts by default")
+ assert_empty(@ws.workbook.charts, "the sheet's workbook should not have any charts by default")
@ws.add_chart Axlsx::Pie3DChart
- assert_equal(@ws.workbook.charts.size, 1, "add_chart adds a chart to the workbook")
+
+ assert_equal(1, @ws.workbook.charts.size, "add_chart adds a chart to the workbook")
end
def test_add_page_break_with_string_cell_ref
- assert(@ws.row_breaks.empty?)
- assert(@ws.col_breaks.empty?)
+ assert_empty(@ws.row_breaks)
+ assert_empty(@ws.col_breaks)
@ws.add_page_break("B1")
+
assert_equal(1, @ws.row_breaks.size)
assert_equal(1, @ws.col_breaks.size)
end
@@ -207,23 +218,26 @@ class TestWorksheet < Test::Unit::TestCase
@ws.add_row [1, 2, 3, 4]
@ws.add_row [1, 2, 3, 4]
- assert(@ws.row_breaks.empty?)
- assert(@ws.col_breaks.empty?)
+ assert_empty(@ws.row_breaks)
+ assert_empty(@ws.col_breaks)
@ws.add_page_break(@ws.rows.last.cells[1])
+
assert_equal(1, @ws.row_breaks.size)
assert_equal(1, @ws.col_breaks.size)
end
def test_drawing
- assert @ws.drawing.nil?
+ assert_nil @ws.drawing
@ws.add_chart(Axlsx::Pie3DChart)
+
assert @ws.drawing.is_a?(Axlsx::Drawing)
end
def test_add_pivot_table
- assert(@ws.workbook.pivot_tables.empty?, "the sheet's workbook should not have any pivot tables by default")
+ assert_empty(@ws.workbook.pivot_tables, "the sheet's workbook should not have any pivot tables by default")
@ws.add_pivot_table 'G5:G6', 'A1:D:10'
- assert_equal(@ws.workbook.pivot_tables.size, 1, "add_pivot_tables adds a pivot_table to the workbook")
+
+ assert_equal(1, @ws.workbook.pivot_tables.size, "add_pivot_tables adds a pivot_table to the workbook")
end
def test_col_style
@@ -233,11 +247,11 @@ class TestWorksheet < Test::Unit::TestCase
@ws.add_row [1, 2, 3, 4]
@ws.col_style((1..2), 1, :row_offset => 1)
@ws.rows[(1..-1)].each do |r|
- assert_equal(r.cells[1].style, 1)
- assert_equal(r.cells[2].style, 1)
+ assert_equal(1, r.cells[1].style)
+ assert_equal(1, r.cells[2].style)
end
- assert_equal(@ws.rows.first.cells[1].style, 0)
- assert_equal(@ws.rows.first.cells[0].style, 0)
+ assert_equal(0, @ws.rows.first.cells[1].style)
+ assert_equal(0, @ws.rows.first.cells[0].style)
end
def test_col_style_with_empty_column
@@ -253,14 +267,16 @@ class TestWorksheet < Test::Unit::TestCase
@ws.add_row [1, 2, 3]
@ws.add_row [1, 2, 3, 4]
c = @ws.cols[1]
- assert_equal(c.size, 4)
- assert_equal(c[0].value, 2)
+
+ assert_equal(4, c.size)
+ assert_equal(2, c[0].value)
end
def test_cols_with_block
@ws.add_row [1, 2, 3]
@ws.add_row [1]
cols = @ws.cols { |_row, _column| :foo }
+
assert_equal(:foo, cols[1][1])
end
@@ -270,15 +286,16 @@ class TestWorksheet < Test::Unit::TestCase
@ws.add_row [1, 2, 3, 4]
@ws.add_row [1, 2, 3, 4]
@ws.row_style 1, 1, :col_offset => 1
+
@ws.rows[1].cells[(1..-1)].each do |c|
- assert_equal(c.style, 1)
+ assert_equal(1, c.style)
end
- assert_equal(@ws.rows[1].cells[0].style, 0)
- assert_equal(@ws.rows[2].cells[1].style, 0)
+ assert_equal(0, @ws.rows[1].cells[0].style)
+ assert_equal(0, @ws.rows[2].cells[1].style)
@ws.row_style(1..2, 1, :col_offset => 2)
@ws.rows[(1..2)].each do |r|
r.cells[(2..-1)].each do |c|
- assert_equal(c.style, 1)
+ assert_equal(1, c.style)
end
end
end
@@ -292,7 +309,8 @@ class TestWorksheet < Test::Unit::TestCase
def test_to_xml_string_dimensions
@ws.add_row [1, 2, 3]
doc = Nokogiri::XML(@ws.to_xml_string)
- assert_equal(doc.xpath('//xmlns:worksheet/xmlns:dimension[@ref="A1:C1"]').size, 1)
+
+ assert_equal(1, doc.xpath('//xmlns:worksheet/xmlns:dimension[@ref="A1:C1"]').size)
end
# def test_fit_to_page_assignation_does_nothing
@@ -315,20 +333,23 @@ class TestWorksheet < Test::Unit::TestCase
def test_to_xml_string_auto_fit_data
@ws.add_row [1, "two"]
doc = Nokogiri::XML(@ws.to_xml_string)
- assert_equal(doc.xpath('//xmlns:worksheet/xmlns:cols/xmlns:col').size, 2)
+
+ assert_equal(2, doc.xpath('//xmlns:worksheet/xmlns:cols/xmlns:col').size)
end
def test_to_xml_string_sheet_data
@ws.add_row [1, "two"]
doc = Nokogiri::XML(@ws.to_xml_string)
- assert_equal(doc.xpath('//xmlns:worksheet/xmlns:sheetData/xmlns:row').size, 1)
+
+ assert_equal(1, doc.xpath('//xmlns:worksheet/xmlns:sheetData/xmlns:row').size)
end
def test_to_xml_string_auto_filter
@ws.add_row [1, "two"]
@ws.auto_filter.range = "A1:B1"
doc = Nokogiri::XML(@ws.to_xml_string)
- assert_equal(doc.xpath('//xmlns:worksheet/xmlns:autoFilter[@ref="A1:B1"]').size, 1)
+
+ assert_equal(1, doc.xpath('//xmlns:worksheet/xmlns:autoFilter[@ref="A1:B1"]').size)
end
def test_to_xml_string_merge_cells
@@ -336,26 +357,30 @@ class TestWorksheet < Test::Unit::TestCase
@ws.merge_cells "A1:D1"
@ws.merge_cells "E1:F1"
doc = Nokogiri::XML(@ws.to_xml_string)
- assert_equal(doc.xpath('//xmlns:worksheet/xmlns:mergeCells/xmlns:mergeCell[@ref="A1:D1"]').size, 1)
- assert_equal(doc.xpath('//xmlns:worksheet/xmlns:mergeCells/xmlns:mergeCell[@ref="E1:F1"]').size, 1)
+
+ assert_equal(1, doc.xpath('//xmlns:worksheet/xmlns:mergeCells/xmlns:mergeCell[@ref="A1:D1"]').size)
+ assert_equal(1, doc.xpath('//xmlns:worksheet/xmlns:mergeCells/xmlns:mergeCell[@ref="E1:F1"]').size)
end
def test_to_xml_string_merge_cells_row
row = @ws.add_row [1, "two"]
@ws.merge_cells row
doc = Nokogiri::XML(@ws.to_xml_string)
- assert_equal(doc.xpath('//xmlns:worksheet/xmlns:mergeCells/xmlns:mergeCell[@ref="A1:B1"]').size, 1)
+
+ assert_equal(1, doc.xpath('//xmlns:worksheet/xmlns:mergeCells/xmlns:mergeCell[@ref="A1:B1"]').size)
end
def test_to_xml_string_row_breaks
@ws.add_page_break("A1")
doc = Nokogiri::XML(@ws.to_xml_string)
- assert_equal(doc.xpath('//xmlns:worksheet/xmlns:rowBreaks/xmlns:brk[@id="0"]').size, 1)
+
+ assert_equal(1, doc.xpath('//xmlns:worksheet/xmlns:rowBreaks/xmlns:brk[@id="0"]').size)
end
def test_to_xml_string_sheet_protection
@ws.sheet_protection.password = 'fish'
doc = Nokogiri::XML(@ws.to_xml_string)
+
assert(doc.xpath('//xmlns:sheetProtection'))
end
@@ -365,7 +390,8 @@ class TestWorksheet < Test::Unit::TestCase
pm.right = 7
end
doc = Nokogiri::XML(@ws.to_xml_string)
- assert_equal(doc.xpath('//xmlns:worksheet/xmlns:pageMargins[@left="9"][@right="7"]').size, 1)
+
+ assert_equal(1, doc.xpath('//xmlns:worksheet/xmlns:pageMargins[@left="9"][@right="7"]').size)
end
def test_to_xml_string_page_setup
@@ -374,7 +400,8 @@ class TestWorksheet < Test::Unit::TestCase
ps.scale = 80
end
doc = Nokogiri::XML(@ws.to_xml_string)
- assert_equal(doc.xpath('//xmlns:worksheet/xmlns:pageSetup[@paperWidth="210mm"][@scale="80"]').size, 1)
+
+ assert_equal(1, doc.xpath('//xmlns:worksheet/xmlns:pageSetup[@paperWidth="210mm"][@scale="80"]').size)
end
def test_to_xml_string_print_options
@@ -383,7 +410,8 @@ class TestWorksheet < Test::Unit::TestCase
po.horizontal_centered = true
end
doc = Nokogiri::XML(@ws.to_xml_string)
- assert_equal(doc.xpath('//xmlns:worksheet/xmlns:printOptions[@gridLines=1][@horizontalCentered=1]').size, 1)
+
+ assert_equal(1, doc.xpath('//xmlns:worksheet/xmlns:printOptions[@gridLines=1][@horizontalCentered=1]').size)
end
def test_to_xml_string_header_footer
@@ -393,12 +421,14 @@ class TestWorksheet < Test::Unit::TestCase
hf.odd_header = 'Test Header'
end
doc = Nokogiri::XML(@ws.to_xml_string)
- assert_equal(doc.xpath('//xmlns:worksheet/xmlns:headerFooter[@differentFirst=0][@differentOddEven=0]').size, 1)
+
+ assert_equal(1, doc.xpath('//xmlns:worksheet/xmlns:headerFooter[@differentFirst=0][@differentOddEven=0]').size)
end
def test_to_xml_string_drawing
@ws.add_chart Axlsx::Pie3DChart
doc = Nokogiri::XML(@ws.to_xml_string)
+
assert_equal @ws.send(:worksheet_drawing).relationship.Id, doc.xpath('//xmlns:worksheet/xmlns:drawing').first["r:id"]
end
@@ -407,14 +437,16 @@ class TestWorksheet < Test::Unit::TestCase
@ws.add_row [1, 2]
table = @ws.add_table "A1:B2"
doc = Nokogiri::XML(@ws.to_xml_string)
- assert_equal(doc.xpath('//xmlns:worksheet/xmlns:tableParts[@count="1"]').size, 1)
+
+ assert_equal(1, doc.xpath('//xmlns:worksheet/xmlns:tableParts[@count="1"]').size)
assert_equal table.rId, doc.xpath('//xmlns:worksheet/xmlns:tableParts/xmlns:tablePart').first["r:id"]
end
def test_to_xml_string
schema = Nokogiri::XML::Schema(File.open(Axlsx::SML_XSD))
doc = Nokogiri::XML(@ws.to_xml_string)
- assert(schema.validate(doc).map { |e| puts e.message; e }.empty?, "error free validation")
+
+ assert_empty(schema.validate(doc).map { |e| puts e.message; e }, "error free validation")
end
def test_styles
@@ -426,14 +458,16 @@ class TestWorksheet < Test::Unit::TestCase
Axlsx::trust_input = false
nasties = "\v\u2028\u0001\u0002\u0003\u0004\u0005\u0006\u0007\u0008\u001f"
@ws.add_row [nasties]
+
assert_equal(0, @ws.rows.last.cells.last.value.index("\v"))
- assert_equal(nil, @ws.to_xml_string.index("\v"))
+ assert_nil(@ws.to_xml_string.index("\v"))
Axlsx::trust_input = old
end
def test_to_xml_string_with_newlines
cell_with_newline = "foo\n\r\nbar"
@ws.add_row [cell_with_newline]
+
assert_equal("foo\n\r\nbar", @ws.rows.last.cells.last.value)
assert_not_nil(@ws.to_xml_string.index("foo\n\r\nbar"))
end
@@ -451,40 +485,50 @@ class TestWorksheet < Test::Unit::TestCase
@ws.add_pivot_table 'G5:G6', 'A1:D10'
schema = Nokogiri::XML::Schema(File.open(Axlsx::SML_XSD))
doc = Nokogiri::XML(@ws.to_xml_string)
- assert(schema.validate(doc).map { |e| puts e.message; e }.empty?, schema.validate(doc).map(&:message).join('\n'))
+
+ assert_empty(schema.validate(doc).map { |e| puts e.message; e }, schema.validate(doc).map(&:message).join('\n'))
end
def test_relationships
@ws.add_row [1, 2, 3]
- assert(@ws.relationships.empty?, "No Drawing relationship until you add a chart")
+
+ assert_empty(@ws.relationships, "No Drawing relationship until you add a chart")
@ws.add_chart Axlsx::Pie3DChart
- assert_equal(@ws.relationships.size, 1, "adding a chart creates the relationship")
+
+ assert_equal(1, @ws.relationships.size, "adding a chart creates the relationship")
@ws.add_chart Axlsx::Pie3DChart
- assert_equal(@ws.relationships.size, 1, "multiple charts still only result in one relationship")
+
+ assert_equal(1, @ws.relationships.size, "multiple charts still only result in one relationship")
@ws.add_comment :text => 'builder', :author => 'bob', :ref => @ws.rows.last.cells.last
- assert_equal(@ws.relationships.size, 3, "adding a comment adds 2 relationships")
+
+ assert_equal(3, @ws.relationships.size, "adding a comment adds 2 relationships")
@ws.add_comment :text => 'not that is a comment!', :author => 'travis', :ref => "A1"
- assert_equal(@ws.relationships.size, 3, "adding multiple comments in the same worksheet should not add any additional comment relationships")
+
+ assert_equal(3, @ws.relationships.size, "adding multiple comments in the same worksheet should not add any additional comment relationships")
@ws.add_pivot_table 'G5:G6', 'A1:D10'
- assert_equal(@ws.relationships.size, 4, "adding a pivot table adds 1 relationship")
+
+ assert_equal(4, @ws.relationships.size, "adding a pivot table adds 1 relationship")
end
def test_set_fixed_width_column
@ws.add_row ["mule", "donkey", "horse"], :widths => [20, :ignore, nil]
- assert(@ws.column_info.size == 3, "a data item for each column")
+
+ assert_equal(3, @ws.column_info.size, "a data item for each column")
assert_equal(20, @ws.column_info[0].width, "adding a row with fixed width updates :fixed attribute")
- assert_equal(@ws.column_info[1].width, nil, ":ignore does not set any data")
+ assert_nil(@ws.column_info[1].width, ":ignore does not set any data")
end
def test_fixed_height
@ws.add_row [1, 2, 3], :height => 40
+
assert_equal(40, @ws.rows[-1].height)
end
def test_set_column_width
@ws.add_row ["chasing windmills", "penut"]
@ws.column_widths nil, 0.5
- assert_equal(@ws.column_info[1].width, 0.5, 'eat my width')
+
+ assert_in_delta(@ws.column_info[1].width, 0.5, 0.001, 'eat my width')
assert_raise(ArgumentError, 'only accept unsigned ints') { @ws.column_widths 2, 7, -1 }
assert_raise(ArgumentError, 'only accept Integer or Float') { @ws.column_widths 2, 7, "-1" }
end
@@ -524,6 +568,7 @@ class TestWorksheet < Test::Unit::TestCase
assert(@ws.send(:protected_ranges).is_a?(Axlsx::SimpleTypedList))
assert_equal(0, @ws.send(:protected_ranges).size)
@ws.protect_range('A1:A3')
+
assert_equal('A1:A3', @ws.send(:protected_ranges).last.sqref)
end
@@ -540,8 +585,9 @@ class TestWorksheet < Test::Unit::TestCase
@ws.merge_cells "A1:A2"
@ws.merge_cells "B2:C3"
@ws.merge_cells @ws.rows.last.cells[(0..1)]
- assert_equal(@ws.send(:merged_cells).size, 3)
- assert_equal(@ws.send(:merged_cells).last, "A3:B3")
+
+ assert_equal(3, @ws.send(:merged_cells).size)
+ assert_equal("A3:B3", @ws.send(:merged_cells).last)
end
def test_merge_cells_sorts_correctly_by_row_when_given_array
@@ -549,37 +595,43 @@ class TestWorksheet < Test::Unit::TestCase
@ws.add_row [i]
end
@ws.merge_cells [@ws.rows[8].cells.first, @ws.rows[9].cells.first]
+
assert_equal "A9:A10", @ws.send(:merged_cells).first
end
def test_auto_filter
- assert(@ws.auto_filter.range.nil?)
+ assert_nil(@ws.auto_filter.range)
assert(@wb.defined_names.none? { |defined_name| defined_name.name == '_xlnm._FilterDatabase' })
assert_raise(ArgumentError) { @ws.auto_filter = 123 }
@ws.auto_filter.range = "A1:D9"
- assert_equal(@ws.auto_filter.range, "A1:D9")
+
+ assert_equal("A1:D9", @ws.auto_filter.range)
@ws.to_xml_string
+
assert(@wb.defined_names.any? { |defined_name| defined_name.name == '_xlnm._FilterDatabase' })
end
def test_auto_filter_assign
other_ws = @wb.add_worksheet
- assert(@ws.auto_filter.range.nil?)
- assert(other_ws.auto_filter.range.nil?)
+ assert_nil(@ws.auto_filter.range)
+ assert_nil(other_ws.auto_filter.range)
assert(@wb.defined_names.none? { |defined_name| defined_name.name == '_xlnm._FilterDatabase' })
assert_raise(ArgumentError) { @ws.auto_filter = 123 }
@ws.auto_filter = "A1:D9"
- assert_equal(@ws.auto_filter.range, "A1:D9")
+
+ assert_equal("A1:D9", @ws.auto_filter.range)
other_ws.auto_filter = "A1:D2"
- assert_equal(other_ws.auto_filter.range, "A1:D2")
+
+ assert_equal("A1:D2", other_ws.auto_filter.range)
@ws.to_xml_string
other_ws.to_xml_string
filter_database = @wb.defined_names.select { |defined_name| defined_name.name == '_xlnm._FilterDatabase' }
+
assert_equal(2, filter_database.size)
assert_equal(@ws.index, filter_database[0].local_sheet_id)
assert_equal(other_ws.index, filter_database[1].local_sheet_id)
@@ -589,23 +641,26 @@ class TestWorksheet < Test::Unit::TestCase
@ws.auto_filter.range = 'A1:D9'
@ws.auto_filter.add_column 0, :filters, :filter_items => [1]
doc = Nokogiri::XML(@ws.to_xml_string)
+
assert(doc.xpath('//sheetPr[@filterMode=1]'))
end
def test_outline_level_rows
3.times { @ws.add_row [1, 2, 3] }
@ws.outline_level_rows 0, 2
+
assert_equal(1, @ws.rows[0].outline_level)
- assert_equal(true, @ws.rows[2].hidden)
- assert_equal(true, @ws.sheet_view.show_outline_symbols)
+ assert(@ws.rows[2].hidden)
+ assert(@ws.sheet_view.show_outline_symbols)
end
def test_outline_level_columns
3.times { @ws.add_row [1, 2, 3] }
@ws.outline_level_columns 0, 2
+
assert_equal(1, @ws.column_info[0].outline_level)
- assert_equal(true, @ws.column_info[2].hidden)
- assert_equal(true, @ws.sheet_view.show_outline_symbols)
+ assert(@ws.column_info[2].hidden)
+ assert(@ws.sheet_view.show_outline_symbols)
end
def test_worksheet_does_not_get_added_to_workbook_on_initialize_failure
@@ -616,13 +671,15 @@ class TestWorksheet < Test::Unit::TestCase
def test_worksheet_only_includes_outline_pr_when_set
doc = Nokogiri::XML(@ws.to_xml_string)
- assert_equal(doc.xpath('//xmlns:worksheet/xmlns:sheetPr/xmlns:outlinePr').size, 0)
+
+ assert_equal(0, doc.xpath('//xmlns:worksheet/xmlns:sheetPr/xmlns:outlinePr').size)
@ws.sheet_pr.outline_pr.summary_below = false
@ws.sheet_pr.outline_pr.summary_right = true
doc = Nokogiri::XML(@ws.to_xml_string)
- assert_equal(doc.xpath('//xmlns:worksheet/xmlns:sheetPr/xmlns:outlinePr').size, 1)
- assert_equal(doc.xpath('//xmlns:worksheet/xmlns:sheetPr/xmlns:outlinePr[@summaryBelow=0][@summaryRight=1]').size, 1)
+
+ assert_equal(1, doc.xpath('//xmlns:worksheet/xmlns:sheetPr/xmlns:outlinePr').size)
+ assert_equal(1, doc.xpath('//xmlns:worksheet/xmlns:sheetPr/xmlns:outlinePr[@summaryBelow=0][@summaryRight=1]').size)
end
def test_merge_styles_1
@@ -706,7 +763,7 @@ class TestWorksheet < Test::Unit::TestCase
wb.apply_styles
- assert_equal true, wb.styles_applied
+ assert wb.styles_applied
assert_equal 12, wb.styles.style_index.count
assert_equal 12 + 2, wb.styles.style_index.keys.max
end
@@ -731,7 +788,7 @@ class TestWorksheet < Test::Unit::TestCase
wb.apply_styles
- assert_equal true, wb.styles_applied
+ assert wb.styles_applied
assert_equal 17, wb.styles.style_index.count
end
@@ -751,7 +808,7 @@ class TestWorksheet < Test::Unit::TestCase
wb.apply_styles
- assert_equal true, wb.styles_applied
+ assert wb.styles_applied
assert_equal 8, wb.styles.style_index.count
assert_equal 8, wb.styled_cells.count
end
@@ -771,7 +828,7 @@ class TestWorksheet < Test::Unit::TestCase
wb.apply_styles
- assert_equal true, wb.styles_applied
+ assert wb.styles_applied
assert_equal 6, wb.styles.style_index.count
assert_equal 6, wb.styled_cells.count
@@ -786,6 +843,7 @@ class TestWorksheet < Test::Unit::TestCase
sz: 11,
family: 1
}
+
assert_equal b2_cell_style, (wb.styles.style_index.values.find { |x| x == b2_cell_style })
d3_cell_style = {
@@ -799,6 +857,7 @@ class TestWorksheet < Test::Unit::TestCase
sz: 11,
family: 1
}
+
assert_equal d3_cell_style, (wb.styles.style_index.values.find { |x| x == d3_cell_style })
end
@@ -895,6 +954,7 @@ class TestWorksheet < Test::Unit::TestCase
def test_escape_formulas
@wb.escape_formulas = false
@ws = @wb.add_worksheet
+
assert_false @ws.escape_formulas
assert_false @ws.add_row(['']).cells.first.escape_formulas
assert_false @ws.add_row([''], escape_formulas: false).cells.first.escape_formulas
@@ -902,10 +962,12 @@ class TestWorksheet < Test::Unit::TestCase
assert_equal [true, false], @ws.add_row(['', ''], escape_formulas: [true, false]).cells.map(&:escape_formulas)
@ws = Axlsx::Worksheet.new(@wb)
+
assert_false @ws.escape_formulas
@wb.escape_formulas = true
@ws = @wb.add_worksheet
+
assert @ws.escape_formulas
assert @ws.add_row(['']).cells.first.escape_formulas
assert_false @ws.add_row([''], escape_formulas: false).cells.first.escape_formulas
@@ -913,9 +975,11 @@ class TestWorksheet < Test::Unit::TestCase
assert_equal [true, false], @ws.add_row(['', ''], escape_formulas: [true, false]).cells.map(&:escape_formulas)
@ws = Axlsx::Worksheet.new(@wb)
+
assert @ws.escape_formulas
@ws.escape_formulas = false
+
assert_false @ws.escape_formulas
assert_false @ws.add_row(['']).cells.first.escape_formulas
assert_false @ws.add_row([''], escape_formulas: false).cells.first.escape_formulas
@@ -923,6 +987,7 @@ class TestWorksheet < Test::Unit::TestCase
assert_equal [true, false], @ws.add_row(['', ''], escape_formulas: [true, false]).cells.map(&:escape_formulas)
@ws.escape_formulas = true
+
assert @ws.escape_formulas
assert @ws.add_row(['']).cells.first.escape_formulas
assert_false @ws.add_row([''], escape_formulas: false).cells.first.escape_formulas
diff --git a/test/workbook/worksheet/tc_worksheet_hyperlink.rb b/test/workbook/worksheet/tc_worksheet_hyperlink.rb
index 98b6937b..29e302a0 100644
--- a/test/workbook/worksheet/tc_worksheet_hyperlink.rb
+++ b/test/workbook/worksheet/tc_worksheet_hyperlink.rb
@@ -35,20 +35,22 @@ class TestWorksheetHyperlink < Test::Unit::TestCase
def test_to_xml_string_with_non_external
doc = Nokogiri::XML(@ws.to_xml_string)
- assert_equal(doc.xpath("//xmlns:hyperlink[@ref='#{@a.ref}']").size, 1)
- assert_equal(doc.xpath("//xmlns:hyperlink[@tooltip='#{@a.tooltip}']").size, 1)
- assert_equal(doc.xpath("//xmlns:hyperlink[@location='#{@a.location}']").size, 1)
- assert_equal(doc.xpath("//xmlns:hyperlink[@display='#{@a.display}']").size, 1)
- assert_equal(doc.xpath("//xmlns:hyperlink[@r:id]").size, 0)
+
+ assert_equal(1, doc.xpath("//xmlns:hyperlink[@ref='#{@a.ref}']").size)
+ assert_equal(1, doc.xpath("//xmlns:hyperlink[@tooltip='#{@a.tooltip}']").size)
+ assert_equal(1, doc.xpath("//xmlns:hyperlink[@location='#{@a.location}']").size)
+ assert_equal(1, doc.xpath("//xmlns:hyperlink[@display='#{@a.display}']").size)
+ assert_equal(0, doc.xpath("//xmlns:hyperlink[@r:id]").size)
end
def test_to_xml_stirng_with_external
@a.target = :external
doc = Nokogiri::XML(@ws.to_xml_string)
- assert_equal(doc.xpath("//xmlns:hyperlink[@ref='#{@a.ref}']").size, 1)
- assert_equal(doc.xpath("//xmlns:hyperlink[@tooltip='#{@a.tooltip}']").size, 1)
- assert_equal(doc.xpath("//xmlns:hyperlink[@display='#{@a.display}']").size, 1)
- assert_equal(doc.xpath("//xmlns:hyperlink[@location='#{@a.location}']").size, 0)
- assert_equal(doc.xpath("//xmlns:hyperlink[@r:id='#{@a.relationship.Id}']").size, 1)
+
+ assert_equal(1, doc.xpath("//xmlns:hyperlink[@ref='#{@a.ref}']").size)
+ assert_equal(1, doc.xpath("//xmlns:hyperlink[@tooltip='#{@a.tooltip}']").size)
+ assert_equal(1, doc.xpath("//xmlns:hyperlink[@display='#{@a.display}']").size)
+ assert_equal(0, doc.xpath("//xmlns:hyperlink[@location='#{@a.location}']").size)
+ assert_equal(1, doc.xpath("//xmlns:hyperlink[@r:id='#{@a.relationship.Id}']").size)
end
end