123456789_123456789_123456789_123456789_123456789_

Class: Test::Unit::Failure

Relationships & Source Files
Inherits: Object
Defined in: lib/test/unit/failure.rb

Overview

Encapsulates a test failure. Created by TestCase when an assertion fails.

Constant Summary

Class Method Summary

Instance Attribute Summary

Instance Method Summary

Constructor Details

.new(test_name, location, message, options = {}) ⇒ Failure

Creates a new Failure with the given location and message.

[ GitHub ]

  
# File 'lib/test/unit/failure.rb', line 23

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

Instance Attribute Details

#actual (readonly)

[ GitHub ]

  
# File 'lib/test/unit/failure.rb', line 15

attr_reader :expected, :actual, :user_message

#critical?Boolean (readonly)

[ GitHub ]

  
# File 'lib/test/unit/failure.rb', line 65

def critical?
  true
end

#expected (readonly)

[ GitHub ]

  
# File 'lib/test/unit/failure.rb', line 15

attr_reader :expected, :actual, :user_message

#inspected_actual (readonly)

[ GitHub ]

  
# File 'lib/test/unit/failure.rb', line 16

attr_reader :inspected_expected, :inspected_actual

#inspected_expected (readonly)

[ GitHub ]

  
# File 'lib/test/unit/failure.rb', line 16

attr_reader :inspected_expected, :inspected_actual

#location (readonly)

[ GitHub ]

  
# File 'lib/test/unit/failure.rb', line 13

attr_reader :test_name, :location, :message

#message (readonly)

[ GitHub ]

  
# File 'lib/test/unit/failure.rb', line 13

attr_reader :test_name, :location, :message

#method_name (readonly)

[ GitHub ]

  
# File 'lib/test/unit/failure.rb', line 14

attr_reader :method_name, :source_location

#source_location (readonly)

[ GitHub ]

  
# File 'lib/test/unit/failure.rb', line 14

attr_reader :method_name, :source_location

#test_name (readonly)

[ GitHub ]

  
# File 'lib/test/unit/failure.rb', line 13

attr_reader :test_name, :location, :message

#user_message (readonly)

[ GitHub ]

  
# File 'lib/test/unit/failure.rb', line 15

attr_reader :expected, :actual, :user_message

Instance Method Details

#compute_diff (private)

[ GitHub ]

  
# File 'lib/test/unit/failure.rb', line 74

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

#diff

[ GitHub ]

  
# File 'lib/test/unit/failure.rb', line 69

def diff
  @diff ||= compute_diff
end

#label

[ GitHub ]

  
# File 'lib/test/unit/failure.rb', line 41

def label
  LABEL
end

#long_display

Returns a verbose version of the error description.

[ GitHub ]

  
# File 'lib/test/unit/failure.rb', line 51

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

#short_display

Returns a brief version of the error description.

[ GitHub ]

  
# File 'lib/test/unit/failure.rb', line 46

def short_display
  "#@test_name: #{@message.split("\n")[0]}"
end

#single_character_display

Returns a single character representation of a failure.

[ GitHub ]

  
# File 'lib/test/unit/failure.rb', line 37

def single_character_display
  SINGLE_CHARACTER
end

#to_s

Overridden to return long_display.

[ GitHub ]

  
# File 'lib/test/unit/failure.rb', line 61

def to_s
  long_display
end