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, MaybeContainer, Template
Constant Summary
collapse
- MAX_DIFF_TARGET_STRING_SIZE =
300
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.
1003
1004
1005
1006
1007
|
# File 'lib/test/unit/assertions.rb', line 1003
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.
869
870
871
|
# File 'lib/test/unit/assertions.rb', line 869
def use_pp
@use_pp
end
|
Class Method Details
.convert(object) ⇒ Object
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
|
# File 'lib/test/unit/assertions.rb', line 919
def convert(object)
case object
when Exception
"Class: <\#{convert(object.class)}>\nMessage: <\#{convert(object.message)}>\n---Backtrace---\n\#{Util::BacktraceFilter.filter_backtrace(object.backtrace).join(\"\\n\")}\n---------------\n".chop
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
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
|
# File 'lib/test/unit/assertions.rb', line 892
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 = nil
diff = "" if !diff_target_string?(from) or !diff_target_string?(to)
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
875
876
877
|
# File 'lib/test/unit/assertions.rb', line 875
def delayed_literal(&block)
DelayedLiteral.new(block)
end
|
.diff_target_string?(string) ⇒ Boolean
884
885
886
887
888
889
890
|
# File 'lib/test/unit/assertions.rb', line 884
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
|
.literal(value) ⇒ Object
871
872
873
|
# File 'lib/test/unit/assertions.rb', line 871
def literal(value)
Literal.new(value)
end
|
.maybe_container(value, &formatter) ⇒ Object
879
880
881
|
# File 'lib/test/unit/assertions.rb', line 879
def maybe_container(value, &formatter)
MaybeContainer.new(value, &formatter)
end
|
Instance Method Details
#add_period(string) ⇒ Object
1017
1018
1019
|
# File 'lib/test/unit/assertions.rb', line 1017
def add_period(string)
(string =~ /\.\Z/ ? string : string + '.')
end
|
#convert(object) ⇒ Object
1009
1010
1011
|
# File 'lib/test/unit/assertions.rb', line 1009
def convert(object)
self.class.convert(object)
end
|
#template ⇒ Object
1013
1014
1015
|
# File 'lib/test/unit/assertions.rb', line 1013
def template
@template ||= Template.create(@template_string)
end
|
#to_s ⇒ Object
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
|
# File 'lib/test/unit/assertions.rb', line 1021
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
|