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.



2008
2009
2010
2011
# File 'lib/test/unit/assertions.rb', line 2008

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

Instance Attribute Details

#countObject (readonly)

Returns the value of attribute count.



2006
2007
2008
# File 'lib/test/unit/assertions.rb', line 2006

def count
  @count
end

Class Method Details

.create(string) ⇒ Object



2001
2002
2003
2004
# File 'lib/test/unit/assertions.rb', line 2001

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

Instance Method Details

#result(parameters) ⇒ Object



2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
# File 'lib/test/unit/assertions.rb', line 2013

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 == '?'
      encoding_safe_concat(expanded_template, params.shift)
    else
      expanded_template << part.gsub(/\\\?/m, '?')
    end
  end
  expanded_template
end