Skip to content

Instantly share code, notes, and snippets.

@atmos
Created November 5, 2009 19:59
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save atmos/227332 to your computer and use it in GitHub Desktop.
Save atmos/227332 to your computer and use it in GitHub Desktop.
require File.dirname(__FILE__) + '/spec_helper'
describe "The library itself" do
Spec::Matchers.define :have_no_tab_characters do
match do |filename|
@failing_lines = []
File.readlines(filename).each_with_index do |line,number|
@failing_lines << number + 1 if line =~ /\t/
end
@failing_lines.empty?
end
failure_message_for_should do |filename|
"The file #{filename} has tab characters on lines #{@failing_lines.join(', ')}"
end
end
Spec::Matchers.define :have_no_extraneous_spaces do
match do |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
@failing_lines.empty?
end
failure_message_for_should do |filename|
"The file #{filename} has spaces on the EOL on lines #{@failing_lines.join(', ')}"
end
end
it "has no tab characters" do
Dir.chdir(File.dirname(__FILE__) + '/..') do
Dir.glob("{lib,spec}/**/*.rb").each do |filename|
filename.should have_no_tab_characters
filename.should have_no_extraneous_spaces
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment