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: ArrayInspector, DelayedLiteral, HashInspector, Inspector, Literal, MaybeContainer, Template
Constant Summary
collapse
- MAX_DIFF_TARGET_STRING_SIZE =
1000
- @@max_diff_target_string_size =
nil
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.
1856
1857
1858
1859
1860
|
# File 'lib/test/unit/assertions.rb', line 1856
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.
1511
1512
1513
|
# File 'lib/test/unit/assertions.rb', line 1511
def use_pp
@use_pp
end
|
Class Method Details
.convert(object) ⇒ Object
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
|
# File 'lib/test/unit/assertions.rb', line 1599
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) ⇒ Object
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
|
# File 'lib/test/unit/assertions.rb', line 1576
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) ⇒ Object
1517
1518
1519
|
# File 'lib/test/unit/assertions.rb', line 1517
def delayed_literal(&block)
DelayedLiteral.new(block)
end
|
.diff_target_string?(string) ⇒ Boolean
1545
1546
1547
1548
1549
1550
1551
|
# File 'lib/test/unit/assertions.rb', line 1545
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) ⇒ Object
1553
1554
1555
1556
1557
1558
1559
|
# File 'lib/test/unit/assertions.rb', line 1553
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) ⇒ Object
1513
1514
1515
|
# File 'lib/test/unit/assertions.rb', line 1513
def literal(value)
Literal.new(value)
end
|
.max_diff_target_string_size ⇒ Object
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
|
# File 'lib/test/unit/assertions.rb', line 1526
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) ⇒ Object
1541
1542
1543
|
# File 'lib/test/unit/assertions.rb', line 1541
def max_diff_target_string_size=(size)
@@max_diff_target_string_size = size
end
|
.maybe_container(value, &formatter) ⇒ Object
1521
1522
1523
|
# File 'lib/test/unit/assertions.rb', line 1521
def maybe_container(value, &formatter)
MaybeContainer.new(value, &formatter)
end
|
.prepare_for_diff(from, to) ⇒ Object
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
|
# File 'lib/test/unit/assertions.rb', line 1561
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) ⇒ Object
1870
1871
1872
|
# File 'lib/test/unit/assertions.rb', line 1870
def add_period(string)
(string =~ /\.\Z/ ? string : string + '.')
end
|
#convert(object) ⇒ Object
1862
1863
1864
|
# File 'lib/test/unit/assertions.rb', line 1862
def convert(object)
self.class.convert(object)
end
|
#template ⇒ Object
1866
1867
1868
|
# File 'lib/test/unit/assertions.rb', line 1866
def template
@template ||= Template.create(@template_string)
end
|
#to_s ⇒ Object
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
|
# File 'lib/test/unit/assertions.rb', line 1874
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
|