Sha256: 8ce4ccac5d42fdb03076e661483953d2f908fa655c80587c1d0caedbf9147d5d

Contents?: true

Size: 1.01 KB

Versions: 20

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).  Usueful 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

20 entries across 20 versions & 1 rubygems

Version Path
chef-15.9.17 spec/support/mock/platform.rb
chef-15.9.17-universal-mingw32 spec/support/mock/platform.rb
chef-15.8.23 spec/support/mock/platform.rb
chef-15.8.23-universal-mingw32 spec/support/mock/platform.rb
chef-15.7.32 spec/support/mock/platform.rb
chef-15.7.32-universal-mingw32 spec/support/mock/platform.rb
chef-15.7.31 spec/support/mock/platform.rb
chef-15.7.31-universal-mingw32 spec/support/mock/platform.rb
chef-15.7.30 spec/support/mock/platform.rb
chef-15.7.30-universal-mingw32 spec/support/mock/platform.rb
chef-15.6.10 spec/support/mock/platform.rb
chef-15.6.10-universal-mingw32 spec/support/mock/platform.rb
chef-15.5.17 spec/support/mock/platform.rb
chef-15.5.17-universal-mingw32 spec/support/mock/platform.rb
chef-15.5.16 spec/support/mock/platform.rb
chef-15.5.16-universal-mingw32 spec/support/mock/platform.rb
chef-15.5.15 spec/support/mock/platform.rb
chef-15.5.15-universal-mingw32 spec/support/mock/platform.rb
chef-15.5.9 spec/support/mock/platform.rb
chef-15.5.9-universal-mingw32 spec/support/mock/platform.rb