Mocking Windows Helpers in Chefspec


#1

I am using Windows helpers in a cookbook to determine the version of Windows that it is running on and different resources execute depending which version it is.

I am wondering if there is a trick to mocking this check so that I can use Chefspec to write unit tests?

In my recipe:

 require 'chef/win32/version'
 version = Chef::ReservedNames::Win32::Version.new
 if version.windows_server_2016?

The error I’m seeing when I try to run a basic spec on the recipe:

 /opt/chefdk/embedded/lib/ruby/gems/2.3.0/gems/ffi-1.9.17/lib/ffi/library.rb:147:in 
`block in ffi_lib': Could not open library 'kernel32': kernel32: cannot open 
shared object file: No such file or directory. (LoadError)
Could not open library 'libkernel32.so': libkernel32.so: cannot open shared 
object file: No such file or directory
from /opt/chefdk/embedded/lib/ruby/gems/2.3.0/gems/ffi- 
1.9.17/lib/ffi/library.rb:100:in `map'
from /opt/chefdk/embedded/lib/ruby/gems/2.3.0/gems/ffi- 
1.9.17/lib/ffi/library.rb:100:in `ffi_lib'
from /opt/chefdk/embedded/lib/ruby/gems/2.3.0/gems/chef- 
12.18.31/lib/chef/win32/api/system.rb:135:in `<module:System>'
from /opt/chefdk/embedded/lib/ruby/gems/2.3.0/gems/chef- 
12.18.31/lib/chef/win32/api/system.rb:24:in `<module:API>'
from /opt/chefdk/embedded/lib/ruby/gems/2.3.0/gems/chef- 
12.18.31/lib/chef/win32/api/system.rb:23:in `<module:Win32>'
from /opt/chefdk/embedded/lib/ruby/gems/2.3.0/gems/chef- 
12.18.31/lib/chef/win32/api/system.rb:22:in `<class:Chef>'
from /opt/chefdk/embedded/lib/ruby/gems/2.3.0/gems/chef- 
12.18.31/lib/chef/win32/api/system.rb:21:in `<top (required)>'
...