summaryrefslogtreecommitdiffhomepage
path: root/test
diff options
context:
space:
mode:
authorRyan Winograd <[email protected]>2020-08-20 19:14:02 -0500
committerRyan Winograd <[email protected]>2020-08-20 19:14:02 -0500
commitdcce5db8a653a099d3c9a18cb84baa7b989199fd (patch)
tree23c8548fd119bff160496ed0cab975aaf44d63b5 /test
parent759f1261000f125a47e11b58905afc4fea8b72e7 (diff)
downloadcaxlsx-dcce5db8a653a099d3c9a18cb84baa7b989199fd.tar.gz
caxlsx-dcce5db8a653a099d3c9a18cb84baa7b989199fd.zip
Fix for older rubies?
Diffstat (limited to 'test')
-rw-r--r--test/tc_package.rb24
1 files changed, 15 insertions, 9 deletions
diff --git a/test/tc_package.rb b/test/tc_package.rb
index a6e31f88..1574c8b8 100644
--- a/test/tc_package.rb
+++ b/test/tc_package.rb
@@ -165,15 +165,21 @@ class TestPackage < Test::Unit::TestCase
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
+ # Only capture warnings on versions of ruby that expose `:define_method` as
+ # a public method
+ if Kernel.respond_to?(:define_method)
+ 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
+ else
+ &block.call
+ end
end
# See comment for Package#zip_entry_for_part