summaryrefslogtreecommitdiffhomepage
path: root/test/support
diff options
context:
space:
mode:
Diffstat (limited to 'test/support')
-rw-r--r--test/support/capture_warnings.rb20
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