1

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?

Alex Harvey
  • 14,494
  • 5
  • 61
  • 97
fasten
  • 27
  • 4
  • puppetlabs-spec-helper is doing the downloading and not rspec-puppet. You can file a feature request for this if you want, or use something else to download your module dependencies for your tests. – Matthew Schuchard Oct 20 '17 at 19:10

1 Answers1

4

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
Alex Harvey
  • 14,494
  • 5
  • 61
  • 97
  • I had thought it was a set in puppetlabs_spec_helper from puppet side. It actually is from Ruby side. Commenting out the spec_clean is exactly doing what I wanted. Thanks! – fasten Oct 23 '17 at 15:26
  • Great. You should mark the question as resolved then. – Alex Harvey Oct 24 '17 at 01:36