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.



1685
1686
1687
1688
# File 'lib/test/unit/assertions.rb', line 1685

def initialize(parts)
  @parts = parts
  @count = parts.find_all{|e| e == '?'}.size
end

Instance Attribute Details

#countObject (readonly)

Returns the value of attribute count.



1683
1684
1685
# File 'lib/test/unit/assertions.rb', line 1683

def count
  @count
end

Class Method Details

.create(string) ⇒ Object



1678
1679
1680
1681
# File 'lib/test/unit/assertions.rb', line 1678

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

Instance Method Details

#result(parameters) ⇒ Object



1690
1691
1692
1693
1694
# File 'lib/test/unit/assertions.rb', line 1690

def result(parameters)
  raise "The number of parameters does not match the number of substitutions." if(parameters.size != count)
  params = parameters.dup
  @parts.collect{|e| e == '?' ? params.shift : e.gsub(/\\\?/m, '?')}.join('')
end