{"id":25360613,"url":"https://github.com/alex-harvey-z3q/create_specs","last_synced_at":"2025-10-30T00:32:03.593Z","repository":{"id":148662098,"uuid":"82464085","full_name":"alex-harvey-z3q/create_specs","owner":"alex-harvey-z3q","description":"Autogenerate Rspec-puppet specs","archived":false,"fork":false,"pushed_at":"2018-08-13T01:00:19.000Z","size":48,"stargazers_count":3,"open_issues_count":3,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-08-22T13:24:28.088Z","etag":null,"topics":["puppet","rspec-puppet"],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/alex-harvey-z3q.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-02-19T14:17:39.000Z","updated_at":"2024-08-22T13:24:34.411Z","dependencies_parsed_at":"2023-05-20T19:30:12.300Z","dependency_job_id":null,"html_url":"https://github.com/alex-harvey-z3q/create_specs","commit_stats":null,"previous_names":["alex-harvey-z3q/create_specs"],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alex-harvey-z3q%2Fcreate_specs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alex-harvey-z3q%2Fcreate_specs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alex-harvey-z3q%2Fcreate_specs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alex-harvey-z3q%2Fcreate_specs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/alex-harvey-z3q","download_url":"https://codeload.github.com/alex-harvey-z3q/create_specs/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238915845,"owners_count":19551794,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["puppet","rspec-puppet"],"created_at":"2025-02-14T21:54:36.305Z","updated_at":"2025-10-30T00:31:58.309Z","avatar_url":"https://github.com/alex-harvey-z3q.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# create_specs.rb\n\nRelease 2.5.0\n\n[![Build Status](https://img.shields.io/travis/alexharv074/create_specs.svg)](https://travis-ci.org/alexharv074/create_specs)\n\n## Overview\n\nThis script can be used to generate Rspec-puppet examples for all of the resources in a Puppet JSON catalog document. The intended use-cases include quickly generating default Rspec tests in a project that doesn't have any; and it can also be useful when refactoring Puppet modules.\n\nIt is assumed that the user already knows how to set up Rspec-puppet for a Puppet module (i.e. how to create the `.fixtures.yml`, `Gemfile`, `spec/spec_helper.rb` etc).  If not, consider reading my [blog post](https://alexharv074.github.io/2016/05/08/setting-up-puppet-module-testing-from-scratch-part-i-puppet-syntax-puppet-lint-and-rspec-puppet.html). Or better still, use [pdk](https://github.com/puppetlabs/pdk).\n\n## Dependencies\n\nThis tool uses the [awesome_print](https://github.com/awesome-print/awesome_print) Gem.\n\nAlso, be aware that the generated spec may depend on the `verify_contents` method that is normally found inside Puppetlabs-spec-helper.\n\n## Installation\n\nInstall by cloning this repo:\n\n```\n$ git clone https://github.com/alexharv074/create_specs.git\n```\n\nThen add a line to your .bash_profile like:\n\n```\nexport PATH=/Users/alexharvey/git/create_specs:$PATH\n```\n\nEnsure you have the dependencies:\n\n```\n$ gem install awesome_print\n```\n\n## Usage\n\nHelp message:\n\n```\n$ create_specs.rb -h\nUsage: create_specs.rb [options]\n  -f, --config_file CONFIG    Path to config file\n  -c, --catalog CATALOG       Path to the catalog JSON file\n  -C, --class CLASS           Class (or node) name under test\n  -o, --output OUTPUTFILE     Path to the output Rspec file\n  -x, --exclude RESOURCE      Resources to exclude. String or Regexp. Repeat this option to exclude multiple resources\n  -i, --include RESOURCE      Resources to include despite the exclude list.\n  -I, --only-include RESOURCE Only include these resources and exclude everything else. Regexp supported\n  -m, --md5sums               Use md5sums instead of full file content to validate file content\n  -t, --[no-]compile-test     Include or exclude the catalog compilation test\n  -h, --help                  Print this help\n```\n\n### Basic usage\n\nBasic usage:\n\n```\n$ cd /path/to/puppet/module\n$ create_specs.rb -c path/to/catalog.json\n```\n\nThis will cause the resources in `catalog.json` to be rewritten as Rspec-puppet examples in `spec/classes/init_spec.rb`, which is the default output file.\n\nBy default, the script excludes all defined types as well as Class, Anchor, Notify and Node resources (see `config.yml`).\n\n### include option\n\nIf you want to override and include one or more of these, use the `-i` option:\n\n```\n$ create_specs.rb -c catalog.json -i Class -i Node\n```\n\nTo include defined types:\n\n```\n$ create_specs.rb -c catalog.json -i /::/\n```\n\nDue to a quirk of the implementation (again, see `config.yml`) it is not possible to include a specific defined type only. Using `-i My::Type` would not override the default behaviour to exclude everything matching `/::/`. To work around that use -I.\n\n### exclude option\n\nIf you want to exclude additional resource types, use the `-x` option:\n\n```\n$ create_specs.rb -c catalog.json -x User -x Group\n```\n\n### only include option\n\nIt is also possible to exclude everything other than a list of resources you care about. Use the `-I` option for this:\n\n```\n$ create_specs.rb -c catalog.json -I 'Service[ntp]' -I 'File[ntp]'\n```\n\nThis option can also accept regular expressions, e.g.:\n\nOnly include all files:\n\n```\n$ create_specs.rb -c catalog.json -I '/File/'  # or\n$ create_specs.rb -c catalog.json -I 'File[/.*/]'\n```\n\nOnly include files in /etc/ssl:\n\n```\n$ create_spec.rb -c catalog.json -I 'File[/\\/etc\\/ssl/]'\n```\n\n### output option\n\nTo specify a different output file:\n\n```\n$ create_specs.rb -c path/to/catalog.json -o path/to/output_spec.rb\n```\n\n### class name option\n\nBy default, the class name that was used to generate the catalog is guessed. In some edge-cases (e.g. if a pre-condition is used in the set up that first declares a different class) the auto-detected class is wrong. To get around this, use the -C option:\n\n```\n$ create_specs.rb -c path/to/catalog.json -C class\n```\n\n### compile test option\n\nThe default behaviour is to include a compile test as follows:\n\n```ruby\n  it 'should write a compiled catalog' do\n    is_expected.to compile.with_all_deps\n    File.write(\n      'catalogs/class_name.json',\n      PSON.pretty_generate(catalogue)\n    )\n  end\n```\n\nThis can be disabled by specifying `--no-compile-test`.\n\n### Specifying custom setup\n\nBy using the -f option, it is possible to pass a custom config.yml file with a custom setup section in it. For example, if your config.yml contained:\n\n```yaml\n:setup:\n  :pre_condition:\n    - hiera_include('classes')\n  :hiera_config: spec/fixtures/hiera.yaml\n  :facts:\n    foo: bar\n    baz: qux\n```\n\nThis would result in auto-generated Rspec code with:\n\n```ruby\n  let(:pre_condition) do\n    \"\"\"\n    hiera_include('classes')\n    \"\"\"\n  end\n\n  let(:hiera_config){ 'spec/fixtures/hiera.yaml' }\n\n  let(:facts) do\n    {\n      \"foo\" =\u003e \"bar\",\n      \"baz\" =\u003e \"qux\"\n    }\n  end\n```\n\n## Creating the catalog document\n\nWhile there are a variety of ways of creating a compiled Puppet catalog, the easiest way is to use Rspec-puppet.  Just create a spec file with the following content:\n\n```ruby\nrequire 'spec_helper'\n\ndescribe 'myclass' do\n  let(:params) do\n    {\n      'param1' =\u003e 'value1',\n      'param2' =\u003e 'value2',\n    }\n  end\n\n  it {\n    File.write(\n      'mycatalog.json',\n      PSON.pretty_generate(catalogue)\n    )\n  }\nend\n```\n\nThen run the tests and you'll have a compiled catalog.\n\nFor more detail, see my [other blog post](https://alexharv074.github.io/2017/05/31/using-create_specs-to-refactor-puppet.html).\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falex-harvey-z3q%2Fcreate_specs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falex-harvey-z3q%2Fcreate_specs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falex-harvey-z3q%2Fcreate_specs/lists"}