Class: Test::Unit::Assertions::AssertionMessage (Ruby 2.7.5)
Description: Class : Test::Unit::Assertions::AssertionMessage - Ruby 2.7.5

### Home Classes Methods

### In Files

- test-unit-3.3.4/lib/test/unit/assertions.rb

### Parent

Object

### Namespace

- CLASS Test::Unit::Assertions::AssertionMessage::ArrayInspector
- CLASS Test::Unit::Assertions::AssertionMessage::DelayedLiteral
- CLASS Test::Unit::Assertions::AssertionMessage::HashInspector
- CLASS Test::Unit::Assertions::AssertionMessage::Inspector
- CLASS Test::Unit::Assertions::AssertionMessage::Literal
- CLASS Test::Unit::Assertions::AssertionMessage::MaybeContainer
- CLASS Test::Unit::Assertions::AssertionMessage::NumericInspector
- CLASS Test::Unit::Assertions::AssertionMessage::Template

### Methods

- ::convert
- ::delayed_diff
- ::delayed_literal
- ::diff_target_string?
- ::ensure_diffable_string
- ::literal
- ::max_diff_target_string_size
- ::max_diff_target_string_size=
- ::maybe_container
- ::new
- ::prepare_for_diff
- #convert
- #template
- #to_s
- #user_message

### Included Modules

- Test::Unit::Util::BacktraceFilter

### Class/Module Index

Quicksearch

- Object
- Test
- Test::Unit
- Test::Unit::AssertionFailedError
- Test::Unit::Assertions
- Test::Unit::Assertions::AssertExceptionHelper
- Test::Unit::Assertions::AssertExceptionHelper::WrappedException
- Test::Unit::Assertions::AssertionMessage
- Test::Unit::Assertions::AssertionMessage::ArrayInspector
- Test::Unit::Assertions::AssertionMessage::DelayedLiteral
- Test::Unit::Assertions::AssertionMessage::HashInspector
- Test::Unit::Assertions::AssertionMessage::Inspector
- Test::Unit::Assertions::AssertionMessage::Literal
- Test::Unit::Assertions::AssertionMessage::MaybeContainer
- Test::Unit::Assertions::AssertionMessage::NumericInspector
- Test::Unit::Assertions::AssertionMessage::Template
- Test::Unit::Assertions::ThrowTagExtractor
- Test::Unit::Attribute
- Test::Unit::Attribute::BaseClassMethods
- Test::Unit::Attribute::ClassMethods
- Test::Unit::Attribute::StringifyKeyHash
- Test::Unit::AttributeMatcher
- Test::Unit::AutoRunner
- Test::Unit::AutoRunner::StopOnFailureListener
- Test::Unit::AutoRunnerLoader
- Test::Unit::CodeSnippetFetcher
- Test::Unit::Collector
- Test::Unit::Collector::Descendant
- Test::Unit::Collector::Dir
- Test::Unit::Collector::Load
- Test::Unit::Collector::ObjectSpace
- Test::Unit::Collector::XML
- Test::Unit::Collector::XML::Listener
- Test::Unit::Color
- Test::Unit::Color::Error
- Test::Unit::Color::ParseError
- Test::Unit::ColorScheme
- Test::Unit::Data
- Test::Unit::Data::ClassMethods
- Test::Unit::Data::ClassMethods::Loader
- Test::Unit::DataSets
- Test::Unit::Diff
- Test::Unit::Diff::Differ
- Test::Unit::Diff::ReadableDiffer
- Test::Unit::Diff::SequenceMatcher
- Test::Unit::Diff::UTF8Line
- Test::Unit::Diff::UnifiedDiffer
- Test::Unit::Error
- Test::Unit::ErrorHandler
- Test::Unit::ExceptionHandler
- Test::Unit::ExceptionHandler::ClassMethods
- Test::Unit::Failure
- Test::Unit::FailureHandler
- Test::Unit::FaultLocationDetector
- Test::Unit::Fixture
- Test::Unit::Fixture::ClassMethods
- Test::Unit::Fixture::Fixture
- Test::Unit::Fixture::HookPoint
- Test::Unit::MixColor
- Test::Unit::Notification
- Test::Unit::NotificationHandler
- Test::Unit::NotifiedError
- Test::Unit::NullResultContainerInitializer
- Test::Unit::Omission
- Test::Unit::OmissionHandler
- Test::Unit::OmittedError
- Test::Unit::PendedError
- Test::Unit::Pending
- Test::Unit::PendingHandler
- Test::Unit::Priority
- Test::Unit::Priority::Checker
- Test::Unit::Priority::ClassMethods
- Test::Unit::TestCase
- Test::Unit::TestCase::InternalData
- Test::Unit::TestCaseNotificationSupport
- Test::Unit::TestCaseOmissionSupport
- Test::Unit::TestCasePendingSupport
- Test::Unit::TestResult
- Test::Unit::TestResultErrorSupport
- Test::Unit::TestResultFailureSupport
- Test::Unit::TestResultNotificationSupport
- Test::Unit::TestResultOmissionSupport
- Test::Unit::TestResultPendingSupport
- Test::Unit::TestSuite
- Test::Unit::UI
- Test::Unit::UI::Console
- Test::Unit::UI::Console::ColorizedReadableDiffer
- Test::Unit::UI::Console::OutputLevel
- Test::Unit::UI::Console::TestRunner
- Test::Unit::UI::Emacs
- Test::Unit::UI::Emacs::TestRunner
- Test::Unit::UI::TestRunner
- Test::Unit::UI::TestRunnerMediator
- Test::Unit::UI::TestRunnerUtilities
- Test::Unit::UI::XML
- Test::Unit::UI::XML::TestRunner
- Test::Unit::Util
- Test::Unit::Util::BacktraceFilter
- Test::Unit::Util::MethodOwnerFinder
- Test::Unit::Util::Observable
- Test::Unit::Util::Output
- Test::Unit::Util::ProcWrapper

No matching classes.

# Test::Unit::Assertions::AssertionMessage

### Constants

MAX_DIFF_TARGET_STRING_SIZE

### Attributes

use_pp[RW]

### Public Class Methods

convert(object) click to toggle source

                   # File test-unit-3.3.4/lib/test/unit/assertions.rb, line 1793
    def convert(object)
      if object.is_a?(Exception)
        object = AssertExceptionHelper::WrappedException.new(object)
      end
      inspector = Inspector.new(object)
      if use_pp
        begin
          require "pp" unless defined?(PP)
          begin
            return PP.pp(inspector, String.new).chomp
          rescue NameError
          end
        rescue LoadError
          self.use_pp = false
        end
      end
      inspector.inspect
    end

delayed_diff(from, to) click to toggle source

                   # File test-unit-3.3.4/lib/test/unit/assertions.rb, line 1770
    def delayed_diff(from, to)
      delayed_literal do
        from, to = prepare_for_diff(from, to)

        diff = "" if from.nil? or to.nil?
        diff ||= Diff.readable(from, to)
        if /^[-+]/ !~ diff
          diff = ""
        elsif /^[ ?]/ =~ diff or /(?:.*\n){2,}/ =~ diff
          diff = "\n\ndiff:\n#{diff}"
        else
          diff = ""
        end

        if Diff.need_fold?(diff)
          folded_diff = Diff.folded_readable(from, to)
          diff += "\n\nfolded diff:\n#{folded_diff}"
        end

        diff
      end
    end

delayed_literal(&block) click to toggle source

                   # File test-unit-3.3.4/lib/test/unit/assertions.rb, line 1711
    def delayed_literal(&block)
      DelayedLiteral.new(block)
    end

diff_target_string?(string) click to toggle source

                   # File test-unit-3.3.4/lib/test/unit/assertions.rb, line 1739
    def diff_target_string?(string)
      if string.respond_to?(:bytesize)
        string.bytesize < max_diff_target_string_size
      else
        string.size < max_diff_target_string_size
      end
    end

ensure_diffable_string(string) click to toggle source

                   # File test-unit-3.3.4/lib/test/unit/assertions.rb, line 1747
    def ensure_diffable_string(string)
      if string.respond_to?(:encoding) and
          !string.encoding.ascii_compatible?
        string = string.dup.force_encoding("ASCII-8BIT")
      end
      string
    end

literal(value) click to toggle source

                   # File test-unit-3.3.4/lib/test/unit/assertions.rb, line 1707
    def literal(value)
      Literal.new(value)
    end

max_diff_target_string_size() click to toggle source

                   # File test-unit-3.3.4/lib/test/unit/assertions.rb, line 1720
    def max_diff_target_string_size
      return @@max_diff_target_string_size if @@max_diff_target_string_size

      size = ENV["TEST_UNIT_MAX_DIFF_TARGET_STRING_SIZE"]
      if size
        begin
          size = Integer(size)
        rescue ArgumentError
          size = nil
        end
      end
      size || MAX_DIFF_TARGET_STRING_SIZE
    end

max_diff_target_string_size=(size) click to toggle source

                   # File test-unit-3.3.4/lib/test/unit/assertions.rb, line 1735
    def max_diff_target_string_size=(size)
      @@max_diff_target_string_size = size
    end

maybe_container(value, &formatter) click to toggle source

                   # File test-unit-3.3.4/lib/test/unit/assertions.rb, line 1715
    def maybe_container(value, &formatter)
      MaybeContainer.new(value, &formatter)
    end

new(user_message, template_string, parameters) click to toggle source

                   # File test-unit-3.3.4/lib/test/unit/assertions.rb, line 2077
    def initialize(user_message, template_string, parameters)
      @user_message = user_message
      @template_string = template_string
      @parameters = parameters
    end

prepare_for_diff(from, to) click to toggle source

                   # File test-unit-3.3.4/lib/test/unit/assertions.rb, line 1755
    def prepare_for_diff(from, to)
      if !from.is_a?(String) or !to.is_a?(String)
        from = convert(from)
        to = convert(to)
      end

      if diff_target_string?(from) and diff_target_string?(to)
        from = ensure_diffable_string(from)
        to = ensure_diffable_string(to)
        [from, to]
      else
        [nil, nil]
      end
    end

### Public Instance Methods

convert(object) click to toggle source

                   # File test-unit-3.3.4/lib/test/unit/assertions.rb, line 2083
    def convert(object)
      self.class.convert(object)
    end

template() click to toggle source

                   # File test-unit-3.3.4/lib/test/unit/assertions.rb, line 2087
    def template
      @template ||= Template.create(@template_string)
    end

to_s() click to toggle source

                   # File test-unit-3.3.4/lib/test/unit/assertions.rb, line 2098
    def to_s
      message_parts = []
      head = user_message
      if head and not head.empty?
        message_parts << add_period(head)
      end
      tail = template.result(@parameters.collect{|e| convert(e)})
      message_parts << tail unless(tail.empty?)
      message_parts.join("\n")
    end

user_message() click to toggle source

                   # File test-unit-3.3.4/lib/test/unit/assertions.rb, line 2091
    def user_message
      return nil unless @user_message
      message = @user_message
      message = message.call if message.respond_to?(:call)
      message.to_s
    end