Class: Test::Unit::Assertions::AssertionMessage
Relationships & Source Files | |
Namespace Children | |
Classes:
| |
Super Chains via Extension / Inclusion / Inheritance | |
Instance Chain:
|
|
Inherits: | Object |
Defined in: | lib/test/unit/assertions.rb |
Constant Summary
-
MAX_DIFF_TARGET_STRING_SIZE =
# File 'lib/test/unit/assertions.rb', line 17121000
::Test::Unit::Util::BacktraceFilter - Included
Class Attribute Summary
Class Method Summary
Instance Method Summary
::Test::Unit::Util::BacktraceFilter - Included
Constructor Details
.new(head, template_string, parameters) ⇒ AssertionMessage
# File 'lib/test/unit/assertions.rb', line 2070
def initialize(head, template_string, parameters) @head = head @template_string = template_string @parameters = parameters end
Class Attribute Details
.max_diff_target_string_size (rw)
[ GitHub ]# File 'lib/test/unit/assertions.rb', line 1713
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) (rw)
[ GitHub ]# File 'lib/test/unit/assertions.rb', line 1728
def max_diff_target_string_size=(size) @@max_diff_target_string_size = size end
.use_pp (rw)
[ GitHub ]# File 'lib/test/unit/assertions.rb', line 1698
attr_accessor :use_pp
Class Method Details
.convert(object)
[ GitHub ]# File 'lib/test/unit/assertions.rb', line 1786
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, '').chomp rescue NameError end rescue LoadError self.use_pp = false end end inspector.inspect end
.delayed_diff(from, to)
[ GitHub ]# File 'lib/test/unit/assertions.rb', line 1763
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)
[ GitHub ]# File 'lib/test/unit/assertions.rb', line 1704
def delayed_literal(&block) DelayedLiteral.new(block) end
.diff_target_string?(string) ⇒ Boolean
# File 'lib/test/unit/assertions.rb', line 1732
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)
[ GitHub ]# File 'lib/test/unit/assertions.rb', line 1740
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)
[ GitHub ].maybe_container(value, &formatter)
[ GitHub ]# File 'lib/test/unit/assertions.rb', line 1708
def maybe_container(value, &formatter) MaybeContainer.new(value, &formatter) end
.prepare_for_diff(from, to)
[ GitHub ]# File 'lib/test/unit/assertions.rb', line 1748
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
Instance Method Details
#add_period(string)
[ GitHub ]# File 'lib/test/unit/assertions.rb', line 2084
def add_period(string) (string =~ /\.\Z/ ? string : string + '.') end
#convert(object)
[ GitHub ]# File 'lib/test/unit/assertions.rb', line 2076
def convert(object) self.class.convert(object) end
#template
[ GitHub ]#to_s
[ GitHub ]# File 'lib/test/unit/assertions.rb', line 2088
def to_s = [] if (@head) head = @head head = head.call if head.respond_to?(:call) head = head.to_s unless(head.empty?) << add_period(head) end end tail = template.result(@parameters.collect{|e| convert(e)}) << tail unless(tail.empty?) .join("\n") end