Skip to content

Instantly share code, notes, and snippets.

@paulz
Last active August 11, 2016 22:49
Show Gist options
  • Save paulz/e8ff07bdb390ea40c4dd to your computer and use it in GitHub Desktop.
Save paulz/e8ff07bdb390ea40c4dd to your computer and use it in GitHub Desktop.
Overcommit pre-commit git hook for Specta and Quick Focused Examples
PreCommit:
NoFocusedExamples:
include: ['*Tests/*.swift', '*Tests/*.m']
enabled: true
description: 'Checking for temporary focused examples'
# .git-hooks/pre_commit/no_focused_examples.rb
# Check BDD specs for temporary focused examples
module Overcommit::Hook::PreCommit
class NoFocusedExamples < Base
def run
errors = []
focused = ['describe', 'context', 'it']
applicable_files.each do |file|
File.open(file, 'r').each_with_index do |line, index|
focused.each do |block_name|
if line.index("f#{block_name}(")
relative = Pathname(file).relative_path_from(Pathname(Overcommit::Utils.repo_root))
errors << "#{relative}:#{index} has focused #{block_name} block `f#{block_name}`"
end
end
end
end
return :fail, errors.join("\n") if errors.any?
:pass
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment