Class: Test::Unit::Assertions::AssertionMessage
- Inherits:
-
Object
- Object
- Test::Unit::Assertions::AssertionMessage
show all
- Includes:
- Util::BacktraceFilter
- Defined in:
- lib/test/unit/assertions.rb
Defined Under Namespace
Classes: DelayedLiteral, 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.
874
875
876
877
878
|
# File 'lib/test/unit/assertions.rb', line 874
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.
773
774
775
|
# File 'lib/test/unit/assertions.rb', line 773
def use_pp
@use_pp
end
|
Class Method Details
.convert(object) ⇒ Object
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
|
# File 'lib/test/unit/assertions.rb', line 808
def convert(object)
case object
when Exception
<<EOM.chop
Class: <#{convert(object.class)}>
Message: <#{convert(object.message)}>
---Backtrace---
#{Util::BacktraceFilter.filter_backtrace(object.backtrace).join("\n")}
---------------
EOM
else
if use_pp
begin
require 'pp' unless defined?(PP)
return PP.pp(object, '').chomp
rescue LoadError
self.use_pp = false
end
end
object.inspect
end
end
|
.delayed_diff(from, to) ⇒ Object
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
|
# File 'lib/test/unit/assertions.rb', line 783
def delayed_diff(from, to)
delayed_literal do
if !from.is_a?(String) or !to.is_a?(String)
from = convert(from)
to = convert(to)
end
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) ⇒ Object
779
780
781
|
# File 'lib/test/unit/assertions.rb', line 779
def delayed_literal(&block)
DelayedLiteral.new(block)
end
|
.literal(value) ⇒ Object
775
776
777
|
# File 'lib/test/unit/assertions.rb', line 775
def literal(value)
Literal.new(value)
end
|
Instance Method Details
#add_period(string) ⇒ Object
888
889
890
|
# File 'lib/test/unit/assertions.rb', line 888
def add_period(string)
(string =~ /\.\Z/ ? string : string + '.')
end
|
#convert(object) ⇒ Object
880
881
882
|
# File 'lib/test/unit/assertions.rb', line 880
def convert(object)
self.class.convert(object)
end
|
#template ⇒ Object
884
885
886
|
# File 'lib/test/unit/assertions.rb', line 884
def template
@template ||= Template.create(@template_string)
end
|
#to_s ⇒ Object
892
893
894
895
896
897
898
899
900
901
902
903
|
# File 'lib/test/unit/assertions.rb', line 892
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
|