1

When running Rspec-puppet tests, a deprecation warning is seen:

Deprecation Warnings:

puppetlabs_spec_helper: defaults `mock_with` to `:mocha`.
  See https://github.com/puppetlabs/puppetlabs_spec_helper#mock_with
  to choose a sensible value for you

Accordingly, I set up a spec_helper with a block like this:

RSpec.configure do |c|
  c.mock_with :mocha
  ...
end

Just like the documentation here suggests. But the warning persists. What is wrong?

Alex Harvey
  • 14,494
  • 5
  • 61
  • 97
  • It is worth clarifying here that what is deprecated is relying on a default mocking framework instead of specifying one explicitly. The message helpfully adds that mocha is the default, but does not mention that the current recommendation is to use rspec-mocks (`:rspec`) instead. – John Bollinger Jan 06 '19 at 18:14

1 Answers1

1

It is actually necessary to open two configuration blocks, whereas the mock_with config must be declared before the puppetlabs_spec_helper is required.

In other words, like this:

RSpec.configure do |c|
  c.mock_with :rspec
end

require 'puppetlabs_spec_helper/module_spec_helper'

RSpec.configure do |c|
  c.formatter = :documentation
  c.tty       = true
  ...
end

See also discussion in here.

I have asked and answered this question here so that this confusing behaviour is documented somewhere because no matter how clear the docs are, this is going to continue to trip people up.

Alex Harvey
  • 14,494
  • 5
  • 61
  • 97
  • 1
    ... or substitute `:rspec` in place of `:mocha` to switch to Rspec-mocks in conformance with the current recommendation (which may well require other changes). The PDK team is trying to encourage folks to move away from Mocha, while avoiding breaking anything. Suppressing the warning by the mechanism shown here subverts that effort. Myself, I'd recommend letting the warning persist until and unless one is prepared to switch to Rspec-mocks. – John Bollinger Jan 06 '19 at 18:19
  • 1
    I changed it to :rspec. Note that I use https://github.com/Accuity/rspec-puppet-utils which is based on Mocha and AFAIK there's no Rspec-mocks equivalent. – Alex Harvey Jan 06 '19 at 22:58