summaryrefslogtreecommitdiffhomepage
path: root/test/tc_package.rb
diff options
context:
space:
mode:
authorRyan Winograd <[email protected]>2020-08-20 09:16:23 -0500
committerRyan Winograd <[email protected]>2020-08-20 09:19:26 -0500
commit759f1261000f125a47e11b58905afc4fea8b72e7 (patch)
tree6e12b219ab5cc5671f57be5e5e1ffd3a603b724a /test/tc_package.rb
parente7673f431813cde7aab2d032a4417d4ddeeb9342 (diff)
downloadcaxlsx-759f1261000f125a47e11b58905afc4fea8b72e7.tar.gz
caxlsx-759f1261000f125a47e11b58905afc4fea8b72e7.zip
Deprecate using `#serialize` with boolean argument
Update `Axlsx::Package#serialize` to accept the second argument as a boolean (being deprecated) or an options hash. In order to transition toward using keyword arguments for `Axlsx::Package#serialize`, change the documented method signature to an options hash, while still parsing the second argument as `confirm_valid` if a boolean is provided (in which case we also warn the user that a boolean argument is deprecated).
Diffstat (limited to 'test/tc_package.rb')
-rw-r--r--test/tc_package.rb26
1 files changed, 23 insertions, 3 deletions
diff --git a/test/tc_package.rb b/test/tc_package.rb
index 18c08f5c..a6e31f88 100644
--- a/test/tc_package.rb
+++ b/test/tc_package.rb
@@ -133,21 +133,21 @@ class TestPackage < Test::Unit::TestCase
end
def test_serialization_with_zip_command
- @package.serialize(@fname, false, zip_command: "zip")
+ @package.serialize(@fname, zip_command: "zip")
assert_zip_file_matches_package(@fname, @package)
File.delete(@fname)
end
def test_serialization_with_zip_command_and_absolute_path
fname = "#{Dir.tmpdir}/#{@fname}"
- @package.serialize(fname, false, zip_command: "zip")
+ @package.serialize(fname, zip_command: "zip")
assert_zip_file_matches_package(fname, @package)
File.delete(fname)
end
def test_serialization_with_invalid_zip_command
assert_raises Axlsx::ZipCommand::ZipError do
- @package.serialize(@fname, false, zip_command: "invalid_zip")
+ @package.serialize(@fname, zip_command: "invalid_zip")
end
end
@@ -156,6 +156,26 @@ class TestPackage < Test::Unit::TestCase
package.send(:parts).each{ |part| zf.get_entry(part[:entry]) }
end
+ def test_serialization_with_deprecated_argument
+ 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"
+ end
+
+ def capture_warnings(&block)
+ original_warn = Kernel.method(:warn)
+ warnings = []
+ Kernel.define_method(:warn){ |string| warnings << string }
+ block.call
+ original_verbose = $VERBOSE
+ $VERBOSE = nil
+ Kernel.define_method(:warn, &original_warn)
+ $VERBOSE = original_verbose
+ warnings
+ end
+
# See comment for Package#zip_entry_for_part
def test_serialization_creates_identical_files_at_any_time_if_created_at_is_set
@package.core.created = Time.now