diff options
| author | Koza <[email protected]> | 2022-07-11 10:16:15 +0200 |
|---|---|---|
| committer | Stefan Daschek <[email protected]> | 2022-07-12 13:11:24 +0200 |
| commit | b9b59ab3e115cde48252fb7f7eec741c20a31ea4 (patch) | |
| tree | ef29dcc7cece9571ecca6db930679e70d540ed39 /test/support | |
| parent | f39e9068803f5cf28a339c67e92ab976c30b00f1 (diff) | |
| download | caxlsx-b9b59ab3e115cde48252fb7f7eec741c20a31ea4.tar.gz caxlsx-b9b59ab3e115cde48252fb7f7eec741c20a31ea4.zip | |
Move "capture warning" test helper to its own module
Diffstat (limited to 'test/support')
| -rw-r--r-- | test/support/capture_warnings.rb | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/test/support/capture_warnings.rb b/test/support/capture_warnings.rb new file mode 100644 index 00000000..60d4f24d --- /dev/null +++ b/test/support/capture_warnings.rb @@ -0,0 +1,20 @@ +module CaptureWarnings + def capture_warnings(&block) + # Turn off warnings with setting $VERBOSE to nil + original_verbose = $VERBOSE + $VERBOSE = nil + + # Redefine warn to redirect warning into our array + original_warn = Kernel.instance_method(:warn) + warnings = [] + Kernel.send(:define_method, :warn) { |string| warnings << string } + block.call + + # Revert to the original warn method and set back $VERBOSE to previous value + Kernel.send(:define_method, :warn, original_warn) + $VERBOSE = original_verbose + + # Give back the received warnings + warnings + end +end |
