Package: cookiecutterassert
Cookie Cutter AssertThis project is intended to allow TDD testing for cookie cutter templates.It is a Command Line Interface (cli) tool that will scan atestfolder in a cookie cutter project to execute test cases and run assertions about generated files and their contentsTheCookie Cuttertemplate merge tool is a great tool for templating projectsCookie Cutter Assert was originally developed at Ford Motor Company to facilitate automated testing of Cookie Cutter templates.Installing cookiecutterassertPre-requisitespipxbrew install pipxpipx ensurepathpipx windows installpython3 -m pip install --user pipxpython3 -m pipx ensurepathInstall commandpipx install cookiecutterassertExecuting testsgo to the root of your cookiecutter project and runcookiecutterassertIf all tests pass, the return code is 0 and you will seeAll tests passedIf tests fail, the return code is 1 and you will seeThere were failing testsThe first failed assertion in each folder will print its failure results and the rest of the assertions are skipped.As each test scenario executes, you will see---Starting tests for {SCENARIO FOLDER NAME}Command line options--helpprints a help message--visible-whitespacemakes common whitespace characters visible in the output of fileMatches rule-vwsame as --visible-whitespace--templatefolderSpecifies the location of the cookiecutter project.  defaults to.test_nameA positional argument specifying a single test folder name to run in the test suitespecifying a single test is useful when iterating on test development, similar to fdescribe or fit in mocha or jasmineUsageUsage: runIntegrationTest.py [OPTIONS] [SPECIFIC_TEST_FOLDER]

  Runs all test folders in the test directory or a single specific test
  folder if specified

Options:
  --templatefolder TEXT      path of cookiecutter project directory, defaults
                             to .

  -vw, --visible-whitespace  make whitespace visble with symbols in place of
                             common whitespace characters

  --help                     Show this message and exit.Setting up a cookiecutter assert projectSeeexampleYour cookie cutter project should have the following structuretemplatefolder
|   cookiecutter.json
|   defaultConfig.yaml
└───{{ cookiecutter.project_name }}
|       templatefiles
|       ...
|
└───build
|       generatedoutputfiles
|       ...
└───test
    └───testCase0
    |   |   assertions.yaml
    |   |   config.yaml
    |
    └───testCase1
        |   assertions.yaml
        |   config.yaml
        ...testis where your cookiecutterassert tests go{{ cookiecutter.project_name }}is the directory with the project template filesbuildis where the output from executingrun.shgoescookiecutter.jsonis a required file and should have variable names with empty valuesdefaultConfig.yamlis default cookie cutter variables across all test cases.  Individual test cases can override the variables completely or partiallytestfolderEach folder name under test should define a scenario and expected outcome in the folder namecookiecutterassert will recursively find every folder under test with bothconfig.yamlandassertions.yamlcookiecutterassert then generates the template usingconfig.yamlfolder to abuildfolder in that test.Finally, cookiecutterassert runs the assertions in the assertions.yaml against the generated filesThe merge of the root leveldefaultConfig.yamland the test case'sconfig.yamlfile will hold the variable values used in that test.The combination ofdefaultConfig.yamland folder-specificconfig.yamlmust define all variables from cookiecutter.jsonTheassertions.yamlfile holds the rules that are executed on the generated filesFiles are generated for each test in the build folder of that testassertions.yamlfileHere is a sampleassertions:
  - pathExists foo.txt
  - pathExists bin/scripts
  - pathNotExists missingFile
  - fileMatches build.gradle expectedBuild.gradle
  - runScript MyApp ./gradlew clean build
  - fileContainsLine MyApp/foo this line should exist
  - fileDoesNotContainLine MyApp/foo this line should not exist
  - fileHasMatchingLine MyApp/foo ^lo+king\sfor.*$
  - fileDoesNotHaveMatchingLine MyApp/foo ^lo+king\sfor.*$
  - fileContainsSnippet MyApp/foo goodSnippet.txt
  - fileDoesNotContainSnippet MyApp/foo badSnippet.txtRulespathExists {generatedFileOrFolderPathRelativeToRoot}Passes if the path exists in thebuildfolder after generationpathNotExists {generatedFileOrFolderPathRelativeToRoot}Passes if the path does not exist in thebuildfolder after generationfileMatches {generatedFileOrFolderPathRelativeToRoot}  {expectedFilePathRelativeToTestFolder}Passes if contents of file generated matches the contents of the expected filerunScript {generatedFolderToRunScriptIn}  {script}executes script in specified folder underbuildPasses if script has a 0 return codefileContainsLine {generatedFile} {line}Passes if generated file inbuildcontains the expected linefileDoesNotContainLine {generatedFile} {line}Passes if generated file inbuilddoes not contain the expected linefileHasMatchingLine {generatedFile} {regex}Passes if generated file inbuildhas a line matching the regular expressionfileDoesNotHaveMatchingLine {generatedFile} {regex}Passes if generated file inbuilddoes not contain a line matching the regular expressionfileContainsSnippet {generatedFile} {snippetFile}Passes if all of the lines in the snippet file occur in order in the generated filefileDoesNotContainSnippet {generatedFile} {snippetFile}Passes if the generated file does not have all of the lines of the snippet file in orderAssertion file optionsYou may put options on the command line or in the assertion file, but some options are only available in assertion files
for example:options:
  visible-whitespace: true
assertions:
  - fileMatches MyApp/file-with-spaces expected-file-with-spacesIn this case, the visible-whitespace enabled by default for rules in this assertion fileAssertion file options are always overridden by command line options where availableList of assertion file optionsvisible-whitespaceSame as the CLI optionignoreSet to true to have cookiecuttterassert not evaluate the test folderDeveloping cookiecutterassertseeDevelopment guide