diff options
| author | Geremia Taglialatela <[email protected]> | 2023-04-13 13:09:14 +0200 |
|---|---|---|
| committer | Geremia Taglialatela <[email protected]> | 2023-05-03 16:05:17 +0200 |
| commit | e81036b76e734ab03fac31faafb9732f6b3b2928 (patch) | |
| tree | 4a5944faddeac7aa574a26955d41f4901fccc038 /test/workbook | |
| parent | 194e852d4f61d7c1acf4cd79df86bee43d84028a (diff) | |
| download | caxlsx-e81036b76e734ab03fac31faafb9732f6b3b2928.tar.gz caxlsx-e81036b76e734ab03fac31faafb9732f6b3b2928.zip | |
Fix offenses to non-production code
- Lint/AmbiguousBlockAssociation
- Lint/AmbiguousOperatorPrecedence
- Lint/EmptyBlock
- Lint/RedundantSplatExpansion
- Lint/RedundantStringCoercion
- Lint/SymbolConversion
- Lint/UnusedBlockArgument
- Style/BlockDelimiters
- Style/CommentAnnotation
- Style/EachForSimpleLoop
- Style/EmptyMethod
- Style/ExpandPathArguments
- Style/FileWrite
- Style/GlobalStdStream (UNSAFE)
- Style/HashEachMethods (UNSAFE)
- Style/NestedParenthesizedCalls
- Style/NilComparison
- Style/NumericLiteralPrefix (manually fixed)
- Style/ParallelAssignment
- Style/PreferredHashMethods (UNSAFE)
- Style/RedundantInterpolation (UNSAFE)
- Style/RedundantParentheses (UNSAFE)
- Style/RegexpLiteral
- Style/RescueStandardError
- Style/SpecialGlobalVars (UNSAFE)
- Style/SymbolProc (UNSAFE)
- Style/ZeroLengthPredicate (UNSAFE)
Diffstat (limited to 'test/workbook')
| -rw-r--r-- | test/workbook/tc_shared_strings_table.rb | 4 | ||||
| -rw-r--r-- | test/workbook/tc_workbook.rb | 3 | ||||
| -rw-r--r-- | test/workbook/worksheet/tc_cell.rb | 8 | ||||
| -rw-r--r-- | test/workbook/worksheet/tc_col.rb | 2 | ||||
| -rw-r--r-- | test/workbook/worksheet/tc_comment.rb | 2 | ||||
| -rw-r--r-- | test/workbook/worksheet/tc_comments.rb | 4 | ||||
| -rw-r--r-- | test/workbook/worksheet/tc_data_validation.rb | 4 | ||||
| -rw-r--r-- | test/workbook/worksheet/tc_date_time_converter.rb | 6 | ||||
| -rw-r--r-- | test/workbook/worksheet/tc_page_setup.rb | 6 | ||||
| -rw-r--r-- | test/workbook/worksheet/tc_rich_text.rb | 4 | ||||
| -rw-r--r-- | test/workbook/worksheet/tc_sheet_protection.rb | 2 | ||||
| -rw-r--r-- | test/workbook/worksheet/tc_sheet_view.rb | 4 | ||||
| -rw-r--r-- | test/workbook/worksheet/tc_table_style_info.rb | 2 | ||||
| -rw-r--r-- | test/workbook/worksheet/tc_worksheet.rb | 36 |
14 files changed, 43 insertions, 44 deletions
diff --git a/test/workbook/tc_shared_strings_table.rb b/test/workbook/tc_shared_strings_table.rb index cb7557c6..775f6ae7 100644 --- a/test/workbook/tc_shared_strings_table.rb +++ b/test/workbook/tc_shared_strings_table.rb @@ -39,7 +39,7 @@ class TestSharedStringsTable < Test::Unit::TestCase puts error.message errors << error end - assert_equal(errors.size, 0, "sharedStirngs.xml Invalid" + errors.map { |e| e.message }.to_s) + assert_equal(errors.size, 0, "sharedStirngs.xml Invalid" + errors.map(&:message).to_s) end def test_remove_control_characters_in_xml_serialization @@ -47,7 +47,7 @@ class TestSharedStringsTable < Test::Unit::TestCase @p.workbook.worksheets[0].add_row [nasties] # test that the nasty string was added to the shared strings - assert @p.workbook.shared_strings.unique_cells.has_key?(nasties) + assert @p.workbook.shared_strings.unique_cells.key?(nasties) # test that none of the control characters are in the XML output for shared strings assert_no_match(/#{Axlsx::CONTROL_CHARS}/, @p.workbook.shared_strings.to_xml_string) diff --git a/test/workbook/tc_workbook.rb b/test/workbook/tc_workbook.rb index 443dd392..f0a7ac19 100644 --- a/test/workbook/tc_workbook.rb +++ b/test/workbook/tc_workbook.rb @@ -6,8 +6,7 @@ class TestWorkbook < Test::Unit::TestCase @wb = p.workbook end - def teardown - end + def teardown; end def test_worksheet_users_xml_space sheet = @wb.add_worksheet(:name => 'foo') diff --git a/test/workbook/worksheet/tc_cell.rb b/test/workbook/worksheet/tc_cell.rb index 907ce97e..959304c8 100644 --- a/test/workbook/worksheet/tc_cell.rb +++ b/test/workbook/worksheet/tc_cell.rb @@ -99,7 +99,7 @@ class TestCell < Test::Unit::TestCase 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(:float, @row.add_cell(1.0 / 10**7).type, 'properly identify exponential floats as float type') + 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') @@ -112,7 +112,7 @@ class TestCell < Test::Unit::TestCase end def test_col_ref - # TODO move to axlsx spec + # TODO: move to axlsx spec assert_equal(Axlsx.col_ref(0), "A") end @@ -133,7 +133,7 @@ class TestCell < Test::Unit::TestCase 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, 1.0 / (10**6)), :float) assert_equal(@c.send(:cell_type_from_value, Axlsx::RichText.new), :richtext) assert_equal(:iso_8601, @c.send(:cell_type_from_value, '2008-08-30T01:45:36.123+09:00')) end @@ -520,7 +520,7 @@ class TestCell < Test::Unit::TestCase end def test_to_xml - # TODO This could use some much more stringent testing related to the xml content generated! + # TODO: This could use some much more stringent testing related to the xml content generated! @ws.add_row [Time.now, Date.today, true, 1, 1.0, "text", "=sum(A1:A2)", "2013-01-13T13:31:25.123"] @ws.rows.last.cells[5].u = true diff --git a/test/workbook/worksheet/tc_col.rb b/test/workbook/worksheet/tc_col.rb index 908e9931..986c6bb7 100644 --- a/test/workbook/worksheet/tc_col.rb +++ b/test/workbook/worksheet/tc_col.rb @@ -86,6 +86,6 @@ class TestCol < Test::Unit::TestCase assert_equal(@col.style, nil) @col.style = 1 assert_equal(@col.style, 1) - # TODO check that the style specified is actually in the styles xfs collection + # TODO: check that the style specified is actually in the styles xfs collection end end diff --git a/test/workbook/worksheet/tc_comment.rb b/test/workbook/worksheet/tc_comment.rb index cbd93f01..8d5df652 100644 --- a/test/workbook/worksheet/tc_comment.rb +++ b/test/workbook/worksheet/tc_comment.rb @@ -53,7 +53,7 @@ class TestComment < Test::Unit::TestCase 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.to_s}']").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) end diff --git a/test/workbook/worksheet/tc_comments.rb b/test/workbook/worksheet/tc_comments.rb index 276dd3b0..cb2e3741 100644 --- a/test/workbook/worksheet/tc_comments.rb +++ b/test/workbook/worksheet/tc_comments.rb @@ -16,7 +16,7 @@ class TestComments < Test::Unit::TestCase def test_add_comment assert_equal(@ws.comments.size, 2) - assert_raise(ArgumentError) { @ws.comments.add_comment() } + 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') } @@ -49,7 +49,7 @@ class TestComments < Test::Unit::TestCase end assert_equal(0, errors.length) - # TODO figure out why these xpath expressions dont work! + # TODO: figure out why these xpath expressions dont work! # assert(doc.xpath("//comments")) # assert_equal(doc.xpath("//xmlns:author").size, @ws.comments.authors.size) # assert_equal(doc.xpath("//comment").size, @ws.comments.size) diff --git a/test/workbook/worksheet/tc_data_validation.rb b/test/workbook/worksheet/tc_data_validation.rb index ff92b847..aac2019d 100644 --- a/test/workbook/worksheet/tc_data_validation.rb +++ b/test/workbook/worksheet/tc_data_validation.rb @@ -44,14 +44,14 @@ class TestDataValidation < Test::Unit::TestCase end def test_boolean_attribute_validation - @boolean_options.each do |key, value| + @boolean_options.each do |key, _value| assert_raise(ArgumentError, "#{key} must be boolean") { @dv.send("#{key}=".to_sym, 'A') } assert_nothing_raised { @dv.send("#{key}=".to_sym, true) } end end def test_string_attribute_validation - @string_options.each do |key, value| + @string_options.each do |key, _value| assert_raise(ArgumentError, "#{key} must be string") { @dv.send("#{key}=".to_sym, :symbol) } assert_nothing_raised { @dv.send("#{key}=".to_sym, "foo") } end diff --git a/test/workbook/worksheet/tc_date_time_converter.rb b/test/workbook/worksheet/tc_date_time_converter.rb index 9c813486..891fa80f 100644 --- a/test/workbook/worksheet/tc_date_time_converter.rb +++ b/test/workbook/worksheet/tc_date_time_converter.rb @@ -7,7 +7,7 @@ class TestDateTimeConverter < Test::Unit::TestCase Time.parse "1893-08-05" Time.parse "9999-12-31T23:59:59Z" true - rescue + rescue StandardError false end end @@ -114,8 +114,8 @@ class TestDateTimeConverter < Test::Unit::TestCase local = Time.parse "2012-01-01 09:00:00 +0900" assert_equal local, utc - assert_equal Axlsx::DateTimeConverter::time_to_serial(local) - local.utc_offset.to_f / 86400, Axlsx::DateTimeConverter::time_to_serial(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) + 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_page_setup.rb b/test/workbook/worksheet/tc_page_setup.rb index b7a36600..6dca8b0a 100644 --- a/test/workbook/worksheet/tc_page_setup.rb +++ b/test/workbook/worksheet/tc_page_setup.rb @@ -59,18 +59,18 @@ class TestPageSetup < Test::Unit::TestCase end def test_default_fit_to_page? - assert(@ps.fit_to_width == nil && @ps.fit_to_height == nil) + assert(@ps.fit_to_width.nil? && @ps.fit_to_height.nil?) assert(@ps.fit_to_page? == false) end def test_with_height_fit_to_page? - assert(@ps.fit_to_width == nil && @ps.fit_to_height == nil) + assert(@ps.fit_to_width.nil? && @ps.fit_to_height.nil?) @ps.set(:fit_to_height => 1) assert(@ps.fit_to_page?) end def test_with_width_fit_to_page? - assert(@ps.fit_to_width == nil && @ps.fit_to_height == nil) + assert(@ps.fit_to_width.nil? && @ps.fit_to_height.nil?) @ps.set(:fit_to_width => 1) assert(@ps.fit_to_page?) end diff --git a/test/workbook/worksheet/tc_rich_text.rb b/test/workbook/worksheet/tc_rich_text.rb index 34117b1b..6c9627d4 100644 --- a/test/workbook/worksheet/tc_rich_text.rb +++ b/test/workbook/worksheet/tc_rich_text.rb @@ -7,7 +7,7 @@ class RichText < Test::Unit::TestCase p.workbook.styles.add_style :sz => 20 @rt = Axlsx::RichText.new b = true - (0..26).each do |r| + 27.times do |r| @rt.add_run "run #{r}, ", :b => (b = !b), :i => !b end @row = @ws.add_row [@rt] @@ -17,7 +17,7 @@ class RichText < Test::Unit::TestCase def test_initialize assert_equal(@c.value, @rt) rt_direct = Axlsx::RichText.new('hi', :i => true) - rt_indirect = Axlsx::RichText.new() + 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) diff --git a/test/workbook/worksheet/tc_sheet_protection.rb b/test/workbook/worksheet/tc_sheet_protection.rb index b14f3e03..e8f18df5 100644 --- a/test/workbook/worksheet/tc_sheet_protection.rb +++ b/test/workbook/worksheet/tc_sheet_protection.rb @@ -44,7 +44,7 @@ class TestSheetProtection < Test::Unit::TestCase end def test_boolean_attribute_validation - @boolean_options.each do |key, value| + @boolean_options.each do |key, _value| assert_raise(ArgumentError, "#{key} must be boolean") { @sp.send("#{key}=".to_sym, 'A') } assert_nothing_raised { @sp.send("#{key}=".to_sym, true) } assert_nothing_raised { @sp.send("#{key}=".to_sym, true) } diff --git a/test/workbook/worksheet/tc_sheet_view.rb b/test/workbook/worksheet/tc_sheet_view.rb index 0f0986cf..18bb3308 100644 --- a/test/workbook/worksheet/tc_sheet_view.rb +++ b/test/workbook/worksheet/tc_sheet_view.rb @@ -45,14 +45,14 @@ class TestSheetView < Test::Unit::TestCase end def test_boolean_attribute_validation - @boolean_options.each do |key, value| + @boolean_options.each do |key, _value| assert_raise(ArgumentError, "#{key} must be boolean") { @sv.send("#{key}=".to_sym, 'A') } assert_nothing_raised { @sv.send("#{key}=".to_sym, true) } end end def test_string_attribute_validation - @string_options.each do |key, value| + @string_options.each do |key, _value| assert_raise(ArgumentError, "#{key} must be string") { @sv.send("#{key}=".to_sym, :symbol) } assert_nothing_raised { @sv.send("#{key}=".to_sym, "foo") } end diff --git a/test/workbook/worksheet/tc_table_style_info.rb b/test/workbook/worksheet/tc_table_style_info.rb index 3d71dc9b..f6606225 100644 --- a/test/workbook/worksheet/tc_table_style_info.rb +++ b/test/workbook/worksheet/tc_table_style_info.rb @@ -24,7 +24,7 @@ class TestTableStyleInfo < Test::Unit::TestCase def test_boolean_properties table_style = Axlsx::TableStyleInfo.new - @options.keys.each do |key| + @options.each_key do |key| assert_nothing_raised { table_style.send("#{key.to_sym}=", true) } assert_raises(ArgumentError) { table_style.send(key.to_sym, 'foo') } end diff --git a/test/workbook/worksheet/tc_worksheet.rb b/test/workbook/worksheet/tc_worksheet.rb index d83cdf91..fde0611d 100644 --- a/test/workbook/worksheet/tc_worksheet.rb +++ b/test/workbook/worksheet/tc_worksheet.rb @@ -45,7 +45,7 @@ class TestWorksheet < Test::Unit::TestCase def test_exception_if_name_too_long_because_of_multibyte_characters four_characters_for_excel = "\u{1F1EB 1F1F7}" # french flag emoji assert_raises(ArgumentError, "name too long!") do - @ws.name = four_characters_for_excel + "x" * 28 + @ws.name = four_characters_for_excel + ("x" * 28) end assert_nothing_raised { @ws.name = "#{four_characters_for_excel}123456789012345678901234567" } assert_nothing_raised { @ws.name = "123456789012345678901234567890…" } @@ -53,45 +53,45 @@ class TestWorksheet < Test::Unit::TestCase end def test_page_margins - assert(@ws.page_margins.is_a? Axlsx::PageMargins) + assert(@ws.page_margins.is_a?(Axlsx::PageMargins)) end def test_page_margins_yeild @ws.page_margins do |pm| - assert(pm.is_a? Axlsx::PageMargins) + assert(pm.is_a?(Axlsx::PageMargins)) assert(@ws.page_margins == pm) end end def test_page_setup - assert(@ws.page_setup.is_a? Axlsx::PageSetup) + assert(@ws.page_setup.is_a?(Axlsx::PageSetup)) end def test_page_setup_yield @ws.page_setup do |ps| - assert(ps.is_a? Axlsx::PageSetup) + assert(ps.is_a?(Axlsx::PageSetup)) assert(@ws.page_setup == ps) end end def test_print_options - assert(@ws.print_options.is_a? Axlsx::PrintOptions) + assert(@ws.print_options.is_a?(Axlsx::PrintOptions)) end def test_print_options_yield @ws.print_options do |po| - assert(po.is_a? Axlsx::PrintOptions) + assert(po.is_a?(Axlsx::PrintOptions)) assert(@ws.print_options == po) end end def test_header_footer - assert(@ws.header_footer.is_a? Axlsx::HeaderFooter) + assert(@ws.header_footer.is_a?(Axlsx::HeaderFooter)) end def test_header_footer_yield @ws.header_footer do |hf| - assert(hf.is_a? Axlsx::HeaderFooter) + assert(hf.is_a?(Axlsx::HeaderFooter)) assert(@ws.header_footer == hf) end end @@ -117,16 +117,16 @@ 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.keys.each do |key| + page_margins.each_key do |key| assert_equal(page_margins[key], optioned.page_margins.send(key)) end - page_setup.keys.each do |key| + page_setup.each_key do |key| assert_equal(page_setup[key], optioned.page_setup.send(key)) end - print_options.keys.each do |key| + print_options.each_key do |key| assert_equal(print_options[key], optioned.print_options.send(key)) end - header_footer.keys.each do |key| + header_footer.each_key do |key| assert_equal(header_footer[key], optioned.header_footer.send(key)) end assert_equal(optioned.name, 'bob') @@ -215,7 +215,7 @@ class TestWorksheet < Test::Unit::TestCase end def test_drawing - assert @ws.drawing == nil + assert @ws.drawing.nil? @ws.add_chart(Axlsx::Pie3DChart) assert @ws.drawing.is_a?(Axlsx::Drawing) end @@ -260,7 +260,7 @@ class TestWorksheet < Test::Unit::TestCase def test_cols_with_block @ws.add_row [1, 2, 3] @ws.add_row [1] - cols = @ws.cols { |row, column| :foo } + cols = @ws.cols { |_row, _column| :foo } assert_equal(:foo, cols[1][1]) end @@ -451,7 +451,7 @@ 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 { |e| e.message }.join('\n')) + assert(schema.validate(doc).map { |e| puts e.message; e }.empty?, schema.validate(doc).map(&:message).join('\n')) end def test_relationships @@ -786,7 +786,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 } + assert_equal b2_cell_style, (wb.styles.style_index.values.find { |x| x == b2_cell_style }) d3_cell_style = { border: { @@ -799,7 +799,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 } + assert_equal d3_cell_style, (wb.styles.style_index.values.find { |x| x == d3_cell_style }) end def test_mixed_borders_1 |
