class UnitDiff

def parse_diff(result)

was expected, and what was actually obtained.
Parses a single diff recording the header and what
def parse_diff(result)
  header = []
  expect = []
  butwas = []
  footer = []
  found = false
  state = :header
  until result.empty? do
    case state
    when :header then
      header << result.shift
      state = :expect if result.first =~ /^<|^Expected/
    when :expect then
      case result.first
      when /^Expected (.*?) to equal (.*?):$/ then
        expect << $1
        butwas << $2
        state = :footer
        result.shift
      when /^Expected (.*?), not (.*)$/m then
        expect << $1
        butwas << $2
        state = :footer
        result.shift
      when /^Expected (.*?)$/ then
        expect << "#{$1}\n"
        result.shift
      when /^to equal / then
        state = :spec_butwas
        bw = result.shift.sub(/^to equal (.*):?$/, '\1')
        butwas << bw
      else
        state = :butwas if result.first.sub!(/ expected( but was|, not)/, '')
        expect << result.shift
      end
    when :butwas then
      butwas = result[0..-1]
      result.clear
    when :spec_butwas then
      if result.first =~ /^\s+\S+ at |^:\s*$/
        state = :footer
      else
        butwas << result.shift
      end
    when :footer then
      butwas.last.sub!(/:$/, '')
      footer = result.map {|l| l.chomp }
      result.clear
    else
      raise "unknown state #{state}"
    end
  end
  return header, expect, nil, footer if butwas.empty?
  expect.last.chomp!
  expect.first.sub!(/^<\"/, '')
  expect.last.sub!(/\">$/, '')
  butwas.last.chomp!
  butwas.last.chop! if butwas.last =~ /\.$/
  butwas.first.sub!( /^<\"/, '')
  butwas.last.sub!(/\">$/, '')
  return header, expect, butwas, footer
end