class Test::Unit::Assertions::AssertionMessage::Template

Attributes

count[R]

Public Class Methods

create(string) click to toggle source
# File test-unit-3.3.7/lib/test/unit/assertions.rb, line 2033
def self.create(string)
  parts = (string ? string.scan(/(?=[^\\])\?|(?:\\\?|[^\?])+/m) : [])
  self.new(parts)
end
new(parts) click to toggle source
# File test-unit-3.3.7/lib/test/unit/assertions.rb, line 2040
def initialize(parts)
  @parts = parts
  @count = parts.find_all{|e| e == '?'}.size
end

Public Instance Methods

result(parameters) click to toggle source
# File test-unit-3.3.7/lib/test/unit/assertions.rb, line 2045
def result(parameters)
  raise "The number of parameters does not match the number of substitutions." if(parameters.size != count)
  params = parameters.dup
  expanded_template = ""
  @parts.each do |part|
    if part == '?'
      param = params.shift
      if Object.const_defined?(:Encoding)
        expanded_template += concatenatable(param,
                                            expanded_template.encoding)
      else
        expanded_template += param
      end
    else
      expanded_template += part.gsub(/\\\?/m, '?')
    end
  end
  expanded_template
end

Private Instance Methods

concatenatable(text, encoding) click to toggle source
# File test-unit-3.3.7/lib/test/unit/assertions.rb, line 2066
def concatenatable(text, encoding)
  if Encoding.compatible?(text, encoding)
    text
  else
    text.dup.force_encoding(encoding)
  end
end