Search code examples
puppetrspec-puppet

Confusing Rspec-puppet deprecation warning: defaults mock_with to :mocha


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?


Solution

  • 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.