Sha256: e8621d7aa57888970e43fd39b7d6683214a7902176a9c07a5728b83fae6de6b3

Contents?: true

Size: 995 Bytes

Versions: 39

Compression:

Stored size: 995 Bytes

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, &block)
  Chef::Platform.stub(: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

39 entries across 39 versions & 1 rubygems

Version Path
chef-11.18.12-x86-mingw32 spec/support/mock/platform.rb
chef-11.18.12 spec/support/mock/platform.rb
chef-11.18.6-x86-mingw32 spec/support/mock/platform.rb
chef-11.18.6 spec/support/mock/platform.rb
chef-11.18.0-x86-mingw32 spec/support/mock/platform.rb
chef-11.18.0 spec/support/mock/platform.rb
chef-12.0.3-x86-mingw32 spec/support/mock/platform.rb
chef-12.0.3 spec/support/mock/platform.rb
chef-12.0.1-x86-mingw32 spec/support/mock/platform.rb
chef-12.0.1 spec/support/mock/platform.rb
chef-12.0.0-x86-mingw32 spec/support/mock/platform.rb
chef-12.0.0 spec/support/mock/platform.rb
chef-12.0.0.rc.0-x86-mingw32 spec/support/mock/platform.rb
chef-12.0.0.rc.0 spec/support/mock/platform.rb
chef-11.16.4-x86-mingw32 spec/support/mock/platform.rb
chef-11.16.4 spec/support/mock/platform.rb
chef-11.16.2-x86-mingw32 spec/support/mock/platform.rb
chef-11.16.2 spec/support/mock/platform.rb
chef-12.0.0.alpha.2-x86-mingw32 spec/support/mock/platform.rb
chef-12.0.0.alpha.2 spec/support/mock/platform.rb