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

Inherits:
Object
  • Object
show all
Defined in:
lib/test/unit/assertions.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parts) ⇒ Template

Returns a new instance of Template.



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

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

Instance Attribute Details

#countObject (readonly)

Returns the value of attribute count.



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

def count
  @count
end

Class Method Details

.create(string) ⇒ Object



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

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

Instance Method Details

#result(parameters) ⇒ Object



2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
# 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