Class: RSpec::Unit::Assertions::AssertionMessage::Template

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parts) ⇒ Template



545
546
547
548
# File 'lib/rspec/unit/assertions.rb', line 545

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

Instance Attribute Details

#countObject (readonly)

Returns the value of attribute count



543
544
545
# File 'lib/rspec/unit/assertions.rb', line 543

def count
  @count
end

Class Method Details

.create(string) ⇒ Object



538
539
540
541
# File 'lib/rspec/unit/assertions.rb', line 538

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

Instance Method Details

#result(parameters) ⇒ Object



550
551
552
553
554
# File 'lib/rspec/unit/assertions.rb', line 550

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