class RSpecCommand::MatchFixture

def failure_message

Returns:
  • (String) -
def failure_message
  matching_files = @fixture.files & @local.files
  fixture_only_files = @fixture.files - @local.files
  local_only_files = @local.files - @fixture.files
  buf = "expected fixture #{@fixture.path} to match files:\n"
  (@fixture.files | @local.files).sort.each do |file|
    if matching_files.include?(file)
      local_file = @local.absolute(file)
      fixture_file = @fixture.absolute(file)
      if File.directory?(local_file) && File.directory?(fixture_file)
        # Do nothing
      elsif File.directory?(fixture_file)
        buf << "  #{file} should be a directory\n"
      elsif File.directory?(local_file)
        buf << "  #{file} should not be a directory"
      else
        actual = IO.read(local_file)
        expected = IO.read(fixture_file)
        if actual != expected
          # Show a diff
          buf << "  #{file} does not match fixture:"
          buf << differ.diff(actual, expected).split(/\n/).map {|line| '    '+line }.join("\n")
        end
      end
    elsif fixture_only_files.include?(file)
      buf << "  #{file} is not found\n"
    elsif local_only_files.include?(file)
      buf << "  #{file} should not exist\n"
    end
  end
  buf
end