Created
November 22, 2010 22:16
-
-
Save leobessa/710823 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env rspec | |
require "spec_helper" | |
describe "The library itself" do | |
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 | |
it "has no malformed whitespace" do | |
error_messages = [] | |
Dir.chdir(File.expand_path("../..", __FILE__)) do | |
`git ls-files | grep \.rb$`.split("\n").each do |filename| | |
next if filename =~ /\.gitmodules|\.marshal|fixtures|vendor/ | |
error_messages << check_for_tab_characters(filename) | |
error_messages << check_for_extra_spaces(filename) | |
end | |
end | |
error_messages.compact.should be_well_formed | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment