Last active
August 11, 2016 22:49
-
-
Save paulz/e8ff07bdb390ea40c4dd to your computer and use it in GitHub Desktop.
Overcommit pre-commit git hook for Specta and Quick Focused Examples
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
PreCommit: | |
NoFocusedExamples: | |
include: ['*Tests/*.swift', '*Tests/*.m'] | |
enabled: true | |
description: 'Checking for temporary focused examples' |
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
# .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