diff options
| author | Geremia Taglialatela <[email protected]> | 2023-04-13 13:13:34 +0200 |
|---|---|---|
| committer | Geremia Taglialatela <[email protected]> | 2023-05-03 16:05:17 +0200 |
| commit | 350f7ae9a04f3d39c099cc54f7c04bf31f385d96 (patch) | |
| tree | e84af2a70d3b18a0b94c784338faf48215c9c8a8 /test/content_type | |
| parent | e81036b76e734ab03fac31faafb9732f6b3b2928 (diff) | |
| download | caxlsx-350f7ae9a04f3d39c099cc54f7c04bf31f385d96.tar.gz caxlsx-350f7ae9a04f3d39c099cc54f7c04bf31f385d96.zip | |
Add RuboCop Minitest
Diffstat (limited to 'test/content_type')
| -rw-r--r-- | test/content_type/tc_content_type.rb | 25 | ||||
| -rw-r--r-- | test/content_type/tc_default.rb | 5 | ||||
| -rw-r--r-- | test/content_type/tc_override.rb | 5 |
3 files changed, 24 insertions, 11 deletions
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 |
