\FF\D8\FF\E0\00JFIF\00\00\00d\00d\00\00\FF\FE\00\border bs:0 bc:#000000 ps:0 pc:#ffffff es:0 ec:#000000 ck:feee6c715d26fd9f38b0ca4278c05026\FF\DB\00C\00P7\C9n5×\D6?\BDê\9Ds\EBp\9F[`8m\B7)o\B5\E8\E6I\99\FE3]]A2\BA\8Cw\D6E\93\\DEv\C8\009\F2\F1NI?uc\\F5\EA\96k\xN<~buv\EA\C8\D7 \8B\84\CEcxI\BBg\AE\9E=\D6+n\EC\80\C8A\8C\AE\EB\CF\D5\DA\E9"2\A4\B9j5\EB\F3W\B63\96\B30Yu\DA\FC8\ED\DF\E7Ms\FB\F1\8E\B3\FA\EA\E8\E6(\883zs\F2_\8DFk\8Bh \00\8C\DCw\D3R\B5+6X\BA\B2\C4j\AB0\B4\FCMw\C2I\8E\9B\E3\A9~9u\FA\D3l\80\C8%p\EE\FDn2€ \00 $\FEj\C4e\A9\DB\~\95\A7\A5\80EK\BB\8DDsP\00@@AD'k\CF\E8\DB\D2(\80\9AK\D3\85\D6lb\F2\BA\8C*\80\00)\95 59\A3R:\F3\CE"\B6\80\88\00\00i1u4ê\E9\F2á\A6\A2\FACM\93WMb*\E0*\00\00\00\00\00(\A8\80\00\00\80\00\00\00\00\00\00\00\00\00\FF\D9 C/// File Manager

File Manager

Path: /opt/chef.upgrade/embedded/lib/ruby/gems/2.3.0/gems/test-unit-3.1.5/lib/test/unit/

Viewing File: failure.rb

#--
#
# Author:: Nathaniel Talbott.
# Copyright:: Copyright (c) 2000-2002 Nathaniel Talbott. All rights reserved.
# License:: Ruby license.

module Test
  module Unit

    # Encapsulates a test failure. Created by Test::Unit::TestCase
    # when an assertion fails.
    class Failure
      attr_reader :test_name, :location, :message
      attr_reader :method_name, :source_location
      attr_reader :expected, :actual, :user_message
      attr_reader :inspected_expected, :inspected_actual

      SINGLE_CHARACTER = 'F'
      LABEL = "Failure"

      # Creates a new Failure with the given location and
      # message.
      def initialize(test_name, location, message, options={})
        @test_name = test_name
        @location = location
        @message = message
        @method_name = options[:method_name]
        @source_location = options[:source_location]
        @expected = options[:expected]
        @actual = options[:actual]
        @inspected_expected = options[:inspected_expected]
        @inspected_actual = options[:inspected_actual]
        @user_message = options[:user_message]
      end
      
      # Returns a single character representation of a failure.
      def single_character_display
        SINGLE_CHARACTER
      end

      def label
        LABEL
      end

      # Returns a brief version of the error description.
      def short_display
        "#@test_name: #{@message.split("\n")[0]}"
      end

      # Returns a verbose version of the error description.
      def long_display
        if location.size == 1
          location_display = location[0].sub(/\A(.+:\d+).*/, ' [\\1]')
        else
          location_display = "\n    [#{location.join("\n     ")}]"
        end
        "#{label}:\n#@test_name#{location_display}:\n#@message"
      end

      # Overridden to return long_display.
      def to_s
        long_display
      end

      def critical?
        true
      end

      def diff
        @diff ||= compute_diff
      end

      private
      def compute_diff
        Assertions::AssertionMessage.delayed_diff(@expected, @actual).inspect
      end
    end

    module FailureHandler
      class << self
        def included(base)
          base.exception_handler(:handle_assertion_failed_error)
        end
      end

      # Report a failure.
      #
      # This is a public API for developers who extend test-unit.
      #
      # @param message [String] The description about the failure.
      # @param backtrace [Array<String>] The backtrace for the failure.
      # @option options [Object] :expected
      #   The expected value of the assertion.
      # @option options [Object] :actual
      #   The actual value of the assertion.
      # @option options [String] :inspected_expected
      #   The inspected expected value of the assertion.
      #   It is used for diff between expected and actual of the failure.
      # @option options [String] :inspected_actual
      #   The inspected actual value of the assertion.
      #   It is used for diff between expected and actual of the failure.
      # @option options [String] :user_message
      #   The message of the assertion from user.
      # @option options [String] :method_name (@method_name)
      #   The method name of the test.
      # @option options [Array<String, Integer>] :source_location
      #   The location where the test is defined. It is the same
      #   format as Proc#source_location. That is, it's an array of
      #   path and and line number where the test definition is
      #   started.
      # @return [void]
      def add_failure(message, backtrace, options={})
        default_options = {
          :method_name => @method_name,
          :source_location => self[:source_location],
        }
        failure = Failure.new(name, filter_backtrace(backtrace), message,
                              default_options.merge(options))
        current_result.add_failure(failure)
      end

      private
      def handle_assertion_failed_error(exception)
        return false unless exception.is_a?(AssertionFailedError)
        problem_occurred
        add_failure(exception.message, exception.backtrace,
                    :expected => exception.expected,
                    :actual => exception.actual,
                    :inspected_expected => exception.inspected_expected,
                    :inspected_actual => exception.inspected_actual,
                    :user_message => exception.user_message)
        true
      end
    end

    module TestResultFailureSupport
      attr_reader :failures

      # Records a Test::Unit::Failure.
      def add_failure(failure)
        @failures << failure
        notify_fault(failure)
        notify_changed
      end

      # Returns the number of failures this TestResult has
      # recorded.
      def failure_count
        @failures.size
      end

      def failure_occurred?
        not @failures.empty?
      end

      private
      def initialize_containers
        super
        @failures = []
        @summary_generators << :failure_summary
        @problem_checkers << :failure_occurred?
      end

      def failure_summary
        "#{failure_count} failures"
      end
    end
  end
end