2014-04-22 14:40:23 -04:00
|
|
|
module Mutant
|
|
|
|
# A class to expect some warning message raising on absence of unexpected warnings
|
|
|
|
class WarningExpectation
|
|
|
|
include Adamantium::Flat, Concord.new(:expected)
|
|
|
|
|
|
|
|
# Error raised on expectation miss
|
|
|
|
class ExpectationError < RuntimeError
|
2014-09-16 20:43:58 -04:00
|
|
|
include Concord.new(:unexpected, :expected)
|
2014-04-22 14:40:23 -04:00
|
|
|
|
|
|
|
# Return exception message
|
|
|
|
#
|
|
|
|
# @return [String]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
|
|
|
def message
|
2014-09-16 20:43:58 -04:00
|
|
|
"Unexpected warnings: #{unexpected.inspect}, expected: #{expected.inspect}"
|
2014-04-22 14:40:23 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# Execute blocks with warning expectations
|
|
|
|
#
|
|
|
|
# @return [self]
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
#
|
|
|
|
def execute(&block)
|
|
|
|
warnings = WarningFilter.use do
|
|
|
|
block.call
|
|
|
|
end
|
2014-06-30 19:46:17 -04:00
|
|
|
|
|
|
|
missing = expected - warnings
|
2014-04-22 14:40:23 -04:00
|
|
|
unexpected = warnings - expected
|
2014-06-30 19:46:17 -04:00
|
|
|
|
|
|
|
if unexpected.any?
|
2014-09-16 20:43:58 -04:00
|
|
|
fail ExpectationError.new(unexpected, expected)
|
2014-04-22 14:40:23 -04:00
|
|
|
end
|
2014-06-30 19:46:17 -04:00
|
|
|
|
|
|
|
if missing.any?
|
|
|
|
$stderr.puts("Expected but missing warnings: #{missing}")
|
|
|
|
end
|
|
|
|
|
2014-04-22 14:40:23 -04:00
|
|
|
self
|
|
|
|
end
|
|
|
|
|
|
|
|
end # WarningExpectation
|
|
|
|
end # Mutant
|