Module: RSpec::Support::WhitespaceChecks

Defined in:
lib/rspec/support/spec/library_wide_checks.rb

Instance Method Summary collapse

Instance Method Details

#check_for_extra_spaces(filename) ⇒ Object



20
21
22
23
24
25
26
27
28
29
# File 'lib/rspec/support/spec/library_wide_checks.rb', line 20

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) ⇒ Object

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



10
11
12
13
14
15
16
17
18
# File 'lib/rspec/support/spec/library_wide_checks.rb', line 10

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