Class: Test::Unit::Assertions::AssertionMessage
- Inherits:
-
Object
- Object
- Test::Unit::Assertions::AssertionMessage
show all
- Includes:
- Util::BacktraceFilter
- Defined in:
- lib/test/unit/assertions.rb
Overview
Defined Under Namespace
Classes: Literal, Template
Constant Summary
Util::BacktraceFilter::TESTUNIT_FILE_SEPARATORS, Util::BacktraceFilter::TESTUNIT_PREFIX, Util::BacktraceFilter::TESTUNIT_RB_FILE
Class Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
#filter_backtrace
Constructor Details
#initialize(head, template_string, parameters) ⇒ AssertionMessage
Returns a new instance of AssertionMessage.
565
566
567
568
569
|
# File 'lib/test/unit/assertions.rb', line 565
def initialize(head, template_string, parameters)
@head = head
@template_string = template_string
@parameters = parameters
end
|
Class Attribute Details
.use_pp ⇒ Object
Returns the value of attribute use_pp.
526
527
528
|
# File 'lib/test/unit/assertions.rb', line 526
def use_pp
@use_pp
end
|
Class Method Details
.literal(value) ⇒ Object
559
560
561
|
# File 'lib/test/unit/assertions.rb', line 559
def self.literal(value)
Literal.new(value)
end
|
Instance Method Details
#add_period(string) ⇒ Object
600
601
602
|
# File 'lib/test/unit/assertions.rb', line 600
def add_period(string)
(string =~ /\.\Z/ ? string : string + '.')
end
|
#convert(object) ⇒ Object
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
|
# File 'lib/test/unit/assertions.rb', line 571
def convert(object)
case object
when Exception
"Class: <\#{convert(object.class)}>\nMessage: <\#{convert(object.message)}>\n---Backtrace---\n\#{filter_backtrace(object.backtrace).join(\"\\n\")}\n---------------\n".chop
else
if(self.class.use_pp)
begin
require 'pp'
rescue LoadError
self.class.use_pp = false
return object.inspect
end unless(defined?(PP))
PP.pp(object, '').chomp
else
object.inspect
end
end
end
|
#template ⇒ Object
596
597
598
|
# File 'lib/test/unit/assertions.rb', line 596
def template
@template ||= Template.create(@template_string)
end
|
#to_s ⇒ Object
604
605
606
607
608
609
610
611
612
613
614
615
|
# File 'lib/test/unit/assertions.rb', line 604
def to_s
message_parts = []
if (@head)
head = @head.to_s
unless(head.empty?)
message_parts << add_period(head)
end
end
tail = template.result(@parameters.collect{|e| convert(e)})
message_parts << tail unless(tail.empty?)
message_parts.join("\n")
end
|