Skip to content

Instantly share code, notes, and snippets.

@fessyfoo
Created March 25, 2016 00:14
Show Gist options
  • Save fessyfoo/5903ceb7c94f067e21e2 to your computer and use it in GitHub Desktop.
Save fessyfoo/5903ceb7c94f067e21e2 to your computer and use it in GitHub Desktop.
RSpec.configure do |c|
# c.before :each do
# # Change autosign from being posix path, which breaks Puppet when
# # we're pretending to be on Windows
# Puppet[:autosign] = true
# end
c.before :each do
# Work even if you don't specify facts
f = self.respond_to?(:facts) ? facts : {}
# Automatically detect whether we're pretending to run on Windows
Thread.current[:windows?] = true if f[:kernel] == 'windows'
end
c.after :each do
Thread.current[:windows?] = nil
end
end
module Puppet
module Util
class << Platform
alias_method :orig_windows?, :windows?
def windows_override?
Thread.current[:windows?]
end
# we need to be selective here
# there are things like the puppet auto loader that
# fail if we pretend to be on windows.
# TODO consider directly monkey patching puppet file type.
def matching_callers
caller.select do |line|
case line
when %r{puppet/provider/exec.*validatecmd} then true
when %r{puppet/type/file} then true
when %r{puppet/parameter/path.*validate_path} then true
else false
end
end
end
def caller_needs_override?
!matching_callers.empty?
end
def windows?
# This is where Puppet normally looks for the target OS.
# It normally returns the *current* OS (i.e., not Windows,
# if you're not running the specs on Windows)
if windows_override? && caller_needs_override?
true
else
orig_windows?
end
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment