Sha256: 354deb435549101fb779347df787ed7867f1602834b97ec35d329052b98687c3

Contents?: true

Size: 1.04 KB

Versions: 5

Compression:

Stored size: 1.04 KB

Contents

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
      include Concord.new(:unexpected, :expected)

      # Return exception message
      #
      # @return [String]
      #
      # @api private
      #
      def message
        "Unexpected warnings: #{unexpected.inspect}, expected: #{expected.inspect}"
      end
    end

    # Execute blocks with warning expectations
    #
    # @return [self]
    #
    # @api private
    #
    def execute(&block)
      warnings = WarningFilter.use do
        block.call
      end

      missing    = expected - warnings
      unexpected = warnings - expected

      if unexpected.any?
        fail ExpectationError.new(unexpected, expected)
      end

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

      self
    end

  end # WarningExpectation
end # Mutant

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
mutant-0.6.7 lib/mutant/warning_expectation.rb
mutant-0.6.6 lib/mutant/warning_expectation.rb
mutant-0.6.5 lib/mutant/warning_expectation.rb
mutant-0.6.4 lib/mutant/warning_expectation.rb
mutant-0.6.3 lib/mutant/warning_expectation.rb