|
1 | 1 | require 'rspec/support/spec/shell_out'
|
2 | 2 |
|
| 3 | +module RSpec |
| 4 | + module Support |
| 5 | + module WhitespaceChecks |
| 6 | + # This malformed whitespace detection logic has been borrowed from bundler: |
| 7 | + # https://github.com/bundler/bundler/blob/v1.8.0/spec/quality_spec.rb |
| 8 | + def check_for_tab_characters(filename) |
| 9 | + failing_lines = [] |
| 10 | + File.readlines(filename).each_with_index do |line, number| |
| 11 | + failing_lines << number + 1 if line =~ /\t/ |
| 12 | + end |
| 13 | + |
| 14 | + return if failing_lines.empty? |
| 15 | + "#{filename} has tab characters on lines #{failing_lines.join(', ')}" |
| 16 | + end |
| 17 | + |
| 18 | + def check_for_extra_spaces(filename) |
| 19 | + failing_lines = [] |
| 20 | + File.readlines(filename).each_with_index do |line, number| |
| 21 | + next if line =~ /^\s+#.*\s+\n$/ |
| 22 | + failing_lines << number + 1 if line =~ /\s+\n$/ |
| 23 | + end |
| 24 | + |
| 25 | + return if failing_lines.empty? |
| 26 | + "#{filename} has spaces on the EOL on lines #{failing_lines.join(', ')}" |
| 27 | + end |
| 28 | + end |
| 29 | + end |
| 30 | +end |
| 31 | + |
3 | 32 | RSpec.shared_examples_for "library wide checks" do |lib, options|
|
4 | 33 | consider_a_test_env_file = options.fetch(:consider_a_test_env_file, /MATCHES NOTHING/)
|
5 | 34 | allowed_loaded_feature_regexps = options.fetch(:allowed_loaded_feature_regexps, [])
|
|
8 | 37 | skip_spec_files = options.fetch(:skip_spec_files, /MATCHES NOTHING/)
|
9 | 38 |
|
10 | 39 | include RSpec::Support::ShellOut
|
| 40 | + include RSpec::Support::WhitespaceChecks |
11 | 41 |
|
12 | 42 | define_method :files_to_require_for do |sub_dir|
|
13 | 43 | slash = File::SEPARATOR
|
@@ -101,29 +131,6 @@ def have_successful_no_warnings_output
|
101 | 131 | expect(loaded_features).to eq([])
|
102 | 132 | end
|
103 | 133 |
|
104 |
| - # This malformed whitespace detection logic has been borrowed from bundler: |
105 |
| - # https://github.com/bundler/bundler/blob/v1.8.0/spec/quality_spec.rb |
106 |
| - def check_for_tab_characters(filename) |
107 |
| - failing_lines = [] |
108 |
| - File.readlines(filename).each_with_index do |line, number| |
109 |
| - failing_lines << number + 1 if line =~ /\t/ |
110 |
| - end |
111 |
| - |
112 |
| - return if failing_lines.empty? |
113 |
| - "#{filename} has tab characters on lines #{failing_lines.join(', ')}" |
114 |
| - end |
115 |
| - |
116 |
| - def check_for_extra_spaces(filename) |
117 |
| - failing_lines = [] |
118 |
| - File.readlines(filename).each_with_index do |line, number| |
119 |
| - next if line =~ /^\s+#.*\s+\n$/ |
120 |
| - failing_lines << number + 1 if line =~ /\s+\n$/ |
121 |
| - end |
122 |
| - |
123 |
| - return if failing_lines.empty? |
124 |
| - "#{filename} has spaces on the EOL on lines #{failing_lines.join(', ')}" |
125 |
| - end |
126 |
| - |
127 | 134 | RSpec::Matchers.define :be_well_formed do
|
128 | 135 | match do |actual|
|
129 | 136 | actual.empty?
|
|
0 commit comments