Sha256: 1f82f5de091d46fdbed12c2fe311324a5f0322bf4b67c5380ed4222bd77e0d72

Contents?: true

Size: 1.01 KB

Versions: 32

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(ChefConfig).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

32 entries across 32 versions & 1 rubygems

Version Path
chef-14.13.11-universal-mingw32 spec/support/mock/platform.rb
chef-15.0.300-universal-mingw32 spec/support/mock/platform.rb
chef-15.0.298-universal-mingw32 spec/support/mock/platform.rb
chef-15.0.293-universal-mingw32 spec/support/mock/platform.rb
chef-14.12.9-universal-mingw32 spec/support/mock/platform.rb
chef-14.12.3-universal-mingw32 spec/support/mock/platform.rb
chef-13.12.14-universal-mingw32 spec/support/mock/platform.rb
chef-14.11.21-universal-mingw32 spec/support/mock/platform.rb
chef-14.10.9-universal-mingw32 spec/support/mock/platform.rb
chef-14.9.13-universal-mingw32 spec/support/mock/platform.rb
chef-14.8.12-universal-mingw32 spec/support/mock/platform.rb
chef-14.7.17-universal-mingw32 spec/support/mock/platform.rb
chef-13.12.3-universal-mingw32 spec/support/mock/platform.rb
chef-14.6.47-universal-mingw32 spec/support/mock/platform.rb
chef-13.11.3-universal-mingw32 spec/support/mock/platform.rb
chef-14.5.33-universal-mingw32 spec/support/mock/platform.rb
chef-13.10.4-universal-mingw32 spec/support/mock/platform.rb
chef-14.3.37-universal-mingw32 spec/support/mock/platform.rb
chef-13.10.0-universal-mingw32 spec/support/mock/platform.rb
chef-13.9.4-universal-mingw32 spec/support/mock/platform.rb