Class: Mutant::WarningExpectation

Inherits:
Object
  • Object
show all
Includes:
Adamantium::Flat
Defined in:
lib/mutant/warning_expectation.rb

Overview

A class to expect some warning message raising on absence of unexpected warnings

Defined Under Namespace

Classes: ExpectationError

Instance Method Summary collapse

Instance Method Details

#execute(&block) ⇒ self

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Execute blocks with warning expectations

Returns:

  • (self)


27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/mutant/warning_expectation.rb', line 27

def execute(&block)
  warnings = WarningFilter.use do
    block.call
  end

  missing    = expected - warnings
  unexpected = warnings - expected

  if unexpected.any?
    fail ExpectationError, unexpected
  end

  if missing.any?
    $stderr.puts("Expected but missing warnings: #{missing}")
  end

  self
end