module RSpec::Support::WhitespaceChecks

def check_for_extra_spaces(filename)

def check_for_extra_spaces(filename)
  failing_lines = []
  File.readlines(filename).each_with_index do |line, number|
    next if line =~ /^\s+#.*\s+\n$/
    failing_lines << number + 1 if line =~ /\s+\n$/
  end
  return if failing_lines.empty?
  "#{filename} has spaces on the EOL on lines #{failing_lines.join(', ')}"
end

def check_for_tab_characters(filename)

https://github.com/bundler/bundler/blob/v1.8.0/spec/quality_spec.rb
This malformed whitespace detection logic has been borrowed from bundler:
def check_for_tab_characters(filename)
  failing_lines = []
  File.readlines(filename).each_with_index do |line, number|
    failing_lines << number + 1 if line =~ /\t/
  end
  return if failing_lines.empty?
  "#{filename} has tab characters on lines #{failing_lines.join(', ')}"
end