rspecpuppetrspec-puppet

Don't delete public puppet modules after rspec-puppet tests are done


In .fixtures.yml, there are modules downloaded from a public library, such as stdlib and concat in the following example:

fixtures:
  forge_modules:
    stdlib: puppetlabs/stdlib
    concat: puppetlabs/concat

These modules need to be downloaded whenever running an rspec-puppet test. They also get deleted after tests are done.

It is good if all tests run completely. But if there is a failed test that needs to run separately, these modules are not available. I have to run all tests (100+) together, thus public modules can be downloaded and available. It is very annoying when I am debugging a small error.

Is there way to configure rspec-puppet so that it doesn't download/delete those public modules every time?


Solution

  • Until recently, the Puppetlabs_spec_helper actually behaved the way you wanted it to, i.e. the fixtures directory was not cleaned unless all the tests pass.

    I notice this patch here changed that behaviour. For what it's worth, I also don't agree with that change.

    Anyway, if you want the old behaviour, you could:

    1. Use an earlier version of Puppetlabs_spec_helper.

    2. Define a custom spec task.

    3. Or just run bundle exec rake spec_prep spec_standalone.

    4. Or if you just want to run the tests in one file, run bundle exec rake spec_prep; bundle exec rspec spec/somefile_spec.rb --fail-fast. (The --fail-fast option is useful when debugging failing tests and it causes rspec to abort on the first failure.)

    To define a custom spec task with the old behaviour, add this to your Rakefile:

    desc "Run spec tests and clean the fixtures directory if successful"
    task :custom_spec do
      Rake::Task[:spec_prep].invoke
      Rake::Task[:spec_standalone].invoke
      Rake::Task[:spec_clean].invoke
    end
    

    If, instead, you want it to never, ever clean the fixtures directory:

    desc "Run tests but don't clean up spec dir"
    task :custom_spec do
      Rake::Task[:spec_prep].invoke
      Rake::Task[:spec_standalone].invoke
    end
    

    In either case, you would then run the tests using:

    $ bundle exec rake custom_spec