Module StructuredWarnings::Test::Assertions
In: lib/structured_warnings/test/assertions.rb

This module ecapsulates all extensions to support test/unit.

Methods

Public Instance methods

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'
    bar
  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.

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'
    bar
  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.

[Validate]