123456789_123456789_123456789_123456789_123456789_

Class: Test::Unit::Assertions::AssertionMessage::Template

Relationships & Source Files
Inherits: Object
Defined in: lib/test/unit/assertions.rb

Class Method Summary

Instance Attribute Summary

Instance Method Summary

Constructor Details

.new(parts) ⇒ Template

[ GitHub ]

  
# File 'lib/test/unit/assertions.rb', line 2318

def initialize(parts)
  @parts = parts
  @count = parts.count('?')
end

Class Method Details

.create(string)

[ GitHub ]

  
# File 'lib/test/unit/assertions.rb', line 2311

def self.create(string)
  parts = (string ? string.scan(/(?=[^\\])\?|(?:\\\?|[^\?])+/m) : [])
  self.new(parts)
end

Instance Attribute Details

#count (readonly)

[ GitHub ]

  
# File 'lib/test/unit/assertions.rb', line 2316

attr_reader :count

Instance Method Details

#concatenatable(text, encoding) (private)

[ GitHub ]

  
# File 'lib/test/unit/assertions.rb', line 2344

def concatenatable(text, encoding)
  if Encoding.compatible?(text, encoding)
    text
  else
    text.dup.force_encoding(encoding)
  end
end

#result(parameters)

[ GitHub ]

  
# File 'lib/test/unit/assertions.rb', line 2323

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