Skip to content

Commit b38891d

Browse files
committed
Adds quality spec
- Spec will fail if Thor contains malformed whitespace - Spec will fail if Thor's tests use inconsistent quote styles (Thor prefers double-quotes) - Run with: rspec spec/quality_spec.rb
1 parent 17bb8e6 commit b38891d

File tree

1 file changed

+75
-0
lines changed

1 file changed

+75
-0
lines changed

spec/quality_spec.rb

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
if defined?(Encoding) && Encoding.default_external != "UTF-8"
2+
Encoding.default_external = "UTF-8"
3+
end
4+
5+
describe "The library itself" do
6+
def check_for_spec_defs_with_single_quotes(filename)
7+
failing_lines = []
8+
9+
File.readlines(filename).each_with_index do |line,number|
10+
failing_lines << number + 1 if line =~ /^ *(describe|it|context) {1}'{1}/
11+
end
12+
13+
unless failing_lines.empty?
14+
"#{filename} uses inconsistent single quotes on lines #{failing_lines.join(', ')}"
15+
end
16+
end
17+
18+
def check_for_tab_characters(filename)
19+
failing_lines = []
20+
File.readlines(filename).each_with_index do |line,number|
21+
failing_lines << number + 1 if line =~ /\t/
22+
end
23+
24+
unless failing_lines.empty?
25+
"#{filename} has tab characters on lines #{failing_lines.join(', ')}"
26+
end
27+
end
28+
29+
def check_for_extra_spaces(filename)
30+
failing_lines = []
31+
File.readlines(filename).each_with_index do |line,number|
32+
next if line =~ /^\s+#.*\s+\n$/
33+
failing_lines << number + 1 if line =~ /\s+\n$/
34+
end
35+
36+
unless failing_lines.empty?
37+
"#{filename} has spaces on the EOL on lines #{failing_lines.join(', ')}"
38+
end
39+
end
40+
41+
RSpec::Matchers.define :be_well_formed do
42+
failure_message_for_should do |actual|
43+
actual.join("\n")
44+
end
45+
46+
match do |actual|
47+
actual.empty?
48+
end
49+
end
50+
51+
it "has no malformed whitespace" do
52+
exempt = /\.gitmodules|\.marshal|fixtures|vendor|spec|ssl_certs|LICENSE/
53+
error_messages = []
54+
Dir.chdir(File.expand_path("../..", __FILE__)) do
55+
`git ls-files`.split("\n").each do |filename|
56+
next if filename =~ exempt
57+
error_messages << check_for_tab_characters(filename)
58+
error_messages << check_for_extra_spaces(filename)
59+
end
60+
end
61+
expect(error_messages.compact).to be_well_formed
62+
end
63+
64+
it "uses double-quotes consistently in specs" do
65+
included = /spec/
66+
error_messages = []
67+
Dir.chdir(File.expand_path("../", __FILE__)) do
68+
`git ls-files`.split("\n").each do |filename|
69+
next unless filename =~ included
70+
error_messages << check_for_spec_defs_with_single_quotes(filename)
71+
end
72+
end
73+
expect(error_messages.compact).to be_well_formed
74+
end
75+
end

0 commit comments

Comments
 (0)