module StructuredWarnings::Test::Assertions
Public Instance Methods
assert_no_warn(message = nil) {|| ...}
click to toggle source
assert_no_warn(warning_class, message) {|| ...}
assert_no_warn(warning_instance) {|| ...}
Asserts that the given warning was not emmitted. It may be restricted to a certain subtree of warnings and/or message.
def foo warn DeprecatedMethodWarning, "used foo, use bar instead" bar end assert_no_warn(StandardWarning) { foo } # passes assert_no_warn(DeprecationWarning) { foo } # fails assert_no_warn() { foo } # fails
See #assert_warn for more examples.
Note: It is currently not possible to add a custom failure message.
# File lib/structured_warnings/test/assertions.rb, line 26 def assert_no_warn(*args) warning, message = parse_arguments(args) w = StructuredWarnings::Test::Warner.new StructuredWarnings::with_warner(w) do yield end assert_block("<#{args_inspect(args)}> has been emitted.") do !w.warned?(warning, message) end end
assert_warn(message = nil) {|| ...}
click to toggle source
assert_warn(warning_class, message) {|| ...}
assert_warn(warning_instance) {|| ...}
Asserts that the given warning was emmitted. It may be restricted to a certain subtree of warnings and/or message.
def foo warn DeprecatedMethodWarning, "used foo, use bar instead" bar end # passes assert_warn(DeprecatedMethodWarning) { foo } assert_warn(DeprecationWarning) { foo } assert_warn() { foo } assert_warn(Warning, "used foo, use bar instead") { foo } assert_warn(Warning, /use bar/) { foo } assert_warn(Warning.new("used foo, use bar instead")) { foo } # fails assert_warn(StandardWarning) { foo } assert_warn(Warning, /deprecated/) { foo } assert_warn(Warning.new) { foo }
Note: It is currently not possible to add a custom failure message.
# File lib/structured_warnings/test/assertions.rb, line 65 def assert_warn(*args) warning, message = parse_arguments(args) w = StructuredWarnings::Test::Warner.new StructuredWarnings::with_warner(w) do yield end assert_block("<#{args_inspect(args)}> has not been emitted.") do w.warned?(warning, message) end end
Private Instance Methods
args_inspect(args)
click to toggle source
# File lib/structured_warnings/test/assertions.rb, line 106 def args_inspect(args) args.map { |a| a.inspect }.join(", ") end
parse_arguments(args)
click to toggle source
# File lib/structured_warnings/test/assertions.rb, line 78 def parse_arguments(args) args = args.clone first = args.shift if first.is_a? Class and first <= Warning warning = first message = args.shift elsif first.is_a? Warning warning = first.class message = first.message elsif first.is_a? String warning = StandardWarning message = first else warning = Warning message = nil end unless args.empty? raise ArgumentError, "wrong number of arguments (#{args.size + 2} for 2)" end return warning, message end