Class: StructuredWarnings::Test::Warner
- Defined in:
- lib/structured_warnings/test/warner.rb
Overview
This warner is used in Assertions#assert_warn and Assertions#assert_no_warn blocks. It captures all warnings in format and provides access to them using the warned? method.
Instance Method Summary collapse
-
#format(warning, message, options, call_stack) ⇒ Object
Overrides the public interface of StructuredWarnings::Warner.
-
#warned?(warning, message = nil) ⇒ Boolean
Returns true if any warning or a subclass of warning was emitted.
Instance Method Details
#format(warning, message, options, call_stack) ⇒ Object
Overrides the public interface of StructuredWarnings::Warner. This method always returns nil to avoid warnings on stdout during assert_warn and assert_no_warn blocks.
8 9 10 11 |
# File 'lib/structured_warnings/test/warner.rb', line 8 def format(warning, , , call_stack) given_warnings << warning.new() nil end |
#warned?(warning, message = nil) ⇒ Boolean
Returns true if any warning or a subclass of warning was emitted.
14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/structured_warnings/test/warner.rb', line 14 def warned?(warning, = nil) case when Regexp given_warnings.any? {|w| w.is_a?(warning) && w. =~ } when String given_warnings.any? {|w| w.is_a?(warning) && w. == } when nil given_warnings.any? {|w| w.is_a?(warning)} else raise ArgumentError, "Unkown argument type for 'message': #{.class.inspect}" end end |