1
0
Fork 0
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:
Nobuyoshi Nakada 2021-10-09 16:17:01 +09:00
parent 489c22b17f
commit 3932227d96
No known key found for this signature in database
GPG key ID: 7CD2805BFA3770C6

View file

@ -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(+"")