Skip to content

Instantly share code, notes, and snippets.

@odlp
Last active June 4, 2018 09:34
Show Gist options
  • Save odlp/58fb925ff65629ff502479860bd072cd to your computer and use it in GitHub Desktop.
Save odlp/58fb925ff65629ff502479860bd072cd to your computer and use it in GitHub Desktop.
Check test / spec files are named correctly
#!/bin/sh
# Checks test files are named "_spec.rb" to match the RSpec globs property
# defined in .circleci/config.yml. This will fail the build if there are test
# files which don't match the required pattern.
# Ignores first-level helper files (e.g. spec_helper.rb) and the spec/support,
# spec/factories, spec/shared_examples folders
set -eu
echo "Checking test files are named *_spec.rb to ensure being run on CI..."
TEST_FILE_PATTERN="_spec.rb"
findIncorrectTestFilenames() {
find spec -mindepth 2 \
-type f -name "*.rb" \
-not -path "spec/support/*" \
-not -path "spec/factories/*" \
-not -path "spec/shared_examples/*" \
| grep "$TEST_FILE_PATTERN" --invert-match
}
if findIncorrectTestFilenames; then
echo "Rename the files as <name>$TEST_FILE_PATTERN or move to another directory"
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment