class StructuredWarnings::Test::Warner
This warner is used in StructuredWarnings::Test::Assertions#assert_warn and StructuredWarnings::Test::Assertions#assert_no_warn blocks. It captures all warnings in format and provides access to them using the warned? method.
Public Instance Methods
format(warning, message, call_stack)
click to toggle source
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.
# File lib/structured_warnings/test/warner.rb, line 10 def format(warning, message, call_stack) given_warnings << warning.new(message) nil end
warned?(warning, message = nil)
click to toggle source
Returns true if any warning or a subclass of warning was emitted.
# File lib/structured_warnings/test/warner.rb, line 16 def warned?(warning, message = nil) case message when Regexp given_warnings.any? {|w| w.is_a?(warning) && w.message =~ message} when String given_warnings.any? {|w| w.is_a?(warning) && w.message == message} when nil given_warnings.any? {|w| w.is_a?(warning)} else raise ArgumentError, "Unkown argument for 'message'" end end