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

Commit 8448a47

Browse files
author
Alex Egan
committed
Extracts checks into common helper.
rspec-rails can't run all library wide checks due to rails warnings and other dependencies. This preps to allow for some specs to be extracted by rspec-rails until the aforementioned is fixed
1 parent a5df89f commit 8448a47

File tree

1 file changed

+32
-23
lines changed

1 file changed

+32
-23
lines changed

lib/rspec/support/spec/library_wide_checks.rb

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

3+
module RSpec
4+
module Support
5+
module WhitespaceChecks
6+
7+
# This malformed whitespace detection logic has been borrowed from bundler:
8+
# https://github.com/bundler/bundler/blob/v1.8.0/spec/quality_spec.rb
9+
def check_for_tab_characters(filename)
10+
failing_lines = []
11+
File.readlines(filename).each_with_index do |line, number|
12+
failing_lines << number + 1 if line =~ /\t/
13+
end
14+
15+
return if failing_lines.empty?
16+
"#{filename} has tab characters on lines #{failing_lines.join(', ')}"
17+
end
18+
19+
def check_for_extra_spaces(filename)
20+
failing_lines = []
21+
File.readlines(filename).each_with_index do |line, number|
22+
next if line =~ /^\s+#.*\s+\n$/
23+
failing_lines << number + 1 if line =~ /\s+\n$/
24+
end
25+
26+
return if failing_lines.empty?
27+
"#{filename} has spaces on the EOL on lines #{failing_lines.join(', ')}"
28+
end
29+
30+
end
31+
end
32+
end
33+
334
RSpec.shared_examples_for "library wide checks" do |lib, options|
435
consider_a_test_env_file = options.fetch(:consider_a_test_env_file, /MATCHES NOTHING/)
536
allowed_loaded_feature_regexps = options.fetch(:allowed_loaded_feature_regexps, [])
@@ -8,6 +39,7 @@
839
skip_spec_files = options.fetch(:skip_spec_files, /MATCHES NOTHING/)
940

1041
include RSpec::Support::ShellOut
42+
include RSpec::Support::WhitespaceChecks
1143

1244
define_method :files_to_require_for do |sub_dir|
1345
slash = File::SEPARATOR
@@ -101,29 +133,6 @@ def have_successful_no_warnings_output
101133
expect(loaded_features).to eq([])
102134
end
103135

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-
127136
RSpec::Matchers.define :be_well_formed do
128137
match do |actual|
129138
actual.empty?

0 commit comments

Comments
 (0)