Sha256: 8711bab146ebb21ae4bb70d183196adda9ffb16a67b3bd2a3092ac448bb2fb70

Contents?: true

Size: 1.51 KB

Versions: 36

Compression:

Stored size: 1.51 KB

Contents

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

module Test
  module Unit

    # Thrown by Test::Unit::Assertions when an assertion fails.
    class AssertionFailedError < StandardError
      @debug_on_failure = false
      class << self
        def debug_on_failure=(boolean)
          @debug_on_failure = boolean
        end

        def debug_on_failure?
          @debug_on_failure
        end
      end

      attr_accessor :expected, :actual, :user_message
      attr_accessor :inspected_expected, :inspected_actual
      def initialize(message=nil, options=nil)
        options ||= {}
        @expected = options[:expected]
        @actual = options[:actual]
        @inspected_expected = options[:inspected_expected]
        @inspected_actual = options[:inspected_actual]
        @user_message = options[:user_message]
        super(message)
        debug_on_failure
      end

      private
      def debug_on_failure
        return unless self.class.debug_on_failure?

        begin
          require "debug"
        rescue LoadError
          return
        end

        return unless binding.respond_to?(:break)

        frames = caller(0)
        pre = nil
        Util::BacktraceFilter.filter_backtrace(frames).each do |location|
          frame_index = frames.index(location)
          next if frame_index.nil?
          pre = "frame #{frame_index}"
          break
        end
        binding.break(pre: pre)
      end
    end
  end
end

Version data entries

36 entries across 36 versions & 9 rubygems

Version Path
es_cli-0.1.0 vendor/bundle/ruby/3.1.0/gems/test-unit-3.6.7/lib/test/unit/assertion-failed-error.rb
test-unit-3.6.7 lib/test/unit/assertion-failed-error.rb
test-unit-3.6.6 lib/test/unit/assertion-failed-error.rb
test-unit-3.6.5 lib/test/unit/assertion-failed-error.rb
test-unit-3.6.4 lib/test/unit/assertion-failed-error.rb
test-unit-3.6.3 lib/test/unit/assertion-failed-error.rb
fluent-plugin-nuopenlineage-light-0.1.0 vendor/bundle/ruby/3.3.0/gems/test-unit-3.6.2/lib/test/unit/assertion-failed-error.rb
fluent-plugin-openlineage-light-0.1.4 vendor/bundle/ruby/3.3.0/gems/test-unit-3.6.2/lib/test/unit/assertion-failed-error.rb
fluent-plugin-openlineage-light-0.1.3 vendor/bundle/ruby/3.3.0/gems/test-unit-3.6.2/lib/test/unit/assertion-failed-error.rb
fluent-plugin-openlineage-0.1.0 vendor/bundle/ruby/3.3.0/gems/test-unit-3.6.2/lib/test/unit/assertion-failed-error.rb
tinymce-rails-7.1.2 vendor/bundle/ruby/3.3.0/gems/test-unit-3.6.2/lib/test/unit/assertion-failed-error.rb
test-unit-3.6.2 lib/test/unit/assertion-failed-error.rb
test-unit-3.6.1 lib/test/unit/assertion-failed-error.rb
test-unit-3.6.0 lib/test/unit/assertion-failed-error.rb
test-unit-3.5.9 lib/test/unit/assertion-failed-error.rb
test-unit-3.5.8 lib/test/unit/assertion-failed-error.rb
fluent-plugin-google-cloud-logging-on-prem-0.1.0 vendor/ruby/3.1.0/gems/test-unit-3.5.7/lib/test/unit/assertion-failed-error.rb
test-unit-3.5.7 lib/test/unit/assertion-failed-error.rb
test-unit-3.5.6 lib/test/unit/assertion-failed-error.rb
tdiary-5.2.4 vendor/bundle/ruby/3.1.0/gems/test-unit-3.5.5/lib/test/unit/assertion-failed-error.rb