Module: StructuredWarnings::Test::Assertions
- Defined in:
- lib/structured_warnings/test/assertions.rb
Overview
This module ecapsulates all extensions to support test/unit
.
Instance Method Summary collapse
-
#assert_no_warn(*args) ⇒ Object
:call-seq: assert_no_warn(message = nil) {|| …} assert_no_warn(warning_class, message) {|| …} assert_no_warn(warning_instance) {|| …}.
-
#assert_warn(*args) ⇒ Object
:call-seq: assert_warn(message = nil) {|| …} assert_warn(warning_class, message) {|| …} assert_warn(warning_instance) {|| …}.
Instance Method Details
#assert_no_warn(*args) ⇒ Object
:call-seq:
assert_no_warn(message = nil) {|| ...}
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 StructuredWarnings::DeprecatedMethodWarning, 'used foo, use bar instead'
end
assert_no_warn(StructuredWarnings::StandardWarning) { foo } # passes
assert_no_warn(StructuredWarnings::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.
24 25 26 27 28 29 30 31 32 33 |
# File 'lib/structured_warnings/test/assertions.rb', line 24 def assert_no_warn(*args) warning, = parse_arguments(args) w = StructuredWarnings::Test::Warner.new StructuredWarnings::with_warner(w) do yield end assert_equal(false, w.warned?(warning, ), "<#{args_inspect(args)}> has been emitted.") end |
#assert_warn(*args) ⇒ Object
:call-seq:
assert_warn(message = nil) {|| ...}
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 StructuredWarnings::DeprecatedMethodWarning, 'used foo, use bar instead'
end
# passes
assert_warn(StructuredWarnings::DeprecatedMethodWarning) { foo }
assert_warn(StructuredWarnings::DeprecationWarning) { foo }
assert_warn() { foo }
assert_warn(StructuredWarnings::Base, 'used foo, use bar instead') { foo }
assert_warn(StructuredWarnings::Base, /use bar/) { foo }
assert_warn(StructuredWarnings::Base.new('used foo, use bar instead')) { foo }
# fails
assert_warn(StructuredWarnings::StandardWarning) { foo }
assert_warn(StructuredWarnings::Base, /deprecated/) { foo }
assert_warn(StructuredWarnings::Base.new) { foo }
Note: It is currently not possible to add a custom failure message.
62 63 64 65 66 67 68 69 70 71 |
# File 'lib/structured_warnings/test/assertions.rb', line 62 def assert_warn(*args) warning, = parse_arguments(args) w = StructuredWarnings::Test::Warner.new StructuredWarnings::with_warner(w) do yield end assert_equal(true, w.warned?(warning, ), "<#{args_inspect(args)}> has not been emitted.") end |