Skip to content

Instantly share code, notes, and snippets.

@markburns
Created November 17, 2010 17:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save markburns/703728 to your computer and use it in GitHub Desktop.
Save markburns/703728 to your computer and use it in GitHub Desktop.
Checks the spec and features directory for any "I debug", "show me the page" or "show_me_the_page" and prevents a commit if so
#!/usr/bin/env ruby
require 'rubygems'
begin
require 'term/ansicolor'
include Term::ANSIColor
rescue LoadError
puts "To get color from this post-commit hook install term/ansicolor"
%w[red blue green].each { |color| eval "def #{color} &blk; blk.call; end" }
end
class FileChecker
attr_accessor :errors, :exit_code
def initialize
@errors = []
@exit_code = 0
end
def perform_checks
features_and_specs = Dir["features/**/*.feature", "spec/**/*_spec.rb"]
check features_and_specs, ["show me the page", "I debug", "show_me_the_page"]
app_folders = Dir["app/**/*.rb", "lib/**/*.rb"]
check app_folders, ["debugger"]
end
def check files, undesirables
files.each do |f|
lines = File.read(f)
undesirables.each do |undesirable|
if lines =~ /#{undesirable}/
@errors << red{"'#{undesirable}'"} + " was found in #{f}"
@exit_code = -1
end
end
end
end
def stars ; puts "*" * 80 + "\n"; end
def display_errors
stars
puts "Git commit cancelled\n"
puts @errors.join("\n") + "\n"
stars
end
end
checker = FileChecker.new
checker.perform_checks
checker.display_errors if checker.exit_code==-1
exit checker.exit_code
@stevegraham
Copy link

this for 1.9? if so i prefer this for L9

%w(red green blue).each { |color| define_singleton_method(color) { |&blk| blk.call } }

@markburns
Copy link
Author

Tsk. You don't remember pairing and looking at this code, then saying this same thing?
Also you said you didn't want your name anywhere near this code. Gone and sullied it now haven't you?
And it's 1.8

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment