Sha256: 9291bf3cd2f49b19166c3f3deb5f941a393f9c2d16d0a2eaae2bb789b38ee3d3

Contents?: true

Size: 1.01 KB

Versions: 54

Compression:

Stored size: 1.01 KB

Contents

# makes Chef think it's running on a certain platform..useful for unit testing
# platform-specific functionality.
#
# If a block is given yields to the block with +RUBY_PLATFORM+ set to
# 'i386-mingw32' (windows) or 'x86_64-darwin11.2.0' (unix).  Useful for
# testing code that mixes in platform specific modules like +Chef::Mixin::Securable+
# or +Chef::FileAccessControl+
def platform_mock(platform = :unix)
  allow(ChefUtils).to receive(:windows?).and_return(platform == :windows ? true : false)
  ENV["SYSTEMDRIVE"] = (platform == :windows ? "C:" : nil)

  if platform == :windows
    Chef::Config.set_defaults_for_windows
  else
    Chef::Config.set_defaults_for_nix
  end

  if block_given?
    mock_constants({ "RUBY_PLATFORM" => (platform == :windows ? "i386-mingw32" : "x86_64-darwin11.2.0"),
                     "File::PATH_SEPARATOR" => (platform == :windows ? ";" : ":"),
                     "File::ALT_SEPARATOR" => (platform == :windows ? "\\" : nil) }) do
                       yield
                     end
  end
end

Version data entries

54 entries across 54 versions & 1 rubygems

Version Path
chef-15.17.4-universal-mingw32 spec/support/mock/platform.rb
chef-15.17.4 spec/support/mock/platform.rb
chef-15.16.7-universal-mingw32 spec/support/mock/platform.rb
chef-15.16.7 spec/support/mock/platform.rb
chef-15.16.4-universal-mingw32 spec/support/mock/platform.rb
chef-15.16.4 spec/support/mock/platform.rb
chef-15.16.2-universal-mingw32 spec/support/mock/platform.rb
chef-15.16.2 spec/support/mock/platform.rb
chef-15.15.0-universal-mingw32 spec/support/mock/platform.rb
chef-15.15.0 spec/support/mock/platform.rb
chef-16.6.14-universal-mingw32 spec/support/mock/platform.rb
chef-16.6.14 spec/support/mock/platform.rb
chef-16.5.77 spec/support/mock/platform.rb
chef-16.5.77-universal-mingw32 spec/support/mock/platform.rb
chef-16.5.64 spec/support/mock/platform.rb
chef-16.5.64-universal-mingw32 spec/support/mock/platform.rb
chef-15.14.0 spec/support/mock/platform.rb
chef-15.14.0-universal-mingw32 spec/support/mock/platform.rb
chef-16.4.41 spec/support/mock/platform.rb
chef-16.4.41-universal-mingw32 spec/support/mock/platform.rb