Skip to content

Instantly share code, notes, and snippets.

@alxndr
Created September 18, 2015 01:12
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 alxndr/ead7c48b137d01e189d0 to your computer and use it in GitHub Desktop.
Save alxndr/ead7c48b137d01e189d0 to your computer and use it in GitHub Desktop.
Sanity test for Elixir projects. Place directly in the `test/` directory.
defmodule App.SanityTest do
@directory_separator "/"
@test_dir __DIR__
@excluded_dirs ~w(factories support fixture vcr_cassettes custom_cassettes)
@excluded_files ~w(test_helper.exs)
test "checks that all test files are named properly" do
bad_files =
Path.join([@test_dir, "**", "*"])
|> Path.wildcard
|> Enum.map(&Path.expand/1)
|> Enum.reject(&File.dir?(&1))
|> Enum.reject(&is_in_excluded_dir?/1)
|> Enum.reject(&String.ends_with?(&1, "_test.exs"))
|> Enum.reject(&is_excluded_file?/1)
assert bad_files == []
end
defp is_in_excluded_dir?(filepath) do
containing_dir =
filepath
|> String.split("/")
|> Enum.at(-2)
Enum.any? @excluded_dirs, &(containing_dir == &1)
end
defp is_excluded_file?(filepath) do
Enum.any?(@excluded_files, &matches?(filepath, &1))
end
defp matches?(string, pattern) when is_binary(pattern) do
String.ends_with?(string, pattern)
end
defp matches?(string, pattern) do
String.match?(string, pattern)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment