forked from ghaskins/riak_wiki
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Quality spec, enforcing clean/well-formed files
- Loading branch information
Showing
3 changed files
with
67 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
require "spec_helper" | ||
|
||
IGNORE = /\.(png$|gz$|rbc$|ico$|jpg$|gif$|eps$|logo$|pdf$)/ | ||
|
||
describe "The application itself" do | ||
it "has no malformed whitespace" do | ||
files = `git ls-files`.split("\n").select {|fn| fn !~ IGNORE} | ||
|
||
files.should be_well_formed | ||
end | ||
end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
require 'rspec' | ||
|
||
Dir[ Bundler.root.join("spec/support/**/*.rb") ].each{|f| require f} | ||
|
||
RSpec.configure do |c| | ||
c.include CustomMatchers | ||
end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
module CustomMatchers | ||
class BeWellFormed | ||
def matches?(files) | ||
@errors = files.map {|filename| | ||
begin | ||
[ | ||
check_for_tabs(filename), | ||
excessive_spacing(filename), | ||
newline_precedes_eof(filename) | ||
] | ||
rescue ArgumentError => e | ||
"File #{filename} likely contains binary data. If so, please exclude it via quality_spec.IGNORE" << | ||
"\n Exception => #{e.inspect}" | ||
end | ||
}.flatten.compact | ||
|
||
@errors.empty? | ||
end | ||
|
||
def failure_message_for_should | ||
@errors.join("\n") | ||
end | ||
|
||
private | ||
def check_for_tabs(filename) | ||
bad_lines = File.readlines(filename).each_with_index.map do |line, line_no| | ||
line_no + 1 if line["\t"] and line !~ /^\s+#.*\s+\n$/ | ||
end.flatten.compact | ||
|
||
"#{filename} has tab characters on lines #{bad_lines.join(', ')}" if bad_lines.any? | ||
end | ||
|
||
def excessive_spacing(filename) | ||
bad_lines = File.readlines(filename).each_with_index.map do |line, line_no| | ||
line_no + 1 if line =~ /\s+\n$/ and line !~ /^\s+#.*\s+\n$/ | ||
end.flatten.compact | ||
|
||
"#{filename} has spaces on the EOL on lines #{bad_lines.join(', ')}" if bad_lines.any? | ||
end | ||
|
||
def newline_precedes_eof(filename) | ||
"#{filename} does not have a newline (\\n) before EOF" if File.read(filename) !~ /\n$/ | ||
end | ||
end | ||
|
||
def be_well_formed | ||
BeWellFormed.new | ||
end | ||
end |