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/tc_axlsx.rb | |
| parent | e81036b76e734ab03fac31faafb9732f6b3b2928 (diff) | |
| download | caxlsx-350f7ae9a04f3d39c099cc54f7c04bf31f385d96.tar.gz caxlsx-350f7ae9a04f3d39c099cc54f7c04bf31f385d96.zip | |
Add RuboCop Minitest
Diffstat (limited to 'test/tc_axlsx.rb')
| -rw-r--r-- | test/tc_axlsx.rb | 37 |
1 files changed, 26 insertions, 11 deletions
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 <''>" 1'!$A$1:$B$1") + + assert_equal("'Sheet <''>" 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 |
