mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Unify Test::Unit::Assertions#message
Merge `Test::Unit::CoreAssertions#message`.
This commit is contained in:
parent
489c22b17f
commit
3932227d96
1 changed files with 10 additions and 21 deletions
|
@ -16,9 +16,16 @@ module Test
|
|||
|
||||
def message msg = nil, ending = nil, &default
|
||||
proc {
|
||||
msg = msg.call.chomp(".") if Proc === msg
|
||||
custom_message = "#{msg}.\n" unless msg.nil? or msg.to_s.empty?
|
||||
"#{custom_message}#{default.call}#{ending || "."}"
|
||||
ending ||= (ending_pattern = /(?<!\.)\z/; ".")
|
||||
ending_pattern ||= /(?<!#{Regexp.quote(ending)})\z/
|
||||
msg = msg.call if Proc === msg
|
||||
ary = [msg, (default.call if default)].compact.reject(&:empty?)
|
||||
ary.map! {|str| str.to_s.sub(ending_pattern, ending) }
|
||||
begin
|
||||
ary.join("\n")
|
||||
rescue Encoding::CompatibilityError
|
||||
ary.map(&:b).join("\n")
|
||||
end
|
||||
}
|
||||
end
|
||||
end
|
||||
|
@ -729,24 +736,6 @@ eom
|
|||
end
|
||||
alias all_assertions_foreach assert_all_assertions_foreach
|
||||
|
||||
def message(msg = nil, *args, &default) # :nodoc:
|
||||
if Proc === msg
|
||||
super(nil, *args) do
|
||||
ary = [msg.call, (default.call if default)].compact.reject(&:empty?)
|
||||
if 1 < ary.length
|
||||
ary[0...-1] = ary[0...-1].map {|str| str.sub(/(?<!\.)\z/, '.') }
|
||||
end
|
||||
begin
|
||||
ary.join("\n")
|
||||
rescue Encoding::CompatibilityError
|
||||
ary.map(&:b).join("\n")
|
||||
end
|
||||
end
|
||||
else
|
||||
super
|
||||
end
|
||||
end
|
||||
|
||||
def diff(exp, act)
|
||||
require 'pp'
|
||||
q = PP.new(+"")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue