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