rspecchef-infrachefspec

Chef warning about platform and version running Coverage for ChefSpec


I am relatively new to Chef and very new to ChefSpec. I'm trying to run Coverage to get ChefSpec coverage using the spec_helper.rb file below:

require 'chefspec'
require 'chefspec/berkshelf'

ChefSpec::Coverage.start! do
  add_output do |reportOutput|
    File.open( "coverage.json","w" ) do |f| 
      f.puts(reportOutput[:total])
      f.puts(reportOutput[:touched])
      f.puts(reportOutput[:coverage])
      f.puts(reportOutput[:untouched_resources])
      f.puts(reportOutput[:all_resources])
    end 
  end 
end

When I run rspec, I get this in the output:

WARNING: you must specify a 'platform' and 'version' to your ChefSpec 
Runner and/or Fauxhai constructor, in the future omitting these will 
become a hard error. A list of available platforms is available at 
https://github.com/chefspec/fauxhai/blob/master/PLATFORMS.md
.WARNING: you must specify a 'platform' and 'version' to your ChefSpec
Runner and/or Fauxhai constructor, in the future omitting these will 
become a hard error. A list of available platforms is available at 
https://github.com/chefspec/fauxhai/blob/master/PLATFORMS.md

I'm not sure how to specify the platform and version in the Coverage - I saw some examples on how to do it with ChefSpec::ServerRunner.new().


Solution

  • You don't show your spec so I can't say specifically, but you must pass platform and version options to your Runner constructor, just like the error says. For example ChefSpec::SoloRunner.new(platform: 'ubuntu', version: '16.04'). You can also specify it once globally for all tests in your spec helper, instructions are in the ChefSpec README.