module RSpec::Support::WhitespaceChecks

Public Instance Methods

check_for_extra_spaces(filename) click to toggle source
# File lib/rspec/support/spec/library_wide_checks.rb, line 18
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
check_for_tab_characters(filename) click to toggle source

This malformed whitespace detection logic has been borrowed from bundler: github.com/bundler/bundler/blob/v1.8.0/spec/quality_spec.rb

# File lib/rspec/support/spec/library_wide_checks.rb, line 8
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