Skip to content
This repository was archived by the owner on Nov 30, 2024. It is now read-only.

Commit f82e762

Browse files
committed
Merge pull request #232 from AEgan/extract-whitespace-checks
Extracts checks into common helper
2 parents a5df89f + 17b640c commit f82e762

File tree

1 file changed

+30
-23
lines changed

1 file changed

+30
-23
lines changed

lib/rspec/support/spec/library_wide_checks.rb

Lines changed: 30 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,34 @@
11
require 'rspec/support/spec/shell_out'
22

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+
332
RSpec.shared_examples_for "library wide checks" do |lib, options|
433
consider_a_test_env_file = options.fetch(:consider_a_test_env_file, /MATCHES NOTHING/)
534
allowed_loaded_feature_regexps = options.fetch(:allowed_loaded_feature_regexps, [])
@@ -8,6 +37,7 @@
837
skip_spec_files = options.fetch(:skip_spec_files, /MATCHES NOTHING/)
938

1039
include RSpec::Support::ShellOut
40+
include RSpec::Support::WhitespaceChecks
1141

1242
define_method :files_to_require_for do |sub_dir|
1343
slash = File::SEPARATOR
@@ -101,29 +131,6 @@ def have_successful_no_warnings_output
101131
expect(loaded_features).to eq([])
102132
end
103133

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-
127134
RSpec::Matchers.define :be_well_formed do
128135
match do |actual|
129136
actual.empty?

0 commit comments

Comments
 (0)